Edgewall Software

Version 1 (modified by Peter Suter, 11 years ago) ( diff )

Document the proposed IEmailDecorator extension point.

Extension Point : IEmailDecorator

InterfaceIEmailDecoratorSince1.1.1
Moduletrac.notificationSourceapi.py

An IEmailDecorator decorates notification email, usually by adding additional email headers.

Purpose

Trac provides an extendible and flexible notification system, that historically has sent emails formatted by some fixed logic.

Now plugins can implement different transports and formatters, decoupling the formatting logic from the transport implementation. IEmailDecorator allows also decoupling e.g. email title formatting and other header manipulation both from transport-neutral formatting logic and the email transport implementation.

Usage

Implementing the interface follows the standard guidelines found in TracDev/ComponentArchitecture and of course TracDev/PluginDevelopment.

The decorate_message() decorates the email message as appropriate. The parameters are:

  • event: A trac.notification.api.NotificationEvent instance describing the event about which the recipients should be notified.
  • message: An instance of email.mime.base.MIMEBase to decorate.

Examples

The following example adds a custom X-Trac-Notification-Author header to emails:

from trac.core import *
from trac.notification.api import IEmailDecorator
from trac.notification.mail import set_header

class AuthorEmailDecorator(Component):

    implements(IEmailDecorator)

    # IEmailDecorator methods
    
    def decorate_message(self, event, message):
        set_header(message, 'X-Trac-Notification-Author', event.author)

Available Implementations

The following implementations are part of core Trac:

  • trac.ticket.notification.mail.ThreadingEmailDecorator: Implements threading (In-Reply-To headers etc.)
  • trac.ticket.notification.mail.StaticEmailDecorator: Implements email_always_cc and email_always_bcc configuration options.
  • trac.ticket.notification.mail.NotificationEmailDecorator: Implements miscellaneous headers.
    • Is this one even needed? The email distributor could just contain this logic.

Various other resolvers might be part of th:AnnouncerPlugin.

Additional Information and References

Note: See TracWiki for help on using the wiki.