Mercurial > p > roundup > code
comparison roundup/roundupdb.py @ 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 | 2c0f89edabe1 |
| children | 71c68961d9f4 |
comparison
equal
deleted
inserted
replaced
| 5969:247f176f9020 | 5970:11a9c5b2efd4 |
|---|---|
| 222 """ | 222 """ |
| 223 | 223 |
| 224 def nosymessage(self, issueid, msgid, oldvalues, whichnosy='nosy', | 224 def nosymessage(self, issueid, msgid, oldvalues, whichnosy='nosy', |
| 225 from_address=None, cc=[], bcc=[], cc_emails = [], | 225 from_address=None, cc=[], bcc=[], cc_emails = [], |
| 226 bcc_emails = [], subject=None, | 226 bcc_emails = [], subject=None, |
| 227 note_filter = None): | 227 note_filter = None, add_headers={}): |
| 228 """Send a message to the members of an issue's nosy list. | 228 """Send a message to the members of an issue's nosy list. |
| 229 | 229 |
| 230 The message is sent only to users on the nosy list who are not | 230 The message is sent only to users on the nosy list who are not |
| 231 already on the "recipients" list for the message. | 231 already on the "recipients" list for the message. |
| 232 | 232 |
| 268 | 268 |
| 269 If note_filter is specified it is a function with this | 269 If note_filter is specified it is a function with this |
| 270 prototype: | 270 prototype: |
| 271 note_filter(original_note, issueid, newvalues, oldvalues) | 271 note_filter(original_note, issueid, newvalues, oldvalues) |
| 272 If called, note_filter returns the new value for the message body. | 272 If called, note_filter returns the new value for the message body. |
| 273 | |
| 274 The add_headers parameter allows to set additional headers for | |
| 275 the outgoing email. | |
| 273 """ | 276 """ |
| 274 encrypt = self.db.config.PGP_ENABLE and self.db.config.PGP_ENCRYPT | 277 encrypt = self.db.config.PGP_ENABLE and self.db.config.PGP_ENCRYPT |
| 275 pgproles = self.db.config.PGP_ROLES | 278 pgproles = self.db.config.PGP_ROLES |
| 276 if msgid: | 279 if msgid: |
| 277 authid = self.db.msg.get(msgid, 'author') | 280 authid = self.db.msg.get(msgid, 'author') |
| 362 # update msgid and recipients only if non-bcc have changed | 365 # update msgid and recipients only if non-bcc have changed |
| 363 if msgid is not None: | 366 if msgid is not None: |
| 364 self.db.msg.set(msgid, recipients=recipients) | 367 self.db.msg.set(msgid, recipients=recipients) |
| 365 if sendto['plain'] or bcc_sendto['plain']: | 368 if sendto['plain'] or bcc_sendto['plain']: |
| 366 self.send_message(issueid, msgid, note, sendto['plain'], | 369 self.send_message(issueid, msgid, note, sendto['plain'], |
| 367 from_address, bcc_sendto['plain'], subject) | 370 from_address, bcc_sendto['plain'], |
| 371 subject, add_headers=add_headers) | |
| 368 if sendto['crypt'] or bcc_sendto['crypt']: | 372 if sendto['crypt'] or bcc_sendto['crypt']: |
| 369 self.send_message(issueid, msgid, note, sendto['crypt'], | 373 self.send_message(issueid, msgid, note, sendto['crypt'], |
| 370 from_address, bcc_sendto['crypt'], subject, crypt=True) | 374 from_address, bcc_sendto['crypt'], subject, crypt=True, |
| 375 add_headers=add_headers) | |
| 371 | 376 |
| 372 # backwards compatibility - don't remove | 377 # backwards compatibility - don't remove |
| 373 sendmessage = nosymessage | 378 sendmessage = nosymessage |
| 374 | 379 |
| 375 def encrypt_to(self, message, sendto): | 380 def encrypt_to(self, message, sendto): |
| 402 part.set_payload(cipher.read()) | 407 part.set_payload(cipher.read()) |
| 403 msg.attach(part) | 408 msg.attach(part) |
| 404 return msg | 409 return msg |
| 405 | 410 |
| 406 def send_message(self, issueid, msgid, note, sendto, from_address=None, | 411 def send_message(self, issueid, msgid, note, sendto, from_address=None, |
| 407 bcc_sendto=[], subject=None, crypt=False): | 412 bcc_sendto=[], subject=None, crypt=False, add_headers={}): |
| 408 '''Actually send the nominated message from this issue to the sendto | 413 '''Actually send the nominated message from this issue to the sendto |
| 409 recipients, with the note appended. | 414 recipients, with the note appended. It's possible to add |
| 415 headers to the message with the add_headers variable. | |
| 410 ''' | 416 ''' |
| 411 users = self.db.user | 417 users = self.db.user |
| 412 messages = self.db.msg | 418 messages = self.db.msg |
| 413 files = self.db.file | 419 files = self.db.file |
| 414 | 420 |
| 602 try: | 608 try: |
| 603 values.encode('ascii') | 609 values.encode('ascii') |
| 604 message[header] = values | 610 message[header] = values |
| 605 except UnicodeError: | 611 except UnicodeError: |
| 606 message[header] = Header(values, charset) | 612 message[header] = Header(values, charset) |
| 613 # Generate additional headers | |
| 614 for k in add_headers: | |
| 615 v = add_headers[k] | |
| 616 try: | |
| 617 v.encode('ascii') | |
| 618 message[k] = v | |
| 619 except UnicodeError: | |
| 620 message[k] = Header(v, charset) | |
| 607 | 621 |
| 608 if not inreplyto: | 622 if not inreplyto: |
| 609 # Default the reply to the first message | 623 # Default the reply to the first message |
| 610 msgs = self.get(issueid, 'messages') | 624 msgs = self.get(issueid, 'messages') |
| 611 # Assume messages are sorted by increasing message number here | 625 # Assume messages are sorted by increasing message number here |
