Skip to content

Commit 73ae5a5

Browse files
committed
issue2551018 add new nosy_filter parameter to nosymessage. Function
passed as nosy_filter can rewrite the nosy message body before it's sent. Tom Ekberg tekberg did the work.
1 parent 14f6d2c commit 73ae5a5

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed

CHANGES.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ Features:
7373
action to return the same data as the old export_csv action. (Tom
7474
Ekberg (tekberg), Andreas (anrounham14) edited/applied and tests
7575
created by John Rouillard)
76+
- issue2551018: Add new note_filter parameter to nosymessage. The
77+
function supplied by this parameter can rewrite the body of the
78+
nosymessage before it gets sent. See issue:
79+
https://issues.roundup-tracker.org/issue2551018 for example
80+
nosyreaction and generated email. (Tom Ekberg (tekberg))
7681

7782
Fixed:
7883

roundup/roundupdb.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ def addmessage(self, issueid, summary, text):
223223

224224
def nosymessage(self, issueid, msgid, oldvalues, whichnosy='nosy',
225225
from_address=None, cc=[], bcc=[], cc_emails = [],
226-
bcc_emails = [], subject=None ):
226+
bcc_emails = [], subject=None,
227+
note_filter = None):
227228
"""Send a message to the members of an issue's nosy list.
228229
229230
The message is sent only to users on the nosy list who are not
@@ -264,6 +265,11 @@ def nosymessage(self, issueid, msgid, oldvalues, whichnosy='nosy',
264265
defined, we try to send encrypted mail to *all* users
265266
*including* cc, bcc, cc_emails and bcc_emails and this might
266267
fail if not all the keys are available in roundups keyring.
268+
269+
If note_filter is specified it is a function with this
270+
prototype:
271+
note_filter(original_note, issueid, newvalues, oldvalues)
272+
If called, note_filter returns the new value for the message body.
267273
"""
268274
encrypt = self.db.config.PGP_ENABLE and self.db.config.PGP_ENCRYPT
269275
pgproles = self.db.config.PGP_ROLES
@@ -345,6 +351,10 @@ def good_recipient(userid):
345351
note = self.generateChangeNote(issueid, oldvalues)
346352
else:
347353
note = self.generateCreateNote(issueid)
354+
if note_filter:
355+
cn = self.classname
356+
cl = self.db.classes[cn]
357+
note = note_filter(note, issueid, self.db, cl, oldvalues)
348358

349359
# If we have new recipients, update the message's recipients
350360
# and send the mail.

test/test_mailgw.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1852,6 +1852,61 @@ def testNosyMessageCcBccEtc(self):
18521852
----------
18531853
assignedto: -> Chef
18541854
1855+
_______________________________________________________________________
1856+
Roundup issue tracker <[email protected]>
1857+
<http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1>
1858+
_______________________________________________________________________
1859+
""")
1860+
1861+
1862+
def testNosyMessageNoteFilter(self):
1863+
def note_filter(original_note, issue_id, db, newvalues, oldvalues):
1864+
return 'This content came from note_filter().'
1865+
self.doNewIssue()
1866+
oldvalues = self.db.getnode('issue', '1').copy()
1867+
oldvalues['assignedto'] = None
1868+
# reconstruct old behaviour: This would reuse the
1869+
# database-handle from the doNewIssue above which has committed
1870+
# as user "Chef". So we close and reopen the db as that user.
1871+
#self.db.close() actually don't close 'cos this empties memorydb
1872+
self.db = self.instance.open('Chef')
1873+
self.db.issue.set('1', assignedto=self.chef_id)
1874+
self.db.commit()
1875+
self.db.issue.nosymessage('1', None, oldvalues,
1876+
cc=['3','4', '5'],
1877+
cc_emails=['[email protected]'],
1878+
note_filter=note_filter)
1879+
new_mail = ""
1880+
# Message-Id: and Date: change every time - remove them.
1881+
for line in self._get_mail().split("\n"):
1882+
if "Message-Id: " in line:
1883+
continue
1884+
if "Date: " in line:
1885+
continue
1886+
new_mail += line+"\n"
1887+
1888+
self.compareMessages(new_mail, """
1889+
1890+
1891+
Content-Type: text/plain; charset="utf-8"
1892+
Subject: [issue1] Testing...
1893+
1894+
From: "Bork, Chef" <[email protected]>
1895+
X-Roundup-Name: Roundup issue tracker
1896+
X-Roundup-Loop: hello
1897+
X-Roundup-Issue-Status: unread
1898+
X-Roundup-Version: 1.3.3
1899+
In-Reply-To: <dummy_test_message_id>
1900+
MIME-Version: 1.0
1901+
Reply-To: Roundup issue tracker
1902+
1903+
Content-Transfer-Encoding: quoted-printable
1904+
1905+
1906+
Change by Bork, Chef <[email protected]>:
1907+
1908+
This content came from note_filter().
1909+
18551910
_______________________________________________________________________
18561911
Roundup issue tracker <[email protected]>
18571912
<http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1>

0 commit comments

Comments
 (0)