Comments
Patch
@@ -203,6 +203,7 @@ test-http.t
test-hybridencode.py
test-identify.t
test-import-bypass.t
+test-import-eol.t
test-import-merge.t
test-import-unknown.t
test-import.t
@@ -11,6 +11,8 @@ import email
import email.charset
import email.header
import email.message
+import email.parser
+import io
import os
import smtplib
import socket
@@ -322,6 +324,23 @@ def mimeencode(ui, s, charsets=None, dis
s, cs = _encode(ui, s, charsets)
return mimetextqp(s, 'plain', cs)
+if pycompat.ispy3:
+ def parse(fp):
+ ep = email.parser.Parser()
+ # disable the "universal newlines" mode, which isn't binary safe.
+ # I have no idea if ascii/surrogateescape is correct, but that's
+ # what the standard Python email parser does.
+ fp = io.TextIOWrapper(fp, encoding=r'ascii',
+ errors=r'surrogateescape', newline=chr(10))
+ try:
+ return ep.parse(fp)
+ finally:
+ fp.detach()
+else:
+ def parse(fp):
+ ep = email.parser.Parser()
+ return ep.parse(fp)
+
def headdecode(s):
'''Decodes RFC-2047 header'''
uparts = []
@@ -112,7 +112,7 @@ def split(stream):
cur.append(line)
c = chunk(cur)
- m = pycompat.emailparser().parse(c)
+ m = mail.parse(c)
if not m.is_multipart():
yield msgfp(m)
else:
@@ -230,7 +230,7 @@ def _extract(ui, fileobj, tmpname, tmpfp
data = {}
- msg = pycompat.emailparser().parse(fileobj)
+ msg = mail.parse(fileobj)
subject = msg[r'Subject'] and mail.headdecode(msg[r'Subject'])
data['user'] = msg[r'From'] and mail.headdecode(msg[r'From'])
@@ -295,10 +295,6 @@ if ispy3:
ret = shlex.split(s.decode('latin-1'), comments, posix)
return [a.encode('latin-1') for a in ret]
- def emailparser(*args, **kwargs):
- import email.parser
- return email.parser.BytesParser(*args, **kwargs)
-
else:
import cStringIO
@@ -371,10 +367,6 @@ else:
rawinput = raw_input
getargspec = inspect.getargspec
- def emailparser(*args, **kwargs):
- import email.parser
- return email.parser.Parser(*args, **kwargs)
-
isjython = sysplatform.startswith('java')
isdarwin = sysplatform == 'darwin'