# Getting email replies with Net::IMAP

**URL:** <https://www.ruby-forum.com/t/getting-email-replies-with-net-imap/171622>\
**Category:** Rails\
**Created:** [July 6, 2009, 6:33pm UTC](https://www.ruby-forum.com/t/getting-email-replies-with-net-imap/171622 "2009-07-06T18:33:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pimeamark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9e8a1a/32.png) [@pimeamark](https://www.ruby-forum.com/u/pimeamark)\
**Post date:** [July 6, 2009, 6:33pm UTC](https://www.ruby-forum.com/t/getting-email-replies-with-net-imap/171622/1 "2009-07-06T18:33:39Z")

</div>

Hi, I recently made a program that retrieves emails from an inbox and  
enters the body of those emails into a database using IMAP. I was just  
wondering, is there any function in IMAP or other solution where I can  
just get the body of the new email and exclude the quoted parts of the  
previous emails? for example, currently I’m getting things like this in  
my database:

Let’s try this one out On Jun 30, 2009, at 11:19 AM, Mark wrote: \>  
Thanks for all your help bud.

^^ here i only want the “Let’s try this one out” and not the text that  
comes after it.

Different email providers handle quoting in different ways, so I don’t  
think it’s as easy as looking for a certain string and deleting the text  
after it. I wouldn’t want to do that anyway. Is there an object in IMAP  
that handles this? Just curious if anyone has similar experience.  
Thanks!

---

<div class="post-metadata">

**Author:** ![pimeamark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9e8a1a/32.png) [@pimeamark](https://www.ruby-forum.com/u/pimeamark)\
**Post date:** [July 6, 2009, 7:31pm UTC](https://www.ruby-forum.com/t/getting-email-replies-with-net-imap/171622/2 "2009-07-06T19:31:15Z")

</div>

Mark Mr wrote:  
[…]

> Different email providers handle quoting in different ways, so I don’t  
> think it’s as easy as looking for a certain string and deleting the text  
> after it.

You just answered your own question. There’s no single standard for  
quoting text, so how could there be anything in the IMAP protocol to  
identify it?

> I wouldn’t want to do that anyway. Is there an object in IMAP  
> that handles this?

Oh, wait, you mean something in the Net::IMAP library rather than the  
protocol command set? In that case I’m not sure, but since it’s easy  
enough to write a couple of regexps to handle the common cases, I’m not  
sure why you’d need it.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![pimeamark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9e8a1a/32.png) [@pimeamark](https://www.ruby-forum.com/u/pimeamark)\
**Post date:** [October 9, 2012, 7:20pm UTC](https://www.ruby-forum.com/t/getting-email-replies-with-net-imap/171622/3 "2012-10-09T19:20:58Z")

</div>

There’s a Ruby gem to handle this, released by Github:

> **[GitHub - github/email\_reply\_parser: Small library to parse plain text email...](https://github.com/github/email_reply_parser)**
>
> Small library to parse plain text email content. Contribute to github/email\_reply\_parser development by creating an account on GitHub.

The Ultimation wrote in post #832834:

> Marnen Laibow-Koser wrote:
> 
> > You just answered your own question. There’s no single standard for  
> > quoting text, so how could there be anything in the IMAP protocol to  
> > identify it?
> 
> > Oh, wait, you mean something in the Net::IMAP library rather than the  
> > protocol command set? In that case I’m not sure, but since it’s easy  
> > enough to write a couple of regexps to handle the common cases, I’m not  
> > sure why you’d need it.
> 
> I wasn’t sure if there was some way of IMAP identifying quotes within an  
> email’s body, but I know technology can do some crazy things so why not  
> 🙂 Just curious if anyone had done something similar and what worked for  
> them. Thanks for the reply though. I’ll resort to regexps if necessary.

---

<div class="post-metadata">

**Author:** ![pimeamark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9e8a1a/32.png) [@pimeamark](https://www.ruby-forum.com/u/pimeamark)\
**Post date:** [July 6, 2009, 7:58pm UTC](https://www.ruby-forum.com/t/getting-email-replies-with-net-imap/171622/4 "2009-07-06T19:58:51Z")

</div>

Marnen Laibow-Koser wrote:

> You just answered your own question. There’s no single standard for  
> quoting text, so how could there be anything in the IMAP protocol to  
> identify it?

> Oh, wait, you mean something in the Net::IMAP library rather than the  
> protocol command set? In that case I’m not sure, but since it’s easy  
> enough to write a couple of regexps to handle the common cases, I’m not  
> sure why you’d need it.

I wasn’t sure if there was some way of IMAP identifying quotes within an  
email’s body, but I know technology can do some crazy things so why not  
🙂 Just curious if anyone had done something similar and what worked for  
them. Thanks for the reply though. I’ll resort to regexps if necessary.
