| 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 | |
| 6 | The ''IEmailAddressResolver'' is a fallback mechanism for determining which email address should be used to send [TracNotification notifications]. |
| 7 | |
| 8 | == Purpose == |
| 9 | |
| 10 | Trac 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 | |
| 12 | Now 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 | |
| 14 | OPEN Is this even needed? The email distributor could just contain this logic. Maybe for directory services? |
| 15 | |
| 16 | == Usage == |
| 17 | |
| 18 | Implementing the interface follows the standard guidelines found in [wiki:TracDev/ComponentArchitecture] and of course [wiki:TracDev/PluginDevelopment]. |
| 19 | |
| 20 | The `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 | |
| 26 | The following naively uses LDAP to retrieve the email address. |
| 27 | |
| 28 | {{{#!python |
| 29 | import ldap |
| 30 | |
| 31 | from trac.core import * |
| 32 | from trac.notification.api import IEmailAddressResolver |
| 33 | |
| 34 | class 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 | |
| 54 | Only `trac.ticket.notification.mail.DefaultDomainEmailResolver` and `trac.ticket.notification.mail.SessionEmailResolver` are part of core Trac. |
| 55 | |
| 56 | OPEN Are they even needed? The email distributor could just contain this logic. |
| 57 | |
| 58 | Various 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? |