-
Notifications
You must be signed in to change notification settings - Fork 204
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
MimePart.to_string() can produce different output depending on MimePart.was_changed() #194
Comments
I can make these changes if all of this makes sense, I just wanted to discuss it first and make sure I'm understanding everything correctly. |
All is reasonable. I would prefer the soft line breaks option. @b0d0nne11 what do you think? |
After some more investigation it appears That leaves just the first bullet, which is a much easier change 😄 |
Okay, so I did even more investigation and I think the original problem I described doesn't exist. I think the actual issue is that when we first scan a MIME string the resulting MimePart(s) return
Is this the desired behavior? |
@mhahnenberg the idea is that if we do not need to make changes to the mime the we return it as is. This is intentional. Originally we did encode message in @anton-efimenko may be you remember what why customers complained? |
You're going to laugh at me, and I'm really sorry for continually changing what this issue is about, but this has been a very tricky bug for me to figure out 😞 However, I think I might have it now (hopefully).
By default I think a quick fix for this would be for flanker to trick quopri by prepending a CRLF to the part's body and then removing it after the encoding has been performed. |
RFC1341 states:
"The Quoted-Printable encoding REQUIRES that encoded lines be no more than 76 characters long."
If we pass a long
7bit
text part with simple'\n'
in it, it will be encoded asquoted-printable
which leads to invalid output. This is due to two things:has_long_lines()
usesstr.splitlines()
, which splits universal newlines (which include'\n'
), thus reducing the perceived length of the lines (even though they're not considered line breaks in the finalquoted-printable
CTE). Instead I believe it should usestr.split('\r\n')
.Even after fixing this, we still pass
quoted-printable
as the preferred encoding inside_choose_text_encoding
even though the line length is too long. I think we should either preferbase64
for text parts with long lines (simpler implementation, butbase64
incurs a higher overhead) or convert the long lines to aquoted-printable
compatible form using "soft" line breaks.Relevant code is here: https://github.com/mailgun/flanker/blob/master/flanker/mime/message/part.py#L657
The text was updated successfully, but these errors were encountered: