Skip to content
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

[Bug] Subject and other headers sometimes aren't in the right encoding #441

Open
chenseanxy opened this issue Oct 18, 2024 · 2 comments · May be fixed by #450
Open

[Bug] Subject and other headers sometimes aren't in the right encoding #441

chenseanxy opened this issue Oct 18, 2024 · 2 comments · May be fixed by #450
Assignees
Labels
bug Something isn't working

Comments

@chenseanxy
Copy link
Contributor

chenseanxy commented Oct 18, 2024

Describe the bug

Subjects, sender names, and preview text are not in the right encoding before being saved to the database, particularly when MIME is in a weird encoding like gbk. This would mean these texts are displayed in the wrong format in the mail list, notifications being sent in the same wrong encoding too, and also these emails won't be searchable

However, the mail rendering page does display these texts without problems.

Also reported by @loshine, #317 @dartraiden

Tested on Windows 10 21H2 and Windows 11 23H2 & 24H2

Expected behavior
Encoding should be followed, but this should be MimeKit's job?!

Sample header: Subject: =?GBK?B?seDC67LiytQ=?=

Screenshots

image

Additional context
I did a bit of digging, but it seems Wino basically offloads all the parsing to MimeKit and isn't doing anything particularly special after getting a parsed MimeMessage.

Only difference between database entries and rendered mail: MIME for the database is directly parsed when returned from GetMessagesAsync, and MIME for rendered mail is parsed when loaded from file with LoadAsync. Maybe these two have different default options for parser? Needs further investigation

MailCopy:

var mimeMessage = await imapFolder.GetMessageAsync(summary.UniqueId, cancellationToken).ConfigureAwait(false);
var mailCopy = summary.GetMailDetails(assignedFolder, mimeMessage);

Rendered mail:

public async Task<MimeMessageInformation> GetMimeMessageInformationAsync(Guid fileId, Guid accountId, CancellationToken cancellationToken = default)
{
var resourcePath = await GetMimeResourcePathAsync(accountId, fileId).ConfigureAwait(false);
var mimeFilePath = GetEMLPath(resourcePath);
var loadedMimeMessage = await MimeMessage.LoadAsync(mimeFilePath, cancellationToken).ConfigureAwait(false);
return new MimeMessageInformation(loadedMimeMessage, resourcePath);
}

@chenseanxy chenseanxy added the bug Something isn't working label Oct 18, 2024
@chenseanxy
Copy link
Contributor Author

Should have done five minutes of search tbh... Already reported in #317, but not necessarily closing this because I'm too lazy to copy things over lmao

@chenseanxy
Copy link
Contributor Author

Welp after digging through MimeKit implementations seems like it's this: jstedfast/MimeKit#1009

It's also on MimeKit's FAQ:

.NET Core (and ASP.NET Core by extension) and .NET 5 only provide the Unicode encodings, ASCII and ISO-8859-1 by default. Other text encodings are not available to your application unless your application registers the encoding provider that provides all of the additional encodings.
First, add a package reference for the System.Text.Encoding.CodePages nuget package to your project and then register the additional text encodings using the following code snippet:

System.Text.Encoding.RegisterProvider (System.Text.CodePagesEncodingProvider.Instance);

Note: The above code snippet should be safe to call in .NET Framework versions >= 4.6 as well.

Registering provider at server lanuch does seem to fix it

image

chenseanxy added a commit to chenseanxy/Wino-Mail that referenced this issue Oct 22, 2024
@chenseanxy chenseanxy linked a pull request Oct 22, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants