How to extract latest reply text from email and cut out previous messages?

How to extract latest reply text from email, and cut out previous messages?

  • I am using OpenPop.dll to read emails in my application. I want to read only the reply of the email not original email which it was replied to. But email is read with previous emails in quotes. I want to remove those previous mail contents. I tried using RegEx for this but that is not very robust way to read replies because different email clients have different reply format. Is there any way by which I can read only the reply text from mail thread in OpenPop.dll or some other open source library. Below is how the reply email text looks like when read from OpenPop.dll. My phone number is 123456789. On Fri, May 8, 2015 at 2:57 PM, wrote: > Hi, > > This mail is regarding your *Phone*. Please reply to this email with your > *Phone*. > > Thanks > This format is such that because it was replied from Gmail. Outlook has different format and so does yahoo. I want to read only My phone number is 123456789. Is there any way I could achieve this? Any solution is welcome.

  • Answer:

    This is a sticky situation and exactly for reason you mentioned - each email server acts differently. When dealing with strings, without any type of special marker, strings that come from un-unified sources, it is almost impossible to parse them perfectly. It is analogous to CSS having different syntax for each browser. You can do best of you can do (if you decided to go on with the project, that it worth it). It is probably not worth it though. You can collect formats from all well-known mail servers and create regex for each. Save your regex in a different DLL or resource file so, if format ever changes you can update the single file. Or, if this application is just for you, keep it in plain text, so you don't have to compile. If your program encounters unknown mail server, you can just let the whole email go. Or, you can attempt to find something generic, like "From:[email protected]" since you know the address it came from. But again, this application can't be 100% accurate as people can reply by commenting existing text, for example, and only say, "Read comments below". I don't think it worth the aggravation...

Mayank Sharma at Stack Overflow Visit the source

Was this solution helpful to you?

Other answers

I faced with such a problem.I did data mining.I used naive Bayes algorithm.You need email data collection.Problem will be solved. This is my project. https://www.youtube.com/watch?v=jJShFuEEsQg

Kadir Diego Kılıc

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.