mail: encode long unicode lines in emails properly (issue5687)
authorIgor Ippolitov <iippolitov@gmail.com>
Tue, 26 Sep 2017 16:14:57 +0300
changeset 34310 2d0c306a88c2
parent 34309 b94db1780365
child 34311 1826d695ad58
mail: encode long unicode lines in emails properly (issue5687) 3e544c074459 introduced a bug: emails Content-Transfer-Encoding is silently replaced with 'quoted-printable' while any other encoding could be used by underlying code. The problem is revealed when a long unicode line is encoded. The patch implements proper check which works for any text and encoding.
mercurial/mail.py
tests/test-keyword.t
tests/test-notify-changegroup.t
tests/test-notify.t
tests/test-patchbomb-bookmark.t
tests/test-patchbomb.t
--- a/mercurial/mail.py	Sat Sep 23 14:58:40 2017 -0700
+++ b/mercurial/mail.py	Tue Sep 26 16:14:57 2017 +0300
@@ -10,8 +10,8 @@
 import email
 import email.charset
 import email.header
+import email.message
 import os
-import quopri
 import smtplib
 import socket
 import time
@@ -216,17 +216,17 @@
     '''Return MIME message.
     Quoted-printable transfer encoding will be used if necessary.
     '''
-    enc = None
+    cs = email.charset.Charset(charset)
+    msg = email.message.Message()
+    msg.set_type('text/' + subtype)
+
     for line in body.splitlines():
         if len(line) > 950:
-            body = quopri.encodestring(body)
-            enc = "quoted-printable"
+            cs.body_encoding = email.charset.QP
             break
 
-    msg = email.MIMEText.MIMEText(body, subtype, charset)
-    if enc:
-        del msg['Content-Transfer-Encoding']
-        msg['Content-Transfer-Encoding'] = enc
+    msg.set_payload(body, cs)
+
     return msg
 
 def _charsets(ui):
--- a/tests/test-keyword.t	Sat Sep 23 14:58:40 2017 -0700
+++ b/tests/test-keyword.t	Tue Sep 26 16:14:57 2017 +0300
@@ -260,8 +260,8 @@
   adding manifests
   adding file changes
   added 2 changesets with 3 changes to 3 files
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Date: * (glob)
   Subject: changeset in...
@@ -283,8 +283,8 @@
   @@ -0,0 +1,1 @@
   +a
   \ No newline at end of file
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Date:* (glob)
   Subject: changeset in...
--- a/tests/test-notify-changegroup.t	Sat Sep 23 14:58:40 2017 -0700
+++ b/tests/test-notify-changegroup.t	Tue Sep 26 16:14:57 2017 +0300
@@ -46,8 +46,8 @@
   adding manifests
   adding file changes
   added 2 changesets with 2 changes to 1 files
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Date: * (glob)
   Subject: * (glob)
@@ -97,8 +97,8 @@
   adding manifests
   adding file changes
   added 2 changesets with 2 changes to 1 files
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Date: * (glob)
   Subject: * (glob)
@@ -174,8 +174,8 @@
   adding manifests
   adding file changes
   added 4 changesets with 4 changes to 1 files
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Date: * (glob)
   Subject: * (glob)
--- a/tests/test-notify.t	Sat Sep 23 14:58:40 2017 -0700
+++ b/tests/test-notify.t	Tue Sep 26 16:14:57 2017 +0300
@@ -188,8 +188,8 @@
   adding manifests
   adding file changes
   added 1 changesets with 1 changes to 1 files
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Date: * (glob)
   Subject: changeset in $TESTTMP/b: b
@@ -241,8 +241,8 @@
   adding manifests
   adding file changes
   added 1 changesets with 1 changes to 1 files
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   X-Test: foo
   Date: * (glob)
@@ -283,8 +283,8 @@
   adding manifests
   adding file changes
   added 1 changesets with 1 changes to 1 files
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   X-Test: foo
   Date: * (glob)
@@ -328,8 +328,8 @@
   adding manifests
   adding file changes
   added 2 changesets with 0 changes to 0 files
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   X-Test: foo
   Date: * (glob)
@@ -351,8 +351,8 @@
   +++ b/a	Thu Jan 01 00:00:02 1970 +0000
   @@ -1,1 +1,2 @@ a
   +a
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   X-Test: foo
   Date: * (glob)
@@ -383,8 +383,8 @@
   adding manifests
   adding file changes
   added 1 changesets with 1 changes to 1 files
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 8bit
   X-Test: foo
   Date: * (glob)
@@ -416,7 +416,7 @@
   > test = False
   > mbox = mbox
   > EOF
-  $ $PYTHON -c 'file("a/a", "ab").write("no" * 500 + "\n")'
+  $ $PYTHON -c 'file("a/a", "ab").write("no" * 500 + "\xd1\x84" + "\n")'
   $ hg --cwd a commit -A -m "long line"
   $ hg --traceback --cwd b pull ../a
   pulling from ../a
@@ -429,25 +429,25 @@
   (run 'hg update' to get a working copy)
   $ $PYTHON $TESTTMP/filter.py < b/mbox
   From test@test.com ... ... .. ..:..:.. .... (re)
-  Content-Type: text/plain; charset="us-ascii"
   MIME-Version: 1.0
+  Content-Type: text/plain; charset="*" (glob)
   Content-Transfer-Encoding: quoted-printable
   X-Test: foo
   Date: * (glob)
   Subject: long line
   From: test@test.com
-  X-Hg-Notification: changeset e0be44cf638b
-  Message-Id: <hg.e0be44cf638b.*.*@*> (glob)
+  X-Hg-Notification: changeset a323cae54f6e
+  Message-Id: <hg.a323cae54f6e.*.*@*> (glob)
   To: baz@test.com, foo@bar
   
-  changeset e0be44cf638b in b
+  changeset a323cae54f6e in b
   description: long line
   diffstat:
    a |  1 + 1 files changed, 1 insertions(+), 0 deletions(-)
   
   diffs (8 lines):
   
-  diff -r 7ea05ad269dc -r e0be44cf638b a
+  diff -r 7ea05ad269dc -r a323cae54f6e a
   --- a/a	Thu Jan 01 00:00:00 1970 +0000
   +++ b/a	Thu Jan 01 00:00:00 1970 +0000
   @@ -1,3 +1,4 @@ a a a
@@ -464,7 +464,7 @@
   ononononononononononononononononononononononononononononononononononononono=
   nononononononononononononononononononononononononononononononononononononon=
   ononononononononononononononononononononononononononononononononononononono=
-  nonononononononononononono
+  nonononononononononononono=D1=84
   
  revset selection: send to address that matches branch and repo
 
@@ -494,18 +494,18 @@
   adding manifests
   adding file changes
   added 1 changesets with 1 changes to 1 files
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   X-Test: foo
   Date: * (glob)
   Subject: test
   From: test@test.com
-  X-Hg-Notification: changeset fbbcbc516f2f
-  Message-Id: <hg.fbbcbc516f2f.*.*@*> (glob)
+  X-Hg-Notification: changeset b7cf10b2bdec
+  Message-Id: <hg.b7cf10b2bdec.*.*@*> (glob)
   To: baz@test.com, foo@bar, notify@example.com
   
-  changeset fbbcbc516f2f in b
+  changeset b7cf10b2bdec in b
   description: test
   (run 'hg update' to get a working copy)
 
@@ -523,18 +523,18 @@
   adding manifests
   adding file changes
   added 1 changesets with 0 changes to 0 files (+1 heads)
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   X-Test: foo
   Date: * (glob)
   Subject: test
   From: test@test.com
-  X-Hg-Notification: changeset 38b42fa092de
-  Message-Id: <hg.38b42fa092de.*.*@*> (glob)
+  X-Hg-Notification: changeset 5a07df312a79
+  Message-Id: <hg.5a07df312a79.*.*@*> (glob)
   To: baz@test.com, foo@bar
   
-  changeset 38b42fa092de in b
+  changeset 5a07df312a79 in b
   description: test
   (run 'hg heads' to see heads)
 
@@ -545,18 +545,18 @@
   $ echo a >> a/a
   $ hg --cwd a commit -m 'default template'
   $ hg --cwd b pull ../a -q | $PYTHON $TESTTMP/filter.py
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Date: * (glob)
   Subject: changeset in b: default template
   From: test@test.com
-  X-Hg-Notification: changeset 3548c9e294b6
-  Message-Id: <hg.3548c9e294b6.*.*@*> (glob)
+  X-Hg-Notification: changeset f5e8ec95bf59
+  Message-Id: <hg.f5e8ec95bf59.*.*@*> (glob)
   To: baz@test.com, foo@bar
   
-  changeset 3548c9e294b6 in $TESTTMP/b (glob)
-  details: http://test/b?cmd=changeset;node=3548c9e294b6
+  changeset f5e8ec95bf59 in $TESTTMP/b (glob)
+  details: http://test/b?cmd=changeset;node=f5e8ec95bf59
   description: default template
 
 with style:
@@ -574,17 +574,17 @@
   $ echo a >> a/a
   $ hg --cwd a commit -m 'with style'
   $ hg --cwd b pull ../a -q | $PYTHON $TESTTMP/filter.py
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Date: * (glob)
   Subject: with style
   From: test@test.com
-  X-Hg-Notification: changeset e917dbd961d3
-  Message-Id: <hg.e917dbd961d3.*.*@*> (glob)
+  X-Hg-Notification: changeset 9e2c3a8e9c43
+  Message-Id: <hg.9e2c3a8e9c43.*.*@*> (glob)
   To: baz@test.com, foo@bar
   
-  changeset e917dbd961d3
+  changeset 9e2c3a8e9c43
 
 with template (overrides style):
 
@@ -597,14 +597,14 @@
   $ echo a >> a/a
   $ hg --cwd a commit -m 'with template'
   $ hg --cwd b pull ../a -q | $PYTHON $TESTTMP/filter.py
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Date: * (glob)
-  Subject: a09743fd3edd: with template
+  Subject: e2cbf5bf18a7: with template
   From: test@test.com
-  X-Hg-Notification: changeset a09743fd3edd
-  Message-Id: <hg.a09743fd3edd.*.*@*> (glob)
+  X-Hg-Notification: changeset e2cbf5bf18a7
+  Message-Id: <hg.e2cbf5bf18a7.*.*@*> (glob)
   To: baz@test.com, foo@bar
   
   with template
--- a/tests/test-patchbomb-bookmark.t	Sat Sep 23 14:58:40 2017 -0700
+++ b/tests/test-patchbomb-bookmark.t	Tue Sep 26 16:14:57 2017 +0300
@@ -31,8 +31,8 @@
   Cc: 
   
   displaying [PATCH 0 of 2] bookmark ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH 0 of 2] bookmark
   Message-Id: <patchbomb.347155260@*> (glob)
@@ -43,8 +43,8 @@
   
   
   displaying [PATCH 1 of 2] first ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH 1 of 2] first
   X-Mercurial-Node: accde9b8b6dce861c185d0825c1affc09a79cb26
@@ -74,8 +74,8 @@
   +first
   
   displaying [PATCH 2 of 2] second ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH 2 of 2] second
   X-Mercurial-Node: 417defd1559c396ba06a44dce8dc1c2d2d653f3f
@@ -138,8 +138,8 @@
   Cc: 
   
   displaying [PATCH] bookmark ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH] bookmark
   X-Mercurial-Node: 8dab2639fd35f1e337ad866c372a5c44f1064e3c
--- a/tests/test-patchbomb.t	Sat Sep 23 14:58:40 2017 -0700
+++ b/tests/test-patchbomb.t	Tue Sep 26 16:14:57 2017 +0300
@@ -40,8 +40,8 @@
   
   
   displaying [PATCH] a ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH] a
   X-Mercurial-Node: 8580ff50825a50c8f716709acdf8de0deddcd6ab
@@ -79,8 +79,8 @@
   
   
   displaying [PATCH] a ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH] a
   X-Mercurial-Node: 8580ff50825a50c8f716709acdf8de0deddcd6ab
@@ -154,8 +154,8 @@
   
   
   displaying [PATCH] a ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH] a
   X-Mercurial-Node: 8580ff50825a50c8f716709acdf8de0deddcd6ab
@@ -192,8 +192,8 @@
   
   
   displaying [PATCH] a ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH] a
   X-Mercurial-Node: 8580ff50825a50c8f716709acdf8de0deddcd6ab
@@ -234,8 +234,8 @@
   
   
   displaying [PATCH 0 of 2] test ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH 0 of 2] test
   Message-Id: <patchbomb.120@*> (glob)
@@ -247,8 +247,8 @@
   
   
   displaying [PATCH 1 of 2] a ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH 1 of 2] a
   X-Mercurial-Node: 8580ff50825a50c8f716709acdf8de0deddcd6ab
@@ -279,8 +279,8 @@
   +a
   
   displaying [PATCH 2 of 2] b ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH 2 of 2] b
   X-Mercurial-Node: 97d72e5f12c7e84f85064aa72e5a297142c36ed9
@@ -375,8 +375,8 @@
   Cc: bar
   
   --===*= (glob)
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   
   a multiline
@@ -420,8 +420,8 @@
   Cc: bar
   
   --===*= (glob)
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   
   a multiline
@@ -453,8 +453,8 @@
   
   
   displaying [PATCH] utf-8 content ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 8bit
   Subject: [PATCH] utf-8 content
   X-Mercurial-Node: 909a00e13e9d78b575aeee23dddbada46d5a143f
@@ -499,8 +499,8 @@
 
   $ cat mbox
   From quux ... ... .. ..:..:.. .... (re)
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="utf-8"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: base64
   Subject: [PATCH] utf-8 content
   X-Mercurial-Node: 909a00e13e9d78b575aeee23dddbada46d5a143f
@@ -561,8 +561,8 @@
   
   
   displaying [PATCH] long line ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: quoted-printable
   Subject: [PATCH] long line
   X-Mercurial-Node: a2ea8fc83dd8b93cfd86ac97b28287204ab806e1
@@ -615,8 +615,8 @@
   sending [PATCH] long line ...
   $ cat mbox
   From quux ... ... .. ..:..:.. .... (re)
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: quoted-printable
   Subject: [PATCH] long line
   X-Mercurial-Node: a2ea8fc83dd8b93cfd86ac97b28287204ab806e1
@@ -677,8 +677,8 @@
   sending [PATCH] isolatin 8-bit encoding ...
   $ cat mbox
   From quux ... ... .. ..:..:.. .... (re)
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="iso-8859-1"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: quoted-printable
   Subject: [PATCH] isolatin 8-bit encoding
   X-Mercurial-Node: 240fb913fc1b7ff15ddb9f33e73d82bf5277c720
@@ -725,8 +725,8 @@
   are you sure you want to send (yn)? y
   
   displaying [PATCH] test ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH] test
   X-Mercurial-Node: ff2c9fa2018b15fa74b33363bda9527323e2a99f
@@ -787,8 +787,8 @@
   are you sure you want to send (yn)? y
   
   displaying [PATCH 0 of 2] test ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH 0 of 2] test
   Message-Id: <patchbomb.60@*> (glob)
@@ -804,8 +804,8 @@
    2 files changed, 2 insertions(+), 0 deletions(-)
   
   displaying [PATCH 1 of 2] a ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH 1 of 2] a
   X-Mercurial-Node: 8580ff50825a50c8f716709acdf8de0deddcd6ab
@@ -840,8 +840,8 @@
   +a
   
   displaying [PATCH 2 of 2] b ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH 2 of 2] b
   X-Mercurial-Node: 97d72e5f12c7e84f85064aa72e5a297142c36ed9
@@ -897,8 +897,8 @@
   Cc: bar
   
   --===*= (glob)
+  MIME-Version: 1.0
   Content-Type: text/x-patch; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Content-Disposition: inline; filename=t2.patch
   
@@ -940,8 +940,8 @@
   Cc: bar
   
   --===*= (glob)
+  MIME-Version: 1.0
   Content-Type: text/x-patch; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: quoted-printable
   Content-Disposition: inline; filename=t2.patch
   
@@ -987,8 +987,8 @@
   
   
   displaying [PATCH 0 of 3] test ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH 0 of 3] test
   Message-Id: <patchbomb.60@*> (glob)
@@ -1017,8 +1017,8 @@
   Cc: bar
   
   --===*= (glob)
+  MIME-Version: 1.0
   Content-Type: text/x-patch; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Content-Disposition: inline; filename=t2-1.patch
   
@@ -1055,8 +1055,8 @@
   Cc: bar
   
   --===*= (glob)
+  MIME-Version: 1.0
   Content-Type: text/x-patch; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Content-Disposition: inline; filename=t2-2.patch
   
@@ -1093,8 +1093,8 @@
   Cc: bar
   
   --===*= (glob)
+  MIME-Version: 1.0
   Content-Type: text/x-patch; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: quoted-printable
   Content-Disposition: inline; filename=t2-3.patch
   
@@ -1151,8 +1151,8 @@
   Cc: bar
   
   --===*= (glob)
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   
   Patch subject is complete summary.
@@ -1160,8 +1160,8 @@
   
   
   --===*= (glob)
+  MIME-Version: 1.0
   Content-Type: text/x-patch; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Content-Disposition: attachment; filename=t2.patch
   
@@ -1202,8 +1202,8 @@
   Cc: bar
   
   --===*= (glob)
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   
   Patch subject is complete summary.
@@ -1211,8 +1211,8 @@
   
   
   --===*= (glob)
+  MIME-Version: 1.0
   Content-Type: text/x-patch; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: quoted-printable
   Content-Disposition: attachment; filename=t2.patch
   
@@ -1269,8 +1269,8 @@
   Cc: bar
   
   --===*= (glob)
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   
   # HG changeset patch
@@ -1288,8 +1288,8 @@
   +c
   
   --===*= (glob)
+  MIME-Version: 1.0
   Content-Type: text/x-patch; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Content-Disposition: attachment; filename=t2.patch
   
@@ -1319,8 +1319,8 @@
   
   
   displaying [PATCH 0 of 3] test ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH 0 of 3] test
   Message-Id: <patchbomb.60@*> (glob)
@@ -1349,8 +1349,8 @@
   Cc: bar
   
   --===*= (glob)
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   
   Patch subject is complete summary.
@@ -1358,8 +1358,8 @@
   
   
   --===*= (glob)
+  MIME-Version: 1.0
   Content-Type: text/x-patch; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Content-Disposition: attachment; filename=t2-1.patch
   
@@ -1396,8 +1396,8 @@
   Cc: bar
   
   --===*= (glob)
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   
   Patch subject is complete summary.
@@ -1405,8 +1405,8 @@
   
   
   --===*= (glob)
+  MIME-Version: 1.0
   Content-Type: text/x-patch; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Content-Disposition: attachment; filename=t2-2.patch
   
@@ -1443,8 +1443,8 @@
   Cc: bar
   
   --===*= (glob)
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   
   Patch subject is complete summary.
@@ -1452,8 +1452,8 @@
   
   
   --===*= (glob)
+  MIME-Version: 1.0
   Content-Type: text/x-patch; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: quoted-printable
   Content-Disposition: attachment; filename=t2-3.patch
   
@@ -1499,8 +1499,8 @@
   
   
   displaying [PATCH 0 of 1] test ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH 0 of 1] test
   Message-Id: <patchbomb.60@*> (glob)
@@ -1512,8 +1512,8 @@
   
   
   displaying [PATCH 1 of 1] c ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH 1 of 1] c
   X-Mercurial-Node: ff2c9fa2018b15fa74b33363bda9527323e2a99f
@@ -1552,8 +1552,8 @@
   
   
   displaying [PATCH 0 of 1] test ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH 0 of 1] test
   Message-Id: <patchbomb.60@*> (glob)
@@ -1566,8 +1566,8 @@
   foo
   
   displaying [PATCH 1 of 1] c ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH 1 of 1] c
   X-Mercurial-Node: ff2c9fa2018b15fa74b33363bda9527323e2a99f
@@ -1608,8 +1608,8 @@
   
   
   displaying [PATCH 0 of 2] test ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH 0 of 2] test
   Message-Id: <patchbomb.60@*> (glob)
@@ -1621,8 +1621,8 @@
   
   
   displaying [PATCH 1 of 2] a ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH 1 of 2] a
   X-Mercurial-Node: 8580ff50825a50c8f716709acdf8de0deddcd6ab
@@ -1653,8 +1653,8 @@
   +a
   
   displaying [PATCH 2 of 2] b ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH 2 of 2] b
   X-Mercurial-Node: 97d72e5f12c7e84f85064aa72e5a297142c36ed9
@@ -1692,8 +1692,8 @@
   
   
   displaying [PATCH] test ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH] test
   X-Mercurial-Node: ff2c9fa2018b15fa74b33363bda9527323e2a99f
@@ -1730,8 +1730,8 @@
   
   
   displaying [PATCH] test ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH] test
   X-Mercurial-Node: ff2c9fa2018b15fa74b33363bda9527323e2a99f
@@ -1788,8 +1788,8 @@
   Cc: bar
   
   --===*= (glob)
+  MIME-Version: 1.0
   Content-Type: text/x-patch; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Content-Disposition: inline; filename=two.diff
   
@@ -1819,8 +1819,8 @@
   
   
   displaying [PATCH 0 of 2] test ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH 0 of 2] test
   Message-Id: <patchbomb.60@*> (glob)
@@ -1849,8 +1849,8 @@
   Cc: bar
   
   --===*= (glob)
+  MIME-Version: 1.0
   Content-Type: text/x-patch; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Content-Disposition: inline; filename=t2-1.patch
   
@@ -1887,8 +1887,8 @@
   Cc: bar
   
   --===*= (glob)
+  MIME-Version: 1.0
   Content-Type: text/x-patch; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Content-Disposition: inline; filename=one.patch
   
@@ -1916,8 +1916,8 @@
   
   
   displaying [PATCH] Added tag two, two.diff for changeset ff2c9fa2018b ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH] Added tag two, two.diff for changeset ff2c9fa2018b
   X-Mercurial-Node: 7aead2484924c445ad8ce2613df91f52f9e502ed
@@ -1959,8 +1959,8 @@
   (optional) Subject: [PATCH 0 of 2] 
   
   displaying [PATCH 1 of 2] a ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH 1 of 2] a
   X-Mercurial-Node: 8580ff50825a50c8f716709acdf8de0deddcd6ab
@@ -1991,8 +1991,8 @@
   +a
   
   displaying [PATCH 2 of 2] b ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH 2 of 2] b
   X-Mercurial-Node: 97d72e5f12c7e84f85064aa72e5a297142c36ed9
@@ -2034,8 +2034,8 @@
   
   
   displaying [PATCH 0 of 2] test ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH 0 of 2] test
   Message-Id: <patchbomb.60@*> (glob)
@@ -2049,8 +2049,8 @@
   
   
   displaying [PATCH 1 of 2] a ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH 1 of 2] a
   X-Mercurial-Node: 8580ff50825a50c8f716709acdf8de0deddcd6ab
@@ -2081,8 +2081,8 @@
   +a
   
   displaying [PATCH 2 of 2] b ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH 2 of 2] b
   X-Mercurial-Node: 97d72e5f12c7e84f85064aa72e5a297142c36ed9
@@ -2122,8 +2122,8 @@
   
   
   displaying [PATCH fooFlag] test ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH fooFlag] test
   X-Mercurial-Node: ff2c9fa2018b15fa74b33363bda9527323e2a99f
@@ -2163,8 +2163,8 @@
   
   
   displaying [PATCH 0 of 2 fooFlag] test ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH 0 of 2 fooFlag] test
   Message-Id: <patchbomb.60@*> (glob)
@@ -2176,8 +2176,8 @@
   
   
   displaying [PATCH 1 of 2 fooFlag] a ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH 1 of 2 fooFlag] a
   X-Mercurial-Node: 8580ff50825a50c8f716709acdf8de0deddcd6ab
@@ -2208,8 +2208,8 @@
   +a
   
   displaying [PATCH 2 of 2 fooFlag] b ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH 2 of 2 fooFlag] b
   X-Mercurial-Node: 97d72e5f12c7e84f85064aa72e5a297142c36ed9
@@ -2249,8 +2249,8 @@
   
   
   displaying [PATCH fooFlag barFlag] test ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH fooFlag barFlag] test
   X-Mercurial-Node: ff2c9fa2018b15fa74b33363bda9527323e2a99f
@@ -2289,8 +2289,8 @@
   
   
   displaying [PATCH 0 of 2 fooFlag barFlag] test ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH 0 of 2 fooFlag barFlag] test
   Message-Id: <patchbomb.60@*> (glob)
@@ -2302,8 +2302,8 @@
   
   
   displaying [PATCH 1 of 2 fooFlag barFlag] a ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH 1 of 2 fooFlag barFlag] a
   X-Mercurial-Node: 8580ff50825a50c8f716709acdf8de0deddcd6ab
@@ -2334,8 +2334,8 @@
   +a
   
   displaying [PATCH 2 of 2 fooFlag barFlag] b ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH 2 of 2 fooFlag barFlag] b
   X-Mercurial-Node: 97d72e5f12c7e84f85064aa72e5a297142c36ed9
@@ -2376,8 +2376,8 @@
   sending [PATCH] test ...
   $ cat < tmp.mbox
   From quux ... ... .. ..:..:.. .... (re)
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH] test
   X-Mercurial-Node: 8580ff50825a50c8f716709acdf8de0deddcd6ab
@@ -2418,8 +2418,8 @@
   Cc: 
   
   displaying [PATCH 0 of 2 R1] test ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH 0 of 2 R1] test
   Message-Id: <patchbomb.60@*> (glob)
@@ -2431,8 +2431,8 @@
   foo
   
   displaying [PATCH 1 of 2 R0] a ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH 1 of 2 R0] a
   X-Mercurial-Node: 8580ff50825a50c8f716709acdf8de0deddcd6ab
@@ -2462,8 +2462,8 @@
   +a
   
   displaying [PATCH 2 of 2 R1] b ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH 2 of 2 R1] b
   X-Mercurial-Node: 97d72e5f12c7e84f85064aa72e5a297142c36ed9
@@ -2501,8 +2501,8 @@
   Cc: 
   
   displaying [PATCH default V2] a ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH default V2] a
   X-Mercurial-Node: 8580ff50825a50c8f716709acdf8de0deddcd6ab
@@ -2543,8 +2543,8 @@
 
   $ cat tmp.mbox
   From quux ... ... .. ..:..:.. .... (re)
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH] test
   X-Mercurial-Node: 8580ff50825a50c8f716709acdf8de0deddcd6ab
@@ -2621,8 +2621,8 @@
   Cc: 
   
   displaying [PATCH 0 of 6] test ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH 0 of 6] test
   Message-Id: <patchbomb.315532860@*> (glob)
@@ -2633,8 +2633,8 @@
   
   
   displaying [PATCH 1 of 6] c ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH 1 of 6] c
   X-Mercurial-Node: ff2c9fa2018b15fa74b33363bda9527323e2a99f
@@ -2664,8 +2664,8 @@
   +c
   
   displaying [PATCH 2 of 6] utf-8 content ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 8bit
   Subject: [PATCH 2 of 6] utf-8 content
   X-Mercurial-Node: 909a00e13e9d78b575aeee23dddbada46d5a143f
@@ -2702,8 +2702,8 @@
   +h\xc3\xb6mma! (esc)
   
   displaying [PATCH 3 of 6] long line ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: quoted-printable
   Subject: [PATCH 3 of 6] long line
   X-Mercurial-Node: a2ea8fc83dd8b93cfd86ac97b28287204ab806e1
@@ -2749,8 +2749,8 @@
   +bar
   
   displaying [PATCH 4 of 6] isolatin 8-bit encoding ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 8bit
   Subject: [PATCH 4 of 6] isolatin 8-bit encoding
   X-Mercurial-Node: 240fb913fc1b7ff15ddb9f33e73d82bf5277c720
@@ -2780,8 +2780,8 @@
   +h\xf6mma! (esc)
   
   displaying [PATCH 5 of 6] Added tag zero, zero.foo for changeset 8580ff50825a ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH 5 of 6] Added tag zero, zero.foo for changeset 8580ff50825a
   X-Mercurial-Node: 5d5ef15dfe5e7bd3a4ee154b5fff76c7945ec433
@@ -2812,8 +2812,8 @@
   +8580ff50825a50c8f716709acdf8de0deddcd6ab zero.foo
   
   displaying [PATCH 6 of 6] d ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH 6 of 6] d
   X-Mercurial-Node: 2f9fa9b998c5fe3ac2bd9a2b14bfcbeecbc7c268
@@ -2857,8 +2857,8 @@
   
   
   displaying [PATCH] test ...
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH] test
   X-Mercurial-Node: 2f9fa9b998c5fe3ac2bd9a2b14bfcbeecbc7c268
@@ -2992,8 +2992,8 @@
   warning: invalid patchbomb.intro value "mpmwearaclownnose"
   (should be one of always, never, auto)
   -f test foo
+  MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
-  MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
   Subject: [PATCH] test
   X-Mercurial-Node: 3b6f1ec9dde933a40a115a7990f8b320477231af