Created
September 22, 2017 15:48
-
-
Save oxpa/b6d9aee3a22a6802c4445a16063d3132 to your computer and use it in GitHub Desktop.
mail.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def mimetextqp(body, subtype, charset): | |
'''Return MIME message. | |
Quoted-printable transfer encoding will be used if necessary. | |
''' | |
msg = email.MIMEText.MIMEText(body, subtype, charset) | |
if hasattr(msg, 'set_charset'): | |
# old (pre python 3.6 framework) | |
cs = email.charset.Charset(charset) | |
enc = None | |
del msg['Content-Transfer-Encoding'] | |
del msg['MIME-Version'] | |
for line in body.splitlines(): | |
if len(line) > 950: | |
body = quopri.encodestring(body) | |
cs.body_encoding = email.charset.QP | |
enc = True | |
break | |
if enc: | |
# the body is correctly encoded, just put it in place | |
msg.set_charset(cs) | |
msg.set_payload(body) | |
else: | |
# the body should be encoded | |
msg.set_payload(body) | |
msg.set_charset(cs) | |
return msg |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -r 05131c963767 mercurial/mail.py | |
--- a/mercurial/mail.py Wed Sep 20 09:35:45 2017 -0700 | |
+++ b/mercurial/mail.py Fri Sep 22 18:47:36 2017 +0300 | |
@@ -216,17 +216,28 @@ | |
'''Return MIME message. | |
Quoted-printable transfer encoding will be used if necessary. | |
''' | |
- enc = None | |
- for line in body.splitlines(): | |
- if len(line) > 950: | |
- body = quopri.encodestring(body) | |
- enc = "quoted-printable" | |
- break | |
+ msg = email.MIMEText.MIMEText(body, subtype, charset) | |
+ if hasattr(msg, 'set_charset'): | |
+ # old (pre python 3.6 framework) | |
+ cs = email.charset.Charset(charset) | |
+ enc = None | |
+ del msg['Content-Transfer-Encoding'] | |
+ del msg['MIME-Version'] | |
+ for line in body.splitlines(): | |
+ if len(line) > 950: | |
+ body = quopri.encodestring(body) | |
+ cs.body_encoding = email.charset.QP | |
+ enc = True | |
+ break | |
+ if enc: | |
+ # the body is correctly encoded, just put it in place | |
+ msg.set_charset(cs) | |
+ msg.set_payload(body) | |
+ else: | |
+ # the body should be encoded | |
+ msg.set_payload(body) | |
+ msg.set_charset(cs) | |
- msg = email.MIMEText.MIMEText(body, subtype, charset) | |
- if enc: | |
- del msg['Content-Transfer-Encoding'] | |
- msg['Content-Transfer-Encoding'] = enc | |
return msg | |
def _charsets(ui): |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment