php - Get the actual email message that the person just wrote, excluding any quoted text -


there 2 pre-existing questions on site. 1 python, 1 java.

i want able pretty same (in php). i've created mail proxy, 2 people can have correspondance emailing unique email address. problem finding however, when person receives email , hits reply, struggling accurately capture text has written , discard quoted text previous correspondance.

i'm trying find solution work both html emails , plaintext email, because sending both.

i have ability if helps insert <*****respond above here*******> tag if neccessary in emails meaning can discard below.

what recommend do? add tag html copy , plaintext copy grab above it?

i still left scenario of knowing how each mail client creates response. because example gmail this:

on wed, nov 2, 2011 @ 10:34 am, message platform <35227817-7cfa-46af-a190-390fa8d64a23@dev.example.com> wrote: ## in replies text above line added message conversation ## 

any suggestions or recommendations of best practices?

or should grab 50 popular mail clients, , start creating custom regex each. each of these clients, bizallion different locale settings since i'm guessing locale of user influence added.

or should remove preceding line if contains date?.. etc

unfortunately, you're in world of hurt if want try clean emails meticulously (removing that's not part of actual reply email itself). ideal way to, suggest, write regex each popular email client/service, that's pretty ridiculous amount of work, , recommend being lazy , dumb it.

interestingly enough, facebook engineers have trouble problem, , google has patent on method "detecting quoted text".

there 3 solutions might find acceptable:

leave alone

the first solution leave in message. email clients this, , nobody seems complain. of course, online message systems (like facebook's 'messages') pretty odd if have inception-style replies. 1 sneaky way make work okay render message quoted lines collapsed, , include little link 'expand quoted text'.

separate reply older message

the second solution, mention, put delineating message @ top of messages, --------- please reply above line ----------, , strip line , below when processing replies. many systems this, , it's not worst thing in world... make email more 'automated' , less personal (in opinion).

strip out quoted text

the last solution strip out new line beginning >, is, presumably, quoted line reply email. email clients use method of indicating quoted text. here's regex (in php) that:

$clean_text = preg_replace('/(^\w.+:\n)?(^>.*(\n|$))+/mi', '', $message_body); 

there problems using simpler method:

  • many email clients allow people quote earlier emails, , preface quote lines > well, you'll stripping out quotes.
  • usually, there's line above quoted email on [date], [person] said. line hard remove, because it's not formatted same among different email clients, , may 1 or 2 lines above quoted text removed. i've implemented detection method, moderate success, in php imap library.

of course, testing key, , tradeoffs might worth particular system. ymmv.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -