Roundup Tracker - Issues

Issue 2551018

Title: Allow changes to the email body of nosy emails.
Type: behavior Severity: normal
Components: Mail interface Versions: devel
Status: fixed Resolution: fixed
Dependencies: Superseder:
Assigned To: rouilj Nosy List: ThomasAH, rouilj, tekberg
Priority: normal Keywords: patch

Created on 2019-01-08 19:50 by tekberg, last changed 2019-03-25 23:47 by rouilj.

File name Uploaded Description Edit Remove
hg-diff.txt tekberg, 2019-01-30 17:47 hg diff for this change
mail.txt tekberg, 2019-01-30 17:49 Actual email that was sent. tekberg, 2019-01-30 17:53 detector/ code that uses this feature tekberg, 2019-03-25 19:45 Patch to test note_filter argument for nosymessage.
msg6313 Author: [hidden] (tekberg) Date: 2019-01-08 19:50
I have been working on an oncall tracker where is it useful for the
nosy email to show specific fields (problem description, page
date/time, call-back phone, etc.) even when they don't change. This
issue describes a modification to the roundup code that allows nosy
wmail to generate a custom body.

The modification involves passing a function as an optional parameter,
calling the function, if non-None, after the email body gets
built. The email body becomes whatever the function returns. The
function can return the original body or replace it with something

The change is to the nosymessage function in roundup/ The
new note_filter parameter to nosymessage defaults to None. If
note_filter is specified it is assumed to be a function with this

            note_filter(original_note, issueid, newvalues, oldvalues)

If called, the note_filter function returns the new value for the
message body.

Example use:

Make a custom change to detectors/ In the nosyreaction
function change this line:

            cl.nosymessage(nodeid, msgid, oldvalues)

to something like this:

            cl.nosymessage(nodeid, msgid, oldvalues, 

Where format_oncall_message is a new function like this:

def format_oncall_message(original_note, issue_id, newvalues, 
    Format the message like the lmit_oncall tracker did with nice 
field names.

    Determine if the description changed or if there are new 
    and return detail that should go into the body of the email 

    email_details = []
    new_description = newvalues.get(issue_id, 'description')
    # If this is a new issue and it has a description, or if the issue
    # was edited and the description changed.
    have_new_description = ((oldvalues is None and new_description) or
                            (oldvalues is not None and
                             'description' in oldvalues and
                             (oldvalues.get('description') != 
    new_messages = determineNewMessages(newvalues, issue_id, 

    # Have new detail. Add the common detail first.
    if have_new_description or new_messages:
        if newvalues.get(issue_id, 'pagedate'):
            email_details.append('Page Date: %s' % 
(newvalues.get(issue_id, 'pagedate').pretty(format='%Y-%m-%d'),))
        if newvalues.get(issue_id, 'pagetime'):
            email_details.append('Page Time: %s' % 
(newvalues.get(issue_id, 'pagetime'),))
        email_details.append('Name: %s' % (newvalues.get(issue_id, 
        source_id = newvalues.get(issue_id, 'source')
        if source_id:
            email_details.append('Source: %s' % 
(db.source.get(source_id, 'name'),))
        location_id = newvalues.get(issue_id, 'location')
        if location_id:
            email_details.append('Location: %s' % 
(db.location.get(location_id, 'name'),))
    if have_new_description:
        email_details.append('Problem Description: %s' % 

    # Add messages (Update/Resolution) if there are any.
    messages = newvalues.db.msg
    for msgid in new_messages:
        content = messages.get(msgid, 'content', '')
        if content:
            email_details.append('Update/Resolution: %s' % (content,))

    return '\n\n'.join(email_details)

This example of real code stores the lines of the email in
the email_details list. It checks carefully to see if there is a new
description, then adds the contents of several fields, and appends the
nosy meessages. The return joins the lines together to return a
string. [The final version of this code will include additional

An example email is attached. Note that the code and the email differ
now, but will match when I finish with this tracker. I redacted where
the email was sent and the person that responded to the email.
msg6314 Author: [hidden] (tekberg) Date: 2019-01-08 19:52
Here is the sample email.
msg6315 Author: [hidden] (ThomasAH) Date: 2019-01-09 07:39

+1 for including this in Roundup
msg6322 Author: [hidden] (tekberg) Date: 2019-01-30 17:47
Needed to add another parameter to the function. Updating the hg diff, 
sample email (real email this time) and added the example use.
msg6421 Author: [hidden] (rouilj) Date: 2019-03-24 01:23
Tom can you work on adding a patch to test/ to add a new
test of this functionality. I think you can use the existing code
for say testNosyMessageCcBccEtc as a template for your test.
msg6432 Author: [hidden] (tekberg) Date: 2019-03-25 19:45
Here is a test case, as a patch for test/ Thank you John
for your suggestion of what to use as a template.
msg6435 Author: [hidden] (rouilj) Date: 2019-03-25 23:47
Checked in hg:f3d68c1bb96e Closing.
Date User Action Args
2019-03-25 23:47:26rouiljsetstatus: new -> fixed
versions: + devel
messages: + msg6435
priority: normal
assignee: rouilj
components: + Mail interface, - Infrastructure
resolution: fixed
2019-03-25 19:45:25tekbergsetfiles: +
messages: + msg6432
2019-03-24 01:23:03rouiljsetmessages: + msg6421
2019-01-30 17:53:57tekbergsetfiles: +
2019-01-30 17:49:52tekbergsetfiles: + mail.txt
2019-01-30 17:47:26tekbergsetfiles: + hg-diff.txt
messages: + msg6322
2019-01-30 17:43:50tekbergsetfiles: - note-filter-example-email.txt
2019-01-30 17:43:43tekbergsetfiles: - note-filter.diff
2019-01-09 07:39:32ThomasAHsetnosy: + ThomasAH
messages: + msg6315
2019-01-08 19:52:18tekbergsetfiles: + note-filter-example-email.txt
messages: + msg6314
2019-01-08 19:50:22tekbergcreate