| 42 | === !ReplyToTicketDecorator |
| 43 | |
| 44 | Another 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 |
| 46 | from trac.core import Component, implements |
| 47 | from trac.config import Option |
| 48 | from trac.notification.api import IEmailDecorator |
| 49 | from trac.notification.mail import set_header |
| 50 | |
| 51 | class 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 | |