-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problems with from-encoding #30
Comments
This fixes nilnull#30 issue
This fixes nilnull#30 issue
Hi, the problem is with all email address headers (from, to, cc).
And then calling this when adding headers:
|
Hi @boskoKlemenc, You are right. Currently, in my MUA software that uses this project, just permits use the “display name” property in the “from” field. But also should be able used in any mail address field… Although, the real problem here is not forcing the use of MimeMailAddress in front of System.Net.Mail.MailAddress. Then it would only be necessary to override the ToString() method. At this time, both classes are mixed along the code and in the client also can be use both. For making this in a good way, should be necessary to hide and override some methods in MimeMailMessage class. But I think this would produce many other changes and things to check. So for the moment, just will refactor my code similarly. Thanks for your reply. |
Freut mich!Vlg
-------- Ursprüngliche Nachricht --------Von: boskoKlemenc ***@***.***> Datum: 23.07.22 09:54 (GMT+01:00) An: nilnull/AIM ***@***.***> Cc: christian489 ***@***.***>, Author ***@***.***> Betreff: Re: [nilnull/AIM] Problems with from-encoding (Issue #30)
Hi,
the problem is with all email address headers (from, to, cc).
I made a similar fix as you did:
`private object TransformAddress(MailAddress address)
{
string trimmedDisplayName = address.DisplayName.Trim();
if (trimmedDisplayName != "" && trimmedDisplayName.Length > 0)
{
return GetEncodedAddress(address);
}
else
{
return address;
}
}
private string GetEncodedAddress(MailAddress address)
{
var headersEncoding = MailMessage.HeadersEncoding ?? Encoding.UTF8;
var encodingName = headersEncoding.BodyName.ToLower();
return "=?" + encodingName + "?B?" + TransferEncoder.ToBase64(headersEncoding.GetBytes(address.DisplayName)) + "?=" + " <" + address.Address + ">";
}`
And then calling this when adding headers:
buf.Append(TransformAddress(MailMessage.From)); ... buf.Append(TransformAddress(MailMessage.To[x])); ... buf.Append(TransformAddress(MailMessage.CC[0])); ... buf.Append(TransformAddress(MailMessage.CC[x]));
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Hi,
as I had problems when using some characters in an extended from: field (e.g. "Max Müller [email protected]").
I repaced the line "buf.Append(MailMessage.From);" in SendMail() with "buf.Append(GetEncodedFromAddress());" and added the following code to SmtpSocketClient.cs
`
private object GetEncodedFromAddress()
{
var headersEncoding = MailMessage.HeadersEncoding ?? Encoding.UTF8;
if (Encoding.ASCII.Equals(headersEncoding))
{
return MailMessage.From;
}
else
{
byte[] bytes = headersEncoding.GetBytes(MailMessage.From.DisplayName);
}
`
also I added the follwing class (from https://dotnet-snippets.de/snippet/quoted-printable-encoder/778) used by the function above:
`
using System.Text;
namespace AegisImplicitMail
{
public class QuotedPrintableConverter
{
private static string _Ascii7BitSigns;
private const string _equalsSign = "=";
private const string _defaultReplaceEqualSign = "=";
}
`
PS: sorry, I could not get the code propperbly recogniced using the "Add code" formater
I can choose between various encodings (other than ASCII7 like "iso-8859-1") using the third parameter of System.Net.Mail.MailAddress(string address, string displayName, Encoding displayNameEncoding) when set the MimeMailMessage.From property.
Maybe you can check this and integrate such a feature in your code.
best regards, Christian
The text was updated successfully, but these errors were encountered: