How to use Mail.connection

50 views
Skip to first unread message

Cy Walker

unread,
Feb 9, 2012, 4:06:35 AM2/9/12
to Ruby's Mail Discussion Group
Hi,
My apologies first off for the question as I am a casual programmer
stumbling through building a RoR app.
I am using the Mail gem but want to be able to 'move' and delete
individual IMAP messages by UID.

Can I do this with Mail.connection?
If so is someone willing to show me some example code as I don't quite
understand the (&block) requirement.

The only other alternative that seems to 'fit' in my 1990's VB mind is
adding (poorly) this functionality in the IMAP retriever with a forked
copy Mail.... which I am sure is just not the proper way of doing
things in your world! :o)

Any help greatly appreciated.

Cheers,
Cy

Donald Ball

unread,
Feb 9, 2012, 10:15:48 AM2/9/12
to mail...@googlegroups.com
If you give an IMAP find method a block with three arguments instead
of the usual one, it will yield the message, the imap connection, and
the uid of the message. You can use the imap connection and uid to do
a variety of different things with the message at that point. So it
would be something along the lines of:

Mail.find(...) do |message, imap, uid|
...
imap.uid_copy(uid, 'archive')
...
end

-- donald

Reply all
Reply to author
Forward
0 new messages