Created
November 20, 2009 08:01
-
-
Save elim/239352 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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