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

Base64 encoded file name not parsed #1095

Closed
martinknafvework opened this issue Nov 7, 2024 · 1 comment
Closed

Base64 encoded file name not parsed #1095

martinknafvework opened this issue Nov 7, 2024 · 1 comment
Labels
3rd-party-client-bug The bug appears to be in the other client

Comments

@martinknafvework
Copy link

Describe the bug

When loading an email using MimeMessage.Load, attachments containing base64-encoded utf8 file names are not parsed properly.

Platform (please complete the following information):

  • OS: Windows
  • .NET Runtime: .NET Framework
  • .NET Framework: 4.8
  • MimeKit Version: 4.8.0

To Reproduce

  1. Download the attached email.txt.
  2. Parse the file using the code below.

Now you will see the attachment filename =?UTF-8?B?SGVsbG9Xb3JsZC50eHQ=?= printed to console.

Expected behavior
I expect to see the attachment file name HelloWorld.txt printed to the console. This is what is shown if I open the same file in Outlook or Mozilla Thunderbird.

Code Snippets
If applicable, add code snippets to help explain your problem.

 MimeMessage message;
 using (var stream = File.OpenRead(filePath))
 {
    message = MimeMessage.Load(stream);
 }

 foreach (var attachment in message.Attachments)
 {
    if (attachment is MimePart mimePart && mimePart.FileName != null)
    {
       Console.WriteLine("Attachment filename: " + mimePart.FileName);
    }
 }

Additional context

  • Email.txt

  • I am parsing EML files produced by external systems. The actual files have the attachment file names split over multiple lines (filename*0=, filename*1= etc). But since the issue was reproducible with a single, I hoped that would be sufficient.

@jstedfast jstedfast added the 3rd-party-client-bug The bug appears to be in the other client label Nov 7, 2024
@jstedfast
Copy link
Owner

The issue is the mix-and-match encoding rules that your sample email uses. It uses both rfc2231 and rfc2047 encoding rules when it should only use rfc2231 -or- rfc2047 (technically, it should use rfc2231 since that is the standard, but rfc2047 encodings were used in the 90's because rfc2231 didn't exist yet).

Instead, the client that sent this message used rfc2047 encoding and then passed that through the rfc2231 encoding rules.

I don't think this is a case worth working around because I guarantee whatever client sent this is the only client in existence that does this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3rd-party-client-bug The bug appears to be in the other client
Projects
None yet
Development

No branches or pull requests

2 participants