0

I'm creating an app to handle emails answered directly to me.

Everything is working fine with Griddler and SendGrid adapter.

My question is: How can I get only the text that user wroted.

My email has a lot of images and I'm using reply_delimiter to cut unnecessary text, but email timestamp still appears. Something like:

"Here's my only text that matters!!\n\n2014-10-10 14:27 GMT-03:00 Company store :\n "

How can I remove after \n considering this may be different in other email clients.

Right now, I only tested replying from Gmail.

Cleyton
  • 2,338
  • 6
  • 23
  • 39

1 Answers1

0

Github has written an awesome ruby gem called email_reply_parser which attempts to do what you're looking for (and it's what GitHub uses themselves to parse emails).

With email_reply_parser and Griddler you'll do something like the following to get the email body.

parsed_body = EmailReplyParser.parse_reply(@email.body)

However, this likely will not play nice with Griddler's reply_delimiter, and you'll want to choose one or the other.

In the end, parsing user created content from the rest of the email is incredibly difficult and often is not possible 100% of the time. Play with both solutions and see which one works best for you.

Nick Q.
  • 3,947
  • 2
  • 23
  • 37
  • I've tried this gem, but it doesn't work well with accents. For example: `Vocês não responderam` turns into `Voc\xC3\xAAs n\xC3\xA3o`. And it still has the email timestamp – Cleyton Oct 10 '14 at 19:10