changeset 5970:11a9c5b2efd4

Additional headers for nosymessage Nice if a message needs to be marked as urgent or similar, e.g., Outlook uses an "Importance" header, when set to "high" it highlights the message.
author Ralf Schlatterbeck <rsc@runtux.com>
date Tue, 05 Nov 2019 13:22:20 +0100
parents 247f176f9020
children e5acd1843517
files CHANGES.txt roundup/roundupdb.py
diffstat 2 files changed, 24 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGES.txt	Sun Nov 03 14:43:29 2019 -0500
+++ b/CHANGES.txt	Tue Nov 05 13:22:20 2019 +0100
@@ -16,6 +16,11 @@
 
 Features:
 
+- Allow to pass additional headers to nosymessage, nice if a message
+  needs to be marked as urgent or similar, e.g., Outlook uses an
+  "Importance" header, when set to "high" it highlights the message.
+  (Ralf Schlatterbeck)
+
 Fixed:
 
 - issue2550996 - Give better error message when running with -c
--- a/roundup/roundupdb.py	Sun Nov 03 14:43:29 2019 -0500
+++ b/roundup/roundupdb.py	Tue Nov 05 13:22:20 2019 +0100
@@ -224,7 +224,7 @@
     def nosymessage(self, issueid, msgid, oldvalues, whichnosy='nosy',
             from_address=None, cc=[], bcc=[], cc_emails = [],
             bcc_emails = [], subject=None,
-            note_filter = None):
+            note_filter = None, add_headers={}):
         """Send a message to the members of an issue's nosy list.
 
         The message is sent only to users on the nosy list who are not
@@ -270,6 +270,9 @@
         prototype:
             note_filter(original_note, issueid, newvalues, oldvalues)
         If called, note_filter returns the new value for the message body.
+
+        The add_headers parameter allows to set additional headers for
+        the outgoing email.
         """
         encrypt = self.db.config.PGP_ENABLE and self.db.config.PGP_ENCRYPT
         pgproles = self.db.config.PGP_ROLES
@@ -364,10 +367,12 @@
                 self.db.msg.set(msgid, recipients=recipients)
         if sendto['plain'] or bcc_sendto['plain']:
             self.send_message(issueid, msgid, note, sendto['plain'],
-                              from_address, bcc_sendto['plain'], subject)
+                              from_address, bcc_sendto['plain'],
+                              subject, add_headers=add_headers)
         if sendto['crypt'] or bcc_sendto['crypt']:
             self.send_message(issueid, msgid, note, sendto['crypt'],
-                from_address, bcc_sendto['crypt'], subject, crypt=True)
+                from_address, bcc_sendto['crypt'], subject, crypt=True,
+                add_headers=add_headers)
 
     # backwards compatibility - don't remove
     sendmessage = nosymessage
@@ -404,9 +409,10 @@
         return msg
 
     def send_message(self, issueid, msgid, note, sendto, from_address=None,
-            bcc_sendto=[], subject=None, crypt=False):
+            bcc_sendto=[], subject=None, crypt=False, add_headers={}):
         '''Actually send the nominated message from this issue to the sendto
-           recipients, with the note appended.
+           recipients, with the note appended. It's possible to add
+           headers to the message with the add_headers variable.
         '''
         users = self.db.user
         messages = self.db.msg
@@ -604,6 +610,14 @@
                 message[header] = values
             except UnicodeError:
                 message[header] = Header(values, charset)
+            # Generate additional headers
+            for k in add_headers:
+                v = add_headers[k]
+                try:
+                    v.encode('ascii')
+                    message[k] = v
+                except UnicodeError:
+                    message[k] = Header(v, charset)
 
             if not inreplyto:
                 # Default the reply to the first message

Roundup Issue Tracker: http://roundup-tracker.org/