From: Damjan Rems Date: 2008-11-05T16:21:35+09:00 Subject: Re: Tmail + IMAP + Attachments Didn't tried with tmail but this is how it goes with IMAP. imap = Net::IMAP.new('my.mail.server') imap.login('usr', 'pwd') imap.select('Inbox') # all msgs n = imap.search(["SINCE", "1-Jan-1969"]) n.each do |msgID| msg = imap.fetch(msgID, ["ENVELOPE","UID","BODY"] )[0] unless msg.attr["ENVELOPE"].subject.index('SOME STRING').nil? body = msg.attr["BODY"] i = 1 while body.parts[i] != nil sType = body.parts[i].subtype cName = body.parts[i].param['NAME'] i+=1 attachment = imap.fetch(msgID, "BODY[#{i}]")[0].attr["BODY[#{i}]"] File.open($wDir+cName,'wb+') { |f| f.write(attachment.unpack('m')) } unless attachment.nil? end end end by TheR -- Posted via http://www.ruby-forum.com/.