diff options
author | Folker Bernitt <fbernitt@thoughtworks.com> | 2015-11-04 14:22:59 +0100 |
---|---|---|
committer | Folker Bernitt <fbernitt@thoughtworks.com> | 2015-11-04 14:25:07 +0100 |
commit | 5b29217cdea1bfd487bfe8ee064559a88540ca58 (patch) | |
tree | f7486aad10f5906db1b83728515594e1ceb62c11 /service | |
parent | d79aa00e3c24c5bf5e5ed5ba5a9b976f93034362 (diff) |
Change str email to twisted.mail.smtp.User
- Issue #499
- leap.mail relies on this
Diffstat (limited to 'service')
-rw-r--r-- | service/pixelated/adapter/services/mail_sender.py | 10 | ||||
-rw-r--r-- | service/test/unit/adapter/services/test_mail_sender.py | 15 |
2 files changed, 23 insertions, 2 deletions
diff --git a/service/pixelated/adapter/services/mail_sender.py b/service/pixelated/adapter/services/mail_sender.py index ca1e99d7..faf3d228 100644 --- a/service/pixelated/adapter/services/mail_sender.py +++ b/service/pixelated/adapter/services/mail_sender.py @@ -21,6 +21,7 @@ from twisted.internet.defer import Deferred, fail from twisted.mail.smtp import SMTPSenderFactory from twisted.internet import reactor, defer from pixelated.support.functional import flatten +from twisted.mail.smtp import User class SMTPDownException(Exception): @@ -28,6 +29,9 @@ class SMTPDownException(Exception): Exception.__init__(self, "Couldn't send mail now, try again later.") +NOT_NEEDED = None + + class MailSender(object): def __init__(self, smtp_config, keymanager): @@ -40,7 +44,8 @@ class MailSender(object): deferreds = [] for recipient in recipients: - deferreds.append(outgoing_mail.send_message(mail.to_smtp_format(), recipient)) + smtp_recipient = self._create_twisted_smtp_recipient(recipient) + deferreds.append(outgoing_mail.send_message(mail.to_smtp_format(), smtp_recipient)) return defer.gatherResults(deferreds) @@ -52,6 +57,9 @@ class MailSender(object): str(self._smtp_config.remote_smtp_host), int(self._smtp_config.remote_smtp_port)) + def _create_twisted_smtp_recipient(self, recipient): + return User(str(recipient), NOT_NEEDED, NOT_NEEDED, NOT_NEEDED) + class LocalSmtpMailSender(object): diff --git a/service/test/unit/adapter/services/test_mail_sender.py b/service/test/unit/adapter/services/test_mail_sender.py index d8c33f17..20ddc2c6 100644 --- a/service/test/unit/adapter/services/test_mail_sender.py +++ b/service/test/unit/adapter/services/test_mail_sender.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Affero General Public License # along with Pixelated. If not, see <http://www.gnu.org/licenses/>. from leap.mail.outgoing.service import OutgoingMail +from twisted.mail.smtp import User from twisted.trial import unittest from mockito import mock, when, verify, any, unstub @@ -24,6 +25,18 @@ from pixelated.support.functional import flatten from test.support.test_helper import mail_dict from twisted.internet import reactor, defer from twisted.internet.defer import Deferred +from mockito.matchers import Matcher + + +class TwistedSmtpUserCapture(Matcher): + + def __init__(self, username): + self._username = username + + def matches(self, arg): + return isinstance(arg, User) \ + and isinstance(arg.dest.addrstr, str) \ + and self._username == arg.dest.addrstr class MailSenderTest(unittest.TestCase): @@ -48,7 +61,7 @@ class MailSenderTest(unittest.TestCase): yield sender.sendmail(input_mail) for recipient in flatten([input_mail.to, input_mail.cc, input_mail.bcc]): - verify(OutgoingMail).send_message(any(), recipient) + verify(OutgoingMail).send_message(any(), TwistedSmtpUserCapture(recipient)) class LocalSmtpMailSenderTest(unittest.TestCase): |