Edgewall Software

Opened 11 years ago

Closed 6 months ago

Last modified 5 months ago

#6613 closed enhancement (fixed)

TracNotification for new tickets only

Reported by: me@… Owned by: Ryan J Ollos
Priority: normal Milestone: 1.2.3
Component: notification Version: 0.10.3
Severity: normal Keywords:
Release Notes:

Added a notification subscriber for new tickets.

API Changes:


For a project I'm working on (Warzone 2100), I'm currently setting up a Trac environment here (with an incomplete SSL certificate as of yet).

In this project we want to be sent notices on the mailinglist when new tickets are created. So I set up TracNotification to send some mails to the mailing list. The problem is though that we only want these notices on ticket creation, not when they're updated or modified. Unfortunately TracNotification didn't do this natively, so I had to extend the TicketNotifyEmail class somewhat.

The attached patch contains this extension/modification and adds a new configuration option to the [notification] section in trac.ini.

  • cc_on_newticket: Email address(es) to send notifications about newly created tickets to, addresses can only be seen when use_public_cc is enabled (Cc:).

NOTE: This patch should work with trunk as well, it's just that I wrote it for my 0.10.3 Trac installation.


Attachments (1)

trac-notification-cc_on_newticket.patch (1.1 KB ) - added by me@… 11 years ago.
adds a TracNotification option for CC on new tickets

Download all attachments as: .zip

Change History (13)

Changed 11 years ago by me@…

adds a TracNotification option for CC on new tickets

comment:1 Changed 11 years ago by Emmanuel Blot

Milestone: 0.10.5

New features won't be integrated to the maintenance branch 0.10

The TracNotification subsystem will be rewritten for 0.12.

comment:2 Changed 11 years ago by anonymous

For the rewrite of TracNotification I assume you mean trac.ticket.api.ITicketChangeListener as mentioned in PluginDevelopment ?

Something like that seems to be in progress @ track-hacks: AnnouncerPlugin.

Also initially I used a patch like this (which would add these mail addresses to the public Cc: list always, indepent from the user_public_cc setting. I personally think this option (i.e. independence of user_public_cc) is better, though this patch feels more like a hack to me (as it changes the interface/function prototypes):

  • notification.py

    old new  
    5555        """Email address(es) to always send notifications to,
    5656           addresses can be see by all recipients (Cc:).""")
     58    smtp_cc_on_newticket = Option('notification', 'smtp_cc_on_newticket', '',
     59        """Email address(es) to send notifications about newly
     60           created tickets to, addresses can be seen by all
     61           recipients (Cc:).""")
    5863    smtp_always_bcc = Option('notification', 'smtp_always_bcc', '',
    5964        """Email address(es) to always send notifications to,
    6065           addresses do not appear publicly (Bcc:). (''since 0.10'').""")
    155160    longaddr_re = re.compile(r"^\s*(.*)\s+<(" + addrfmt + ")>\s*$");
    156161    nodomaddr_re = re.compile(r"[\w\d_\.\-]+")
    157162    addrsep_re = re.compile(r"[;\s,]+")
     163    newticket = None
    159165    def __init__(self, env):
    160166        Notify.__init__(self, env)
    192198        else:
    193199            raise TracError, 'Invalid email encoding setting: %s' % pref
    195     def notify(self, resid, subject):
     201    def notify(self, resid, subject, newticket=False):
    196202        self.subject = subject
     203        self.newticket = newticket
    198205        if not self.config.getbool('notification', 'smtp_enabled'):
    199206            return
    325332        bccaddrs = bccparam and \
    326333                   build_addresses(bccparam.replace(',', ' ').split()) or []
     335        if self.newticket:
     336            naccparam = self.config.get('notification', 'smtp_cc_on_newticket')
     337            accaddrs += naccparam and \
     338                        build_addresses(naccparam.replace(',', ' ').split()) or []
    328340        recipients = []
    329341        (toaddrs, recipients) = remove_dup(toaddrs, recipients)
    330342        (ccaddrs, recipients) = remove_dup(ccaddrs, recipients)
  • ticket/notification.py

    old new  
    126126                self.hdf.set_unescaped('email.changes_body', changes)
    127127        self.ticket['link'] = link
    128128        self.hdf.set_unescaped('ticket', self.ticket.values)
    129         NotifyEmail.notify(self, ticket.id, subject)
     129        NotifyEmail.notify(self, ticket.id, subject, self.newticket)
    131131    def format_props(self):
    132132        tkt = self.ticket

comment:3 Changed 11 years ago by Christian Boos

Milestone: 0.12

See also Stephen Hansen's mail on trac-dev, Notification Architecture.

Setting the milestone tentatively to 0.12, as I think the new notification architecture should be able to allow for such requests, though not necessarily through the way proposed in the patch, rather using some more general ways, like in Stephen's proposal.

comment:4 Changed 4 years ago by AH

Might still be useful 7 years later with many Trac releases in between. Has it made its way into the product?

comment:5 Changed 4 years ago by Ryan J Ollos

Owner: Emmanuel Blot deleted

comment:6 Changed 21 months ago by Peter Suter

Could now be implemented as a plugin (or optional component)? Untested:

from trac.core import Component, implements
from trac.notification.api import INotificationSubscriber
from trac.notification.model import Subscription

class NewTicketSubscriber(Component):
    """Subscribe to new created tickets."""


    # INotificationSubscriber methods

    def matches(self, event):
        if event.realm != 'ticket':
        if event.category != 'created':

        klass = self.__class__.__name__
        for s in Subscription.find_by_class(self.env, klass):
            yield s.subscription_tuple()

    def description(self):
        return _("Any ticket is created")

    def default_subscriptions(self):
        return []

    def requires_authentication(self):
        return False

comment:7 Changed 21 months ago by Peter Suter

comment:8 Changed 21 months ago by Ryan J Ollos

NewTicketSubscriber works well and I agree we should add to tracopt.

comment:9 Changed 21 months ago by Ryan J Ollos

Or maybe just add to trac.ticket.notification. I don't see any downsides to enabling NewTicketSubscriber in a default installation.

comment:10 Changed 6 months ago by Ryan J Ollos

Milestone: next-major-releases1.2.3
Owner: set to Ryan J Ollos
Release Notes: modified (diff)
Status: newassigned

Proposed changes in [99a7c844f/rjollos.git].

comment:11 Changed 6 months ago by Ryan J Ollos

Resolution: fixed
Status: assignedclosed

Committed to 1.2-stable in r16630, merged to trunk in r16631.

comment:12 Changed 5 months ago by Ryan J Ollos

Release Notes: modified (diff)

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain Ryan J Ollos.
The resolution will be deleted.
to The owner will be changed from Ryan J Ollos to the specified user.

Add Comment

E-mail address and name can be saved in the Preferences .
Note: See TracTickets for help on using tickets.