Don't create duplicate headers in outgoing email
authorMagnus Hagander <magnus@hagander.net>
Thu, 10 Sep 2020 14:45:38 +0000 (16:45 +0200)
committerMagnus Hagander <magnus@hagander.net>
Thu, 10 Sep 2020 14:45:38 +0000 (16:45 +0200)
The python libraries will *append* a header if it's just added again,
which would cause the news to go out with two date headers. Oops. So
instead check if each header is present and in that case replace it
rather than appending.

pgweb/mailqueue/util.py

index 6828cabbc73f5bd947946c09167125558f6126ec..4346d7d06b06f525716d7305f378f1ec9e07b500 100644 (file)
@@ -51,8 +51,12 @@ def send_simple_mail(sender, receiver, subject, msgtxt, attachments=None, userge
     elif not usergenerated:
         msg['Auto-Submitted'] = 'auto-generated'
 
-    for h in headers.keys():
-        msg[h] = headers[h]
+    for h, v in headers.items():
+        if h in msg:
+            # Replace the existing header -- the one specified is supposedly overriding it
+            msg.replace_header(h, v)
+        else:
+            msg.add_header(h, v)
 
     if htmlbody:
         mpart = MIMEMultipart("alternative")