2

I'm wondering how I'd strip the contents of an email and perhaps do gmail-like threading when I have the email body html returned in ruby on rails.

For example, the following text is sent to my app:

Hey XYZ, 

I've fixed that error and tested it a couple of times, it seems to be working fine now.

On Fri, Feb 18, 2011 at 7:44 AM, Joe David <[email protected]> wrote:
Initial thread starts here... 

-- 
Thanks
[email protected]
2
  • Just so I understand, would you expect that text to yield one message (the reply) or two (the reply + the original)? Feb 18, 2011 at 22:58
  • Hey, ideally it should return it in threads; The reply and original in perhaps an array or something like that. Feb 18, 2011 at 23:05

1 Answer 1

2

Email format is a tricky thing. You could use find the boundaries between emails using a regex that detects strings like On Fri, Feb 18, 2011 at 7:44 AM, Joe David <[email protected]> wrote:. But you can't guarantee that all incoming messages will have a string like that between emails.

Another option is to check for the > character, which may appear at the beginning of each quoted line. However, once again, you have to worry about what happens if you receive a message that doesn't follow this convention.

Yet another option--and I think Gmail does this--is to look for matches between the incoming message and previous messages. I.e. if you see Initial thread starts here...Thanks, [email protected] in the message, and you also have that in a previous message in your database, you could infer that it's a quote from earlier in the thread.

2
  • I wish there was a service that did this for me, I'd gladly pay! Feb 19, 2011 at 3:40
  • We have some experimental code in the works at CloudMailin to do this. However as you can imagine it's not easy to find across all the different browsers so it will be a while before we have any production ready code. Feb 22, 2011 at 13:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.