diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/mailman/mta/docs/personalized.txt | 137 | ||||
| -rw-r--r-- | src/mailman/mta/docs/verp.txt | 9 | ||||
| -rw-r--r-- | src/mailman/mta/personalized.py | 59 | ||||
| -rw-r--r-- | src/mailman/mta/verp.py | 9 |
4 files changed, 206 insertions, 8 deletions
diff --git a/src/mailman/mta/docs/personalized.txt b/src/mailman/mta/docs/personalized.txt new file mode 100644 index 000000000..c1c590479 --- /dev/null +++ b/src/mailman/mta/docs/personalized.txt @@ -0,0 +1,137 @@ +=========================== +Fully personalized delivery +=========================== + +Fully personalized mail delivery is an enhancement over VERP_ delivery where +the To field of the message is replaced with the recipient's address. A +typical email message is sent to the mailing list's posting address and copied +to the list membership that way. Some people like the more personal address. + +.. _VERP: verp.txt + +Personalized delivery still does VERP. + + >>> from mailman.mta.personalized import PersonalizedDelivery + >>> personalized = PersonalizedDelivery() + +Delivery strategies must implement the proper interface. + + >>> from mailman.interfaces.mta import IMailTransportAgentDelivery + >>> from zope.interface.verify import verifyObject + >>> verifyObject(IMailTransportAgentDelivery, personalized) + True + + +To header +========= + +The To header is replaced with the recipient's address and name. + + >>> mlist = create_list('test@example.com') + >>> msg = message_from_string("""\ + ... From: aperson@example.org + ... To: test@example.com + ... Subject: test one + ... Message-ID: <aardvark> + ... + ... This is a test. + ... """) + + >>> recipients = set([ + ... 'aperson@example.com', + ... 'bperson@example.com', + ... 'cperson@example.com', + ... ]) + + >>> personalized.deliver(mlist, msg, dict(recipients=recipients)) + {} + >>> messages = list(smtpd.messages) + >>> len(messages) + 3 + + >>> from operator import itemgetter + >>> for message in sorted(messages, key=itemgetter('to')): + ... print message.as_string() + ... print '----------' + From: aperson@example.org + To: aperson@example.com + Subject: test one + Message-ID: <aardvark> + X-Peer: ... + X-MailFrom: test-bounces+aperson=example.com@example.com + X-RcptTo: aperson@example.com + <BLANKLINE> + This is a test. + ---------- + From: aperson@example.org + To: bperson@example.com + Subject: test one + Message-ID: <aardvark> + X-Peer: ... + X-MailFrom: test-bounces+bperson=example.com@example.com + X-RcptTo: bperson@example.com + <BLANKLINE> + This is a test. + ---------- + From: aperson@example.org + To: cperson@example.com + Subject: test one + Message-ID: <aardvark> + X-Peer: ... + X-MailFrom: test-bounces+cperson=example.com@example.com + X-RcptTo: cperson@example.com + <BLANKLINE> + This is a test. + ---------- + +If the recipient is a user registered with Mailman, and the user has an +associated real name, then this name also shows up in the To header. + + >>> from zope.component import getUtility + >>> from mailman.interfaces.usermanager import IUserManager + >>> user_manager = getUtility(IUserManager) + + >>> bill = user_manager.create_user('bperson@example.com', 'Bill Person') + >>> cate = user_manager.create_user('cperson@example.com', 'Cate Person') + >>> transaction.commit() + + >>> personalized.deliver(mlist, msg, dict(recipients=recipients)) + {} + >>> messages = list(smtpd.messages) + >>> len(messages) + 3 + + >>> from operator import itemgetter + >>> for message in sorted(messages, key=itemgetter('x-rcptto')): + ... print message.as_string() + ... print '----------' + From: aperson@example.org + To: aperson@example.com + Subject: test one + Message-ID: <aardvark> + X-Peer: ... + X-MailFrom: test-bounces+aperson=example.com@example.com + X-RcptTo: aperson@example.com + <BLANKLINE> + This is a test. + ---------- + From: aperson@example.org + To: Bill Person <bperson@example.com> + Subject: test one + Message-ID: <aardvark> + X-Peer: ... + X-MailFrom: test-bounces+bperson=example.com@example.com + X-RcptTo: bperson@example.com + <BLANKLINE> + This is a test. + ---------- + From: aperson@example.org + To: Cate Person <cperson@example.com> + Subject: test one + Message-ID: <aardvark> + X-Peer: ... + X-MailFrom: test-bounces+cperson=example.com@example.com + X-RcptTo: cperson@example.com + <BLANKLINE> + This is a test. + ---------- diff --git a/src/mailman/mta/docs/verp.txt b/src/mailman/mta/docs/verp.txt index ac8d70e29..11157d363 100644 --- a/src/mailman/mta/docs/verp.txt +++ b/src/mailman/mta/docs/verp.txt @@ -2,13 +2,11 @@ Standard VERP delivery ====================== -'VERP' delivery is an alternative to bulk_ delivery, where an individual -message is crafted uniquely for each recipient. Our use of the term `VERP`_ -is actually incorrect, since the term is narrowly defined by the technique of -setting the return path so that bounces can be unambiguously decoded. +Variable Envelope Return Path (VERP_) delivery is an alternative to bulk_ +delivery, where an individual message is crafted uniquely for each recipient. -.. _bulk: bulk.txt .. _VERP: http://en.wikipedia.org/wiki/Variable_envelope_return_path +.. _bulk: bulk.txt The cost of enabling VERP is that Mailman must send to the upstream MTA, one message per recipient. Under bulk delivery, an exact copy of one message can @@ -78,6 +76,7 @@ intended recipient's delivery address. ... ]) >>> verp.deliver(mlist, msg, dict(recipients=recipients)) + {} >>> messages = list(smtpd.messages) >>> len(messages) 3 diff --git a/src/mailman/mta/personalized.py b/src/mailman/mta/personalized.py new file mode 100644 index 000000000..99d939096 --- /dev/null +++ b/src/mailman/mta/personalized.py @@ -0,0 +1,59 @@ +# Copyright (C) 2009 by the Free Software Foundation, Inc. +# +# This file is part of GNU Mailman. +# +# GNU Mailman is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Mailman. If not, see <http://www.gnu.org/licenses/>. + +"""Personalized delivery.""" + +from __future__ import absolute_import, unicode_literals + +__metaclass__ = type +__all__ = [ + 'PersonalizedDelivery', + ] + + +from email.header import Header +from email.utils import formataddr +from zope.component import getUtility + +from mailman.interfaces.usermanager import IUserManager +from mailman.mta.verp import VERPDelivery + + + +class PersonalizedDelivery(VERPDelivery): + """Personalize the message's To header.""" + + def _deliver_to_recipients(self, mlist, msg, msgdata, + sender, recipients): + """See `BaseDelivery`.""" + # This module only works with VERP delivery. + assert len(recipients) == 1, 'Single recipient is required' + # Try to find the real name for the recipient email address, if the + # address is associated with a user registered with Mailman. + recipient = recipients[0] + user_manager = getUtility(IUserManager) + user = user_manager.get_user(recipient) + if user is None: + msg.replace_header('To', recipient) + else: + # Convert the unicode name to an email-safe representation. + # Create a Header instance for the name so that it's properly + # encoded for email transport. + name = Header(user.real_name).encode() + msg.replace_header('To', formataddr((name, recipient))) + return super(PersonalizedDelivery, self)._deliver_to_recipients( + mlist, msg, msgdata, sender, recipients) diff --git a/src/mailman/mta/verp.py b/src/mailman/mta/verp.py index be44afd10..a8cc9d937 100644 --- a/src/mailman/mta/verp.py +++ b/src/mailman/mta/verp.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License along with # GNU Mailman. If not, see <http://www.gnu.org/licenses/>. -"""VERP (i.e. personalized) message delivery.""" +"""VERP delivery.""" from __future__ import absolute_import, unicode_literals @@ -55,6 +55,7 @@ class VERPDelivery(BaseDelivery): return sender = self._get_sender(mlist, msg, msgdata) sender_mailbox, sender_domain = split_email(sender) + refused = {} for recipient in recipients: # Make a copy of the original messages and operator on it, since # we're going to munge it repeatedly for each recipient. @@ -80,5 +81,7 @@ class VERPDelivery(BaseDelivery): del message_copy['x-mailman-copy'] if recipient in msgdata.get('add-dup-header', {}): message_copy['X-Mailman-Copy'] = 'yes' - self._deliver_to_recipients(mlist, msg, msgdata, - verp_sender, [recipient]) + recipient_refused = self._deliver_to_recipients( + mlist, msg, msgdata, verp_sender, [recipient]) + refused.update(recipient_refused) + return refused |
