summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/pixelated/adapter/services/mail_sender.py5
-rw-r--r--service/test/unit/adapter/services/test_mail_sender.py14
2 files changed, 19 insertions, 0 deletions
diff --git a/service/pixelated/adapter/services/mail_sender.py b/service/pixelated/adapter/services/mail_sender.py
index 8ccfc5a2..4499adbd 100644
--- a/service/pixelated/adapter/services/mail_sender.py
+++ b/service/pixelated/adapter/services/mail_sender.py
@@ -91,4 +91,9 @@ class MailSender(object):
int(self._smtp_config.remote_smtp_port))
def _create_twisted_smtp_recipient(self, recipient):
+ # TODO: Better is fix Twisted instead
+ recipient = self._remove_canonical_recipient(recipient)
return User(str(recipient), NOT_NEEDED, NOT_NEEDED, NOT_NEEDED)
+
+ def _remove_canonical_recipient(self, recipient):
+ return recipient.split('<')[1][0:-1] if '<' in recipient else recipient
diff --git a/service/test/unit/adapter/services/test_mail_sender.py b/service/test/unit/adapter/services/test_mail_sender.py
index 562f919d..cd4a84c3 100644
--- a/service/test/unit/adapter/services/test_mail_sender.py
+++ b/service/test/unit/adapter/services/test_mail_sender.py
@@ -100,3 +100,17 @@ class MailSenderTest(unittest.TestCase):
for recipient in flatten([input_mail.to, input_mail.cc, input_mail.bcc]):
verify(OutgoingMail).send_message(MailToSmtpFormatCapture(recipient, bccs), TwistedSmtpUserCapture(recipient))
+
+ def test_remove_canonical_recipient_when_it_is_not_canonical(self):
+ recipient = u'user@pixelated.org'
+
+ non_canonical = self.sender._remove_canonical_recipient(recipient)
+
+ self.assertEqual(recipient, non_canonical)
+
+ def test_remove_canonical_recipient_when_it_is_canonical(self):
+ recipient = u'User <user@pixelated.org>'
+
+ non_canonical = self.sender._remove_canonical_recipient(recipient)
+
+ self.assertEqual(u'user@pixelated.org', non_canonical)