Show More
@@ -332,3 +332,21 b' def mimeencode(ui, s, charsets=None, dis' | |||
|
332 | 332 | if not display: |
|
333 | 333 | s, cs = _encode(ui, s, charsets) |
|
334 | 334 | return mimetextqp(s, 'plain', cs) |
|
335 | ||
|
336 | def headdecode(s): | |
|
337 | '''Decodes RFC-2047 header''' | |
|
338 | uparts = [] | |
|
339 | for part, charset in email.Header.decode_header(s): | |
|
340 | if charset is not None: | |
|
341 | try: | |
|
342 | uparts.append(part.decode(charset)) | |
|
343 | continue | |
|
344 | except UnicodeDecodeError: | |
|
345 | pass | |
|
346 | try: | |
|
347 | uparts.append(part.decode('UTF-8')) | |
|
348 | continue | |
|
349 | except UnicodeDecodeError: | |
|
350 | pass | |
|
351 | uparts.append(part.decode('ISO-8859-1')) | |
|
352 | return encoding.tolocal(u' '.join(uparts).encode('UTF-8')) |
@@ -31,6 +31,7 b' from . import (' | |||
|
31 | 31 | diffhelpers, |
|
32 | 32 | encoding, |
|
33 | 33 | error, |
|
34 | mail, | |
|
34 | 35 | mdiff, |
|
35 | 36 | pathutil, |
|
36 | 37 | scmutil, |
@@ -210,8 +211,8 b' def extract(ui, fileobj):' | |||
|
210 | 211 | try: |
|
211 | 212 | msg = email.Parser.Parser().parse(fileobj) |
|
212 | 213 | |
|
213 | subject = msg['Subject'] | |
|
214 | data['user'] = msg['From'] | |
|
214 | subject = msg['Subject'] and mail.headdecode(msg['Subject']) | |
|
215 | data['user'] = msg['From'] and mail.headdecode(msg['From']) | |
|
215 | 216 | if not subject and not data['user']: |
|
216 | 217 | # Not an email, restore parsed headers if any |
|
217 | 218 | subject = '\n'.join(': '.join(h) for h in msg.items()) + '\n' |
@@ -822,4 +822,27 b' Test corner case involving copies and mu' | |||
|
822 | 822 | > EOF |
|
823 | 823 | applying patch from stdin |
|
824 | 824 | |
|
825 | Test email metadata | |
|
826 | ||
|
827 | $ hg revert -qa | |
|
828 | $ hg --encoding utf-8 import - <<EOF | |
|
829 | > From: =?UTF-8?q?Rapha=C3=ABl=20Hertzog?= <hertzog@debian.org> | |
|
830 | > Subject: [PATCH] =?UTF-8?q?=C5=A7=E2=82=AC=C3=9F=E1=B9=AA?= | |
|
831 | > | |
|
832 | > diff --git a/a b/a | |
|
833 | > --- a/a | |
|
834 | > +++ b/a | |
|
835 | > @@ -1,1 +1,2 @@ | |
|
836 | > a | |
|
837 | > +a | |
|
838 | > EOF | |
|
839 | applying patch from stdin | |
|
840 | $ hg --encoding utf-8 log -r . | |
|
841 | changeset: 2:* (glob) | |
|
842 | tag: tip | |
|
843 | user: Rapha\xc3\xabl Hertzog <hertzog@debian.org> (esc) | |
|
844 | date: * (glob) | |
|
845 | summary: \xc5\xa7\xe2\x82\xac\xc3\x9f\xe1\xb9\xaa (esc) | |
|
846 | ||
|
847 | ||
|
825 | 848 | $ cd .. |
General Comments 0
You need to be logged in to leave comments.
Login now