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!)

rip calendar attachments from an email (in ruby) (See related posts)

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

You need to create an account or log in to post comments to this site.


Related Posts