Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

parsing email text reply/forward

I am creating a web based email client using c# asp.net.

What is confusing is that various email clients seem to add the original text in alot of different ways when replying by email.

What I was wondering is that, if there is some sort of standardized way, to disambiguate this process?

Thank you -Theo

like image 725
Theofanis Pantelides Avatar asked Mar 11 '10 11:03

Theofanis Pantelides


1 Answers

I was thinking:

public String cleanMsgBody(String oBody, out Boolean isReply) 
{
    isReply = false;

    Regex rx1 = new Regex("\n-----");
    Regex rx2 = new Regex("\n([^\n]+):([ \t\r\n\v\f]+)>");
    Regex rx3 = new Regex("([0-9]+)/([0-9]+)/([0-9]+)([^\n]+)<([^\n]+)>");

    String txtBody = oBody;

    while (txtBody.Contains("\n\n")) txtBody = txtBody.Replace("\n\n", "\n");
    while (new Regex("\n ").IsMatch(txtBody)) txtBody = (new Regex("\n ")).Replace(txtBody, "\n");
    while (txtBody.Contains("  ")) txtBody = txtBody.Replace("  ", " ");

    if (isReply = (isReply || rx1.IsMatch(txtBody)))
        txtBody = rx1.Split(txtBody)[0]; // Maybe a loop through would be better
    if (isReply = (isReply || rx2.IsMatch(txtBody)))
        txtBody = rx2.Split(txtBody)[0]; // Maybe a loop through would be better
    if (isReply = (isReply || rx3.IsMatch(txtBody))) 
        txtBody = rx3.Split(txtBody)[0]; // Maybe a loop through would be better

    return txtBody;
}
like image 174
Theofanis Pantelides Avatar answered Sep 20 '22 12:09

Theofanis Pantelides