I am trying to build a script that will download emails + their
attachments (from gmail server) and place them both into their
respective folders (one folder containing one email + its attachments).
I have managed to build a script (by putting together pieces from two
separate scripts) that gets the job 90% done, my problem is that I can't
get the attachments to save in the same folders as their respective
emails.
The folder structure where the emails are saved now is perfect, it is
just a question of getting the attachments to follow its respective
email into the folder.
If someone would have any tips for me I would be extremely grateful!
Here's some sample code of the attached script:
*************************************************************************
def save_to_disk(email) ## downloads emails
dir = File.join(MAIL_FOLDER,email.subject)
FileUtils.mkdir_p(dir)
filename = File.join(dir,email.subject)
file = File.open(filename,"w")
file.puts email.body
file.close
if email.multipart? then ## downloads attachments
email.parts.each do |m|
if m.disposition
filename = m.disposition_param('filename')
if filename[0,2]=='=?'
filename.gsub!(/=\?[^\?]+\?(.)\?([^\?]+)\?=$/){$1=='B' ?
$2.unpack('m*') : $2.unpack('M*')}
end
file = File.open(filename,'wb') {|f|f.write(m.body)}
puts filename
end
end
end
end
*************************************************************************
Attachments:
http://www.ruby-forum.com/attachment/3673/fetch-email_attachment_3.rb
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---