notify: fix neglect of custom headers set via template
authorChristian Ebert <blacktrash@gmx.net>
Thu, 15 Jan 2009 01:38:52 +0100
changeset 7673 af4871b73be7
parent 7668 876de22b70b8
child 7674 4d63b10a602e
child 7675 011e69b96c69
notify: fix neglect of custom headers set via template e981725da3fe introduced a bug that discarded all custom headers. Add custom header to test template.
hgext/notify.py
tests/test-notify
tests/test-notify.out
--- a/hgext/notify.py	Mon Jan 19 12:36:06 2009 +0100
+++ b/hgext/notify.py	Thu Jan 15 01:38:52 2009 +0100
@@ -185,10 +185,16 @@
 
         # store sender and subject
         sender, subject = msg['From'], msg['Subject']
+        del msg['From'], msg['Subject']
+        # store remaining headers
+        headers = msg.items()
         # create fresh mime message from msg body
         text = msg.get_payload()
         # for notification prefer readability over data precision
         msg = mail.mimeencode(self.ui, text, self.charsets, self.test)
+        # reinstate custom headers
+        for k, v in headers:
+            msg[k] = v
 
         def fix_subject(subject):
             '''try to make subject line exist and be useful.'''
--- a/tests/test-notify	Mon Jan 19 12:36:06 2009 +0100
+++ b/tests/test-notify	Thu Jan 15 01:38:52 2009 +0100
@@ -52,7 +52,7 @@
 config = $HGTMP/.notify.conf
 domain = test.com
 strip = 3
-template = Subject: {desc|firstline|strip}\nFrom: {author}\n\nchangeset {node|short} in {webroot}\ndescription:\n\t{desc|tabindent|strip}
+template = Subject: {desc|firstline|strip}\nFrom: {author}\nX-Test: foo\n\nchangeset {node|short} in {webroot}\ndescription:\n\t{desc|tabindent|strip}
 
 [web]
 baseurl = http://test/
--- a/tests/test-notify.out	Mon Jan 19 12:36:06 2009 +0100
+++ b/tests/test-notify.out	Thu Jan 15 01:38:52 2009 +0100
@@ -108,6 +108,7 @@
 Content-Type: text/plain; charset="us-ascii"
 MIME-Version: 1.0
 Content-Transfer-Encoding: 7bit
+X-Test: foo
 Date:
 Subject: b
 From: test@test.com
@@ -138,6 +139,7 @@
 Content-Type: text/plain; charset="us-ascii"
 MIME-Version: 1.0
 Content-Transfer-Encoding: 7bit
+X-Test: foo
 Date:
 Subject: b
 From: test@test.com