Skip to content

Instantly share code, notes, and snippets.

@elim
Created November 20, 2009 08:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elim/239352 to your computer and use it in GitHub Desktop.
Save elim/239352 to your computer and use it in GitHub Desktop.
#!/opt/local/bin/ruby1.9
# -*- coding: utf-8 -*-
# based upon
# http://d.hatena.ne.jp/omochist/20060906/1157532315
require 'action_mailer'
require 'logger'
logger = Logger.new(STDERR)
ARGV.each do |fname|
logger.debug "fname = #{fname}"
email = TMail::Mail.load(fname)
begin
if email.has_attachments?
logger.debug 'attach detected.'
email.attachments.each do |attachment|
content = attachment.read
filename = attachment.original_filename
content_type = attachment.content_type
logger.debug "filename = #{filename}, content-type = #{content_type}"
File.open(filename, 'wb') {|f|
f.write content
}
end
end
rescue
next
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment