summaryrefslogtreecommitdiff
path: root/src/mailman/mta/personalized.py
diff options
context:
space:
mode:
authorBarry Warsaw2009-11-01 18:21:20 -0500
committerBarry Warsaw2009-11-01 18:21:20 -0500
commitb2a308fe129c59bd8b4732907e55133807c2d8d9 (patch)
tree1f40b7a4ee68ae97cf9dcca2a725fca5b4b0bd43 /src/mailman/mta/personalized.py
parent0f03599f841388c066232cdbfd417d69e57b312d (diff)
downloadmailman-b2a308fe129c59bd8b4732907e55133807c2d8d9.tar.gz
mailman-b2a308fe129c59bd8b4732907e55133807c2d8d9.tar.zst
mailman-b2a308fe129c59bd8b4732907e55133807c2d8d9.zip
Diffstat (limited to 'src/mailman/mta/personalized.py')
-rw-r--r--src/mailman/mta/personalized.py44
1 files changed, 34 insertions, 10 deletions
diff --git a/src/mailman/mta/personalized.py b/src/mailman/mta/personalized.py
index 99d939096..3c8eba25a 100644
--- a/src/mailman/mta/personalized.py
+++ b/src/mailman/mta/personalized.py
@@ -22,6 +22,7 @@ from __future__ import absolute_import, unicode_literals
__metaclass__ = type
__all__ = [
'PersonalizedDelivery',
+ 'PersonalizedMixin',
]
@@ -34,17 +35,26 @@ from mailman.mta.verp import VERPDelivery
-class PersonalizedDelivery(VERPDelivery):
- """Personalize the message's To header."""
+class PersonalizedMixin:
+ """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]
+ This is a mixin class, providing the basic functionality for header
+ personalization. The methods it provides are intended to be called from a
+ concrete base class.
+ """
+
+ def personalize_to(self, msg, recipient):
+ """Modify the To header to contain the recipient.
+
+ The To header contents is replaced with the recipient's address, and
+ if the recipient is a user registered with Mailman, the recipient's
+ real name too.
+
+ :param msg: The message to modify.
+ :type msg: `email.message.Message`
+ :param recipient: The recipient's email address.
+ :type recipient: string
+ """
user_manager = getUtility(IUserManager)
user = user_manager.get_user(recipient)
if user is None:
@@ -55,5 +65,19 @@ class PersonalizedDelivery(VERPDelivery):
# encoded for email transport.
name = Header(user.real_name).encode()
msg.replace_header('To', formataddr((name, recipient)))
+
+
+class PersonalizedDelivery(VERPDelivery, PersonalizedMixin):
+ """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]
+ self.personalize_to(msg, recipient)
return super(PersonalizedDelivery, self)._deliver_to_recipients(
mlist, msg, msgdata, sender, recipients)