Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

About this user

Jason Hoffman http://textdrive.com/

« Newer Snippets
Older Snippets »
1 total  XML / RSS feed 

rip calendar attachments from an email (in ruby)

See here for context.

I did this for undees

#!/usr/local/bin/ruby
$: << '/home/username/usr/local/lib/ruby/site_ruby/1.8'
require 'tmail'

s = $stdin.read
mail = TMail::Mail.parse s
mail.parts.each do |part|
  if 'text/calendar' == part.content_type
    t = part.body
    t.gsub!(/=[\r\n]+/, '')
    t.gsub!(/=(\w\w)/) {$1.hex.chr}
    
    outPath = '/home/username/path/to/Calendar.ics'
    File.open outPath, 'w' do |f|
      f.write t
    end
    File.chmod 0664, outPath    
  end
end
« Newer Snippets
Older Snippets »
1 total  XML / RSS feed