From: Damjan Rems Date: 2007-03-21T15:47:18+09:00 Subject: Re: E-mail library for Ruby? Just Another Victim of the Am Morality wrote: > Okay, I'll detail my problem and, hopefully, people can suggest a > solution to me. > I have an account on a Linux machine that I use as my e-mail > address. I > use Pine as my mail client. I have let my inbox accumulate e-mail for > years > and there is now too much e-mail queued up for my tastes. Now, I don't > want > to delete my e-mail. Instead, I want archive it to various e-mail > folders > like how I would have if I used Pine. I could do this by hand, using > Pine, > except that there is simply too much e-mail for me to do this in any > reasonable time. > So, I think my solution is to automate this sorting using something > like > Ruby and an appropriate library. Does anyone know what Ruby library I'm > looking for? > Thank you... If You have imap access you can do this. This is excerpt from my program which is cleaning postmaster box. aDelete=Array.new aMove=Array.new imap = Net::IMAP.new('mail.domain.com') imap.login('user', 'pwd') imap.select('Inbox') n = imap.search(["SINCE", "1-Jan-1969"]) listInbox = imap.fetch(n, ["ENVELOPE","UID"] ) listInbox.each do | a | if (a.attr["ENVELOPE"].subject[0..14] == "Discarded Mail:" or a.attr["ENVELOPE"].subject[0..16] == "Quarantined Mail:") then aMove.push(a.attr["UID"]) # either move aDelete.push(a.attr["UID"]) # or delete end end # Move to other folder if aMove.length > 0 imap.uid_copy(aMove,"FolderToMove") imap.uid_store(aMove, "+FLAGS", [:Deleted]) end # Delete msgs imap.uid_store(aDelete, "+FLAGS", [:Deleted]) if aDelete.length > 0 # Expunge msgs marked for deletion imap.expunge imap.close by TheR -- Posted via http://www.ruby-forum.com/.