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

« Newer Snippets
Older Snippets »
2 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

rip calendar attachments from an email

See here for context.

#!/usr/bin/env /usr/local/bin/python

import sys, email

msg = email.message_from_string(sys.stdin.read())

for part in msg.walk():
  if part.get_content_type() == 'text/calendar':
    f = open(part.get_filename(), 'w')
    f.write(part.get_payload())
    f.close()
« Newer Snippets
Older Snippets »
2 total  XML / RSS feed