# E-mail library for Ruby?

**URL:** <https://www.ruby-forum.com/t/e-mail-library-for-ruby/89551>\
**Category:** Ruby\
**Created:** [March 21, 2007, 5:25am UTC](https://www.ruby-forum.com/t/e-mail-library-for-ruby/89551 "2007-03-21T05:25:25Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![maz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@maz](https://www.ruby-forum.com/u/maz)\
**Post date:** [March 21, 2007, 5:25am UTC](https://www.ruby-forum.com/t/e-mail-library-for-ruby/89551/1 "2007-03-21T05:25:25Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![maz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@maz](https://www.ruby-forum.com/u/maz)\
**Post date:** [March 21, 2007, 7:47am UTC](https://www.ruby-forum.com/t/e-mail-library-for-ruby/89551/2 "2007-03-21T07:47:16Z")

</div>

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](http://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

---

<div class="post-metadata">

**Author:** ![maz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@maz](https://www.ruby-forum.com/u/maz)\
**Post date:** [March 21, 2007, 7:48am UTC](https://www.ruby-forum.com/t/e-mail-library-for-ruby/89551/3 "2007-03-21T07:48:47Z")

</div>

I forgot. You must also add  
require ‘net/imap’  
at the top.

by

TheR

---

<div class="post-metadata">

**Author:** ![maz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@maz](https://www.ruby-forum.com/u/maz)\
**Post date:** [March 21, 2007, 3:19pm UTC](https://www.ruby-forum.com/t/e-mail-library-for-ruby/89551/4 "2007-03-21T15:19:34Z")

</div>

On Wed, 21 Mar 2007, Just Another Victim of the Ambient M. wrote:

> Thank you…  
> you are looking for tmail. let me warn you, however, that it’s **very**  
> easy  
> to blow away your mail while learning this library - be sure to make a  
> backup  
> first!

cheers.

-a

---

<div class="post-metadata">

**Author:** ![maz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@maz](https://www.ruby-forum.com/u/maz)\
**Post date:** [March 21, 2007, 11:57am UTC](https://www.ruby-forum.com/t/e-mail-library-for-ruby/89551/5 "2007-03-21T11:57:12Z")

</div>

On 3/21/07, Just Another Victim of the Ambient M.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> 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?

Well there’s POP3 libraries too, in addition to IMAP. And they ship  
with with Ruby.  
You can probably find 3rd party libraries too that are effective in  
more niche mail  
formats.

I would presume that you might end up using some kind of subject line  
pattern  
matching to sort the email (especially useful for mailing lists)

---

<div class="post-metadata">

**Author:** ![maz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@maz](https://www.ruby-forum.com/u/maz)\
**Post date:** [March 21, 2007, 11:36pm UTC](https://www.ruby-forum.com/t/e-mail-library-for-ruby/89551/6 "2007-03-21T23:36:57Z")

</div>

“Alex LeDonne” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote in message  
news:removed\_email\_address@domain.invalid…

> > to delete my e-mail. Instead, I want archive it to various e-mail  
> > [In Pine, how do I enable aggregate commands?](http://kb.iu.edu/data/aixg.html) (In Pine, how do I enable aggregate
> 
> Since you’re already familiar with Pine, then using the aggregate  
> command set, I think you could, in fact, do this in a reasonable  
> amount of time by hand. 🙂

```
This looks very promising, thank you.
I'm a little embarrassed using a non-Ruby solution solicited from a 

```

Ruby  
newsgroup…

---

<div class="post-metadata">

**Author:** ![maz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@maz](https://www.ruby-forum.com/u/maz)\
**Post date:** [March 21, 2007, 9:31pm UTC](https://www.ruby-forum.com/t/e-mail-library-for-ruby/89551/7 "2007-03-21T21:31:37Z")

</div>

On 3/21/07, Just Another Victim of the Ambient M.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.

For the record: In Pine, you can enable aggregate commands, select  
messages by criteria, then move them in bulk.

For step-by-step instructions to get started:  
[In Pine, how do I enable aggregate commands?](http://kb.iu.edu/data/aixg.html) (In Pine, how do I enable aggregate  
commands?)  
[http://kb.iu.edu/data/afsx.html](http://kb.iu.edu/data/afsx.html) (In Pine, how do I perform an action  
(like saving or printing) on a large number of messages at once?)

For further adventures:  
[http://www.google.com/search?&q=pine+enable+aggregate+command+set](http://www.google.com/search?&q=pine+enable+aggregate+command+set)

You can then do things like select all the messages with “ruby-talk”  
in the to field, and apply the save command to save them all to a  
folder.

Since you’re already familiar with Pine, then using the aggregate  
command set, I think you could, in fact, do this in a reasonable  
amount of time by hand. 🙂

-Alex

---

<div class="post-metadata">

**Author:** ![maz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@maz](https://www.ruby-forum.com/u/maz)\
**Post date:** [March 22, 2007, 5:18pm UTC](https://www.ruby-forum.com/t/e-mail-library-for-ruby/89551/8 "2007-03-22T17:18:59Z")

</div>

On 3/21/07, Just Another Victim of the Ambient M.

> ```
> 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?

You could keep your inbox as-is, and use sup[1](http://sup.rubyforge.org/) to label, sort, and  
search. It’s Gmail for the command-line, written in Ruby.

- Dimitri
