Created
March 3, 2015 11:34
-
-
Save gpr/a6276c0ed22056020982 to your computer and use it in GitHub Desktop.
Process email attachments in Rails
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
# message is Mail::Message | |
# see http://www.rubydoc.info/github/mikel/mail/Mail/Message | |
message.attachments.each do |attch| | |
f = Tempfile.new(attch.filename, Rails.root.join('tmp')) | |
puts " - Save #{attch.filename} to #{f.path}" | |
begin | |
f.binmode | |
f.write attch.decoded | |
ensure | |
file.close | |
file.unlink # deletes the temp file | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment