Edgewall Software

Changes between Initial Version and Version 1 of TracDev/Proposals/AdvancedNotification/IEmailAddressResolver


Ignore:
Timestamp:
Nov 18, 2012, 12:21:15 AM (12 years ago)
Author:
Peter Suter
Comment:

Document the proposed IEmailAddressResolver extension point.

Legend:

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

    v1 v1  
     1== Extension Point : ''IEmailAddressResolver'' ==
     2
     3||'''Interface'''||''IEmailAddressResolver''||'''Since'''||[wiki:TracDev/ApiChanges/1.1.1#IEmailAddressResolver 1.1.1]||
     4||'''Module'''||''trac.notification''||'''Source'''||[source:trunk/trac/notification/api.py#/IEmailAddressResolver api.py]||
     5
     6The ''IEmailAddressResolver'' is a fallback mechanism for determining which email address should be used to send [TracNotification notifications].
     7
     8== Purpose ==
     9
     10Trac provides an extendible and flexible notification system, that historically has sent emails to the email address specified in the user preferences or in the CC, reporter or author fields.
     11
     12Now plugins can add additional ways to find an email address for a Trac session that has no email address specified in the user preferences.
     13
     14OPEN Is this even needed? The email distributor could just contain this logic. Maybe for directory services?
     15
     16== Usage ==
     17
     18Implementing the interface follows the standard guidelines found in [wiki:TracDev/ComponentArchitecture] and of course [wiki:TracDev/PluginDevelopment].
     19
     20The `get_address_for_session()` method returns the email address for the given session or `None`. The parameters are:
     21* `sid`: The Trac session ID.
     22* `authenticated`: 1 if the Trac session ID is authenticated, 0 otherwise.
     23
     24== Examples ==
     25
     26The following naively uses LDAP to retrieve the email address.
     27
     28{{{#!python
     29import ldap
     30
     31from trac.core import *
     32from trac.notification.api import IEmailAddressResolver
     33
     34class LdapEmailAddressResolver(Component):
     35
     36    implements(IEmailAddressResolver)
     37
     38    # IEmailAddressResolver methods
     39   
     40    def get_address_for_name(name, authenticated):
     41        ld = ldap.initialize('ldap://localhost:1390')
     42        ld.simple_bind_s()
     43        for dn, entry in ld.search_s('ou=people,dc=example,dc=com',
     44                                     ldap.SCOPE_SUBTREE,
     45                                     '(cn={0}) % user,
     46                                     ['mail']):
     47            if 'mail' in entry:
     48                return entry['mail']
     49        ld.unbind_s()
     50}}}
     51
     52== Available Implementations ==
     53
     54Only `trac.ticket.notification.mail.DefaultDomainEmailResolver` and `trac.ticket.notification.mail.SessionEmailResolver`  are part of core Trac.
     55
     56OPEN Are they even needed? The email distributor could just contain this logic.
     57
     58Various other resolvers might be part of th:AnnouncerPlugin.
     59
     60== Additional Information and References ==
     61
     62 * [http://www.edgewall.org/docs/trac-trunk/epydoc/trac.notification.api.IEmailAddressResolver-class.html epydoc]
     63 * [http://www.edgewall.org/docs/trac-trunk/html/api/trac_notification.html#trac.notification.api.IEmailAddressResolver API Reference]
     64 * This interface originated in th:AnnouncerPlugin as `IAnnouncementAddressResolver`.
     65   * DONE Renamed `get_address_for_name()` to `get_address_for_session()`.
     66   * DONE Other distributors can not use the same interface (according to comment in th:AnnouncerPlugin's `XmppDistributor`) so this is email specific.
     67   * TODO: Make it usable by multiple distributors?