-
-
Notifications
You must be signed in to change notification settings - Fork 818
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
Leading double period from .NET Framework's SmtpClient not decoded #1607
Comments
The files saved by System.Net.Mail are not in MIME format (they have been pre-escaped for SMTP transport) and so MimeKit's parser does not know to unescape them. If you want them to be unescaped, you'll need to unescape the stream before you parse it. Unfortunately, neither MimeKit nor MailKit have a filter for this so you'll have to write your own logic, but it should be fairly simple to do. Is there a reason you are saving the message using System.Net.Mail and then parsing it using MimeKit? Can you use MimeMessage.CreateFromMailMessage(mailMessage) instead? Or even better, just generate the message using MimeKit? |
We have a suite of (legacy) applications which use We had previously used the IIS 6 SMTP Server that ships with Windows to pick these up and forward them to a real mail server, but that was an endless source of weird bugs. We now have a tool based on MailKit which reads these in and forwards them, which is how we encountered this. Could you point me in the right direction to build such a filter? If you believe it's something that would be more generally useful I'd be happy to open a PR once it's written. |
The 2 closest filters would probably be https://github.com/jstedfast/MailKit/blob/master/MailKit/Net/Smtp/SmtpDataFilter.cs and maybe https://github.com/jstedfast/MimeKit/blob/master/MimeKit/IO/Filters/Dos2UnixFilter.cs The SmtpDataFilter is a filter that adds the extra dot (which is the opposite of what you want to do). Once you've got your filter written, you'll be able to do something like this: string file = Directory.EnumerateFiles(pickupDirectory, "*.eml").FirstOrDefault();
using var stream = File.OpenRead (file);
using var filtered = new FIlteredStream (stream);
filtered.Add (new CustomSmtpDataUnescapeFilter ());
var message = MimeMessage.Load (filtered); |
I opted to add it as a mode of the existing SmtpDataFilter instead and optimized the logic a bit. |
That looks great, thank you! |
When loading an email generated by .NET Framework's
SmtpClient
, if a line starts with a leading.
, it is replaced with..
.When using .NET 7 instead of .NET Framework it produces a
.eml
without the additional leading.
.Program.cs:
Project file:
Sample generated email when using
badBody
.I could not see an option to change the decode behaviour when loading - sorry if I've overlooked something.
The text was updated successfully, but these errors were encountered: