Edgewall Software

Changes between Version 3 and Version 4 of TracDev/Proposals/AdvancedNotification/IEmailDecorator


Ignore:
Timestamp:
Oct 19, 2013, 9:17:59 AM (11 years ago)
Author:
Peter Suter
Comment:

Added ReplyToTicketDecorator example

Legend:

Unmodified
Added
Removed
Modified
  • TracDev/Proposals/AdvancedNotification/IEmailDecorator

    v3 v4  
    4040}}}
    4141
     42=== !ReplyToTicketDecorator
     43
     44Another example (adapted from [th:comment:4:ticket:10044 a feature request]) changes the reply-to address depending on the ticket id (so recipients can just reply to the emails and e.g. th:EmailtoTracScript can forward such replies to `10044@trac-hacks.org` to [th:ticket:10044 the appropriate ticket]):
     45{{{#!python
     46from trac.core import Component, implements
     47from trac.config import Option
     48from trac.notification.api import IEmailDecorator
     49from trac.notification.mail import set_header
     50
     51class ReplyToTicketDecorator(Component):
     52    """Replaces the 'Reply-To' header for tickets with a dynamic email address.
     53
     54    Uses a new config option 'ticket_email_from'.
     55    """
     56    implements(IEmailDecorator)
     57
     58    ticket_email_replyto = Option('notification', 'ticket_email_replyto', '__id__@localhost',
     59                """Reply-To address for ticket notification emails.
     60
     61                   ` __id__` is replaced with the ticket id.""")
     62
     63    def decorate_message(self, event, message, charset):
     64        if event.realm == 'ticket':
     65            replyto = self.ticket_email_replyto.replace('__id__', str(event.target.id))
     66            set_header(message, 'Reply-To', replyto, charset)
     67}}}
     68
    4269== Available Implementations ==
    4370