Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #6783

Re: How to detach mail attachments with Net::IMAP

Newsgroups comp.lang.ruby
Date 2013-04-06 05:52 -0700
References <034f7414de995e5a4c3eaca706f19a5d@ruby-forum.com>
Message-ID <ffbd873c-5308-4eb3-9ca1-0eda9027d6ab@googlegroups.com> (permalink)
Subject Re: How to detach mail attachments with Net::IMAP
From a.aboelllef@gmail.com

Show all headers | View raw


On Thursday, June 14, 2007 8:49:31 AM UTC+3, Damjan Rems wrote:
> Since documenattion on this topic is very "non existing" I thought I
> would share this with you:
> 
> -------------------------------
> require 'net/imap'
> 
> imap = Net::IMAP.new('my.mail.server')
> imap.login('usr', 'pwd')
> imap.select('Inbox')
> # All msgs in a folder
> msgs = imap.search(["SINCE", "1-Jan-1969"])
> # Read each message
> msgs.each do |msgID|
>   msg = imap.fetch(msgID, ["ENVELOPE","UID","BODY"] )[0]
> # Only those with 'SOMETEXT' in subject are of our interest
>   if msg.attr["ENVELOPE"].subject.index('SOMETEXT') != nil
>     body = msg.attr["BODY"]
>     i = 1
>     while body.parts[i] != nil
> # additional attachments attributes
>       cType = body.parts[i].media_type
>       cName = body.parts[i].param['NAME']
>       i+=1
> # fetch attachment.
>       attachment = imap.fetch(msgID, "BODY[#{i}]")[0].attr["BODY[#{i}]"]
> # Save message, BASE64 decoded
>       File.new(cName,'wb+').write(attachment.unpack('m'))
>     end
>   end
> end
> imap.close
> ---------------------------------
> 
> by
> TheR
> 
> -- 
> Posted via http://www.ruby-forum.com/.

THANKS this helped me alot 

Back to comp.lang.ruby | Previous | Next | Find similar | Unroll thread


Thread

Re: How to detach mail attachments with Net::IMAP a.aboelllef@gmail.com - 2013-04-06 05:52 -0700

csiph-web