luke
6/1/2006 10:04:00 AM
OK, I've made a bit of progress on this issue, but still I can't locate
where the binary file is, or work out how to initiate a transfer of it
to another local directory.
What I've got so far is below:
require 'net/imap'
imap = Net::IMAP.new('domain.name.com')
imap.authenticate('LOGIN', 'mailbox', 'password')
imap.select('INBOX')
imap.search(["SINCE", "8-Aug-2002"]).each do |message_id|
attach = imap.fetch(message_id, "BODY")[0].attr["BODY"]
puts "#{attach.parts[1].media_type}"
puts "#{attach.parts[1].param['NAME']}"
puts "#{attach.parts[1].subtype}"
puts "#{(attach.parts[1].size)/1024} kb"
end
It simply prints out information about the attachment, like this:
IMAGE
filename.jpg
JPEG
35 kb
I hope this isn't a really basic question, but what is the next step to
saving this file attachment?
Thanks
Luke
luke wrote:
> Hi,
>
> I'm trying to write a Ruby script that will connect to my mail server
> using IMAP, check for new email, and if an email has an attachment then
> it will save the attachment into a certain local directory. And that's
> it! I don't actually care about the contents of the email. This will be
> simply a way of collecting files that are sent as attachments to a
> certain email address.
>
> I've been looking around for 2 nights and so far haven't been able to
> find something myself that demonstrates how to retrieve attachments
> using the Net::IMAP library, or using something that works into that
> library.
>
> I have my code to the point where it connects successfully to my mail
> server, and then prints some subject lines just to say email is being
> detected. I've tried googling, checking script libraries and reading
> through the API docs for the standard library to no avail. Can someone
> give me some pointers?
>
> Thanks
> Luke