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

message/rfc822 attachment with blank Content-Transfer-Encoding header causes attachment to become corrupted when loaded and prepared by mimekit #1049

Closed
The-Nutty opened this issue Jun 26, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@The-Nutty
Copy link

Describe the bug
A clear and concise description of what the bug is.

Platform (please complete the following information):

  • OS: Windows, Linux
  • .NET Runtime: NET8
  • .NET Framework: NET8
  • MimeKit Version: 4.1.0 and 4.6.0 tested

To Reproduce

  1. In a new .NET console app with Mimekit installed, paste the following
var msg = MimeMessage.Load("demo.eml");
msg.Prepare(EncodingConstraint.None);

msg.WriteTo("output.eml");

With demo.eml set to copy to output directory.

  1. Run the script and it will generate output.eml
  2. Open both in a message viewer (IE outlook): demo.eml will work fine with the attached email text being readable "A medium-severity alert has been triggered....." output.eml the attachment will instead show "--=3D-th9mpsHWlvyU5398Ajg2gQ=3D=3D
    Content-Type: multipart/alternative; boundary=3D"=3D-opcn9iLL5vM98wIjSIhg+Q=
    =3D=3D"

--=3D-opcn9iLL5vM98wIjSIhg+Q=3D=3D
......."

Expected behaviour
The attachment should not be corrupted when loaded, prepared and saved by mimekit.

Additional context
This seems to only occur when time message/rfc822 header has a Content-Transfer-Encoding: header, this does not happen with either Content-Transfer-Encoding: quoted-printable or a no Content-Transfer-Encoding at all.

@jstedfast
Copy link
Owner

My gut instinct is that this is where things are going wrong:

https://github.com/jstedfast/MimeKit/blob/master/MimeKit/ParserOptions.cs#L358-L383

Technically, what is likely going wrong is the IsEncoded() logic here: https://github.com/jstedfast/MimeKit/blob/master/MimeKit/ParserOptions.cs#L282-L294

but the first link I pasted contains the "justification" for said logic and why it's being used at all.

2 possible fixes that might work:

  1. Modify IsEncoded(ContentEncoding encoding) to add ContentEncoding.Default to the list of values that return false
  2. Modify IsEncoded(IList<Header> headers) to return false if the TryParse() fails

jstedfast added a commit that referenced this issue Jun 26, 2024
@jstedfast
Copy link
Owner

I'll want to add unit tests for this (for both MimeParser and ExperimentalMimeParser) before I call this "complete", but in the meantime, I figured I'd push those potential fixes and you'll be able to test the nuget package (that will get pushed to myget.org) when the CI/CD pipeline finishes pushing out a new build/package.

@jstedfast jstedfast added the bug Something isn't working label Jun 26, 2024
@jstedfast
Copy link
Owner

FWIW, I'm also planning to push a new release probably this weekend or maybe before then if I get the free time.

@The-Nutty
Copy link
Author

Brilliant, thanks for your help really appreciate the quick response.

@jstedfast
Copy link
Owner

jstedfast commented Jun 27, 2024

Just added some unit tests and it seems like it works with my fixes.

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

No branches or pull requests

2 participants