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

QuotedPrintableEncoder max line length should be 76 instead of 71 #743

Closed
RaniRishmawi opened this issue Jan 11, 2022 · 5 comments
Closed
Labels
enhancement New feature or request

Comments

@RaniRishmawi
Copy link

When setting the ContentTransferEncoding property to ContentEncoding.QuotedPrintable the encoder encodes the lines so that each is maxed to 71 (other than the equals sign). According to the standard, the max should be 76. This might not be a problem when decoding, but for some reason, in our case, we need it to be 76. Is it possible that we improve the way a MimePart is composed so that we can inject our own encoder implementation? also, is it possible that the class QuotedPrintableEncoder itself has a constructor to specify the max length of the line?

@jstedfast
Copy link
Owner

Why do you need it to be 76? (I'm not saying "no" to this change, I'm just curious).

What you can do is to pre-encode the stream that you add to the MimeContent and also set the MimeContent's encoding to quoted-printable.

When MimePart's WriteTo() method gets called, if the MimeContent stream is already encoded in the MimePart's ContentTransferENcoding, then no transforms are applied - it will just write the MimeContent's stream directly to the output.

in other words:

var content = new MimeContent (qpEncodedStream, ContentEncoding.QuotedPrintable);
var mimePart = new MimePart ("application", "octet-stream") {
    ContentTransferEncoding = ContentEncoding.QuotedPrintable,
    Content = content
};

Hope that clarifies what I mean.

also, is it possible that the class QuotedPrintableEncoder itself has a constructor to specify the max length of the line?

Yea, I would consider adding this functionality similar to the way the Base64Encoder .ctor takes a int maxLineLength argument.

@jstedfast jstedfast added the enhancement New feature or request label Jan 11, 2022
@RaniRishmawi
Copy link
Author

Some gateways do re-encode messages again while passing through their systems. One example is SendGrid. if the message is signed then it is a problem to encode using a max line of 72 before sending and encoding to 76 in the gateway as it will corrupt the signature verification. I understand your solution, I will use it and let you know.

jstedfast added a commit that referenced this issue Jan 13, 2022
@jstedfast
Copy link
Owner

SendGrid should not be re-encoding anything within a multipart/signed 😞

jstedfast added a commit that referenced this issue Jan 13, 2022
jstedfast added a commit that referenced this issue Jan 13, 2022
Use this value when creating the QuotedPrintable/Base64 encoder filter.

Completes the fix for issue #743
@RaniRishmawi
Copy link
Author

Thank you for the commit. are you going to release this to nuget?

@jstedfast
Copy link
Owner

This was included in the 3.1.0 release I made a day or 2 ago.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants