In from field of email, your names contains double quote which shows \" instead of "

0 votes
asked Jan 17 by dsouzac (190 points)

Inbound email id is ""atul" cus't'omer" when any email comes from this email id it shows as,

From: "\"atul\" cus't'omer"

Here is my question, how should i get ""atul" cus't'omer" instead of "\"atul\" cus't'omer"

I am using POP3:v4.0.30319 version Rebex lib.

Please let me know how to solve it or is there any other way to skip "\" from From field.

Applies to: Rebex Secure Mail
commented Jan 17 by dsouzac (190 points)
Is this an issue in Rebex?

1 Answer

0 votes
answered Jan 17 by Lukas Pokorny (81,570 points)
selected Jan 17 by dsouzac
Best answer

This From header is not formatted correctly:

From: "\"atul\" cus't'omer"

According to RFC 2822, the address must be enclosed in angle brackets when display name is present, which means the header should look like this:

From: "\"atul\" cus't'omer" <>.

Please note that \" is not causing any problems - the backslash just indicates that the following character is a literal character, not a control character. The lack of < and > is the problem. (See the examples in RFC 2822.)

commented Jan 17 by dsouzac (190 points)
Thanks for quick reply, but you got it wrong. My issue is with display name, while typing i have typed angle brackets but it didn't shown when i published my question.

its ok, here again..
display name: "atul" cus't'omer

so email id looks like "atul" cus't'omer <>. When i send an email from this email id (e.g. outlook or thunderbird or etc) to my email id which is configured in my application and implemented by Rebex library.

in this scenario, i display from email id e.g. msg.From (msg is MailMessage object). then it shows as "\"atul\" cus't'omer" <>, where as I am expecting it to be displayed as "atul" cus't'omer <>.

Actual Result:"\"atul\" cus't'omer" <>
Expected result: "atul" cus't'omer <>
commented Jan 17 by Lukas Pokorny (81,570 points)
Oh well, sorry for the confusion. It looks like you use .ToString() to display the content of msg.From, but this results in an encoded form of the display name - it returns the contents of the header, not its visual representation. However, decoded parts are available through MailAddress object, which makes it quite simple to achieve what you need - just cunstruct the desired visual representation yourself.

This code displays the name and address parts along with ToString() and a custom-formatted form, which looks like what you need:

        foreach (MailAddress address in mail.From)
            Console.WriteLine("Name: {0}", address.DisplayName);
            Console.WriteLine("Address: {0}", address.Address);
            Console.WriteLine("Both: {0}", address.ToString());
            Console.WriteLine("Custom: {0} <{1}>", address.DisplayName, address.Address);
commented Jan 17 by dsouzac (190 points)
Thanks Lukas,

This will solve my problem, i have to use custom approach to display complete email id.