changeset 6447:9d2ce19bdacd

patchbomb: Fix mangling of lines beginning with From we should mangle the lines beginning with From only when writing to mbox format.
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Wed, 02 Apr 2008 01:49:29 +0200
parents ee5313bc3c0c
children cd3d49ffc6f6
files hgext/patchbomb.py
diffstat 1 files changed, 10 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/patchbomb.py	Tue Apr 01 14:35:35 2008 +0200
+++ b/hgext/patchbomb.py	Wed Apr 02 01:49:29 2008 +0200
@@ -66,7 +66,8 @@
 
 import os, errno, socket, tempfile
 import email.MIMEMultipart, email.MIMEText, email.MIMEBase
-import email.Utils, email.Encoders
+import email.Utils, email.Encoders, email.Generator
+import cStringIO.StringIO
 from mercurial import cmdutil, commands, hg, mail, patch, util
 from mercurial.i18n import _
 from mercurial.node import bin
@@ -407,8 +408,9 @@
                 fp = os.popen(os.environ['PAGER'], 'w')
             else:
                 fp = ui
+            generator = email.Generator.Generator(fp, mangle_from_=False)
             try:
-                fp.write(m.as_string(0))
+                generator.flatten(m, 0)
                 fp.write('\n')
             except IOError, inst:
                 if inst.errno != errno.EPIPE:
@@ -418,9 +420,10 @@
         elif opts.get('mbox'):
             ui.status('Writing ', m['Subject'], ' ...\n')
             fp = open(opts.get('mbox'), 'In-Reply-To' in m and 'ab+' or 'wb+')
+            generator = email.Generator.Generator(fp, mangle_from_=True)
             date = util.datestr(start_time, '%a %b %d %H:%M:%S %Y')
             fp.write('From %s %s\n' % (sender_addr, date))
-            fp.write(m.as_string(0))
+            generator.flatten(m, 0)
             fp.write('\n\n')
             fp.close()
         else:
@@ -429,7 +432,10 @@
             ui.status('Sending ', m['Subject'], ' ...\n')
             # Exim does not remove the Bcc field
             del m['Bcc']
-            sendmail(sender, to + bcc + cc, m.as_string(0))
+            fp = cStringIO.StringIO()
+            generator = email.Generator.Generator(fp, mangle_from_=False)
+            generator.flatten(m, 0)
+            sendmail(sender, to + bcc + cc, fp.getvalue())
 
 cmdtable = {
     "email":