Skip to content

Commit

Permalink
Merge pull request #816 from twisted/9180-rodrigc-smtp
Browse files Browse the repository at this point in the history
Author: rodrigc
Reviewer: tardyp
Fixes: ticket:9180

Fix stacktrace in twisted.smtp on buildbot
  • Loading branch information
rodrigc committed Jun 14, 2017
2 parents 562496b + fe368dc commit 5ddbe39
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/twisted/mail/newsfragments/9180.bugfix
@@ -0,0 +1 @@
Sending a list of recipients with twisted.smtp.SenderFactory has been fixed. This fixes a problem found when running buildbot.
7 changes: 4 additions & 3 deletions src/twisted/mail/smtp.py
Expand Up @@ -17,9 +17,10 @@
import os
import random
import binascii
import email.utils
import warnings

from email.utils import parseaddr

from zope.interface import implementer

from twisted import cred
Expand Down Expand Up @@ -176,7 +177,7 @@ def quoteaddr(addr):
if isinstance(addr, bytes):
addr = addr.decode('ascii')

res = email.utils.parseaddr(addr)
res = parseaddr(addr)

if res == (None, None):
# It didn't parse, use it as-is
Expand Down Expand Up @@ -1896,7 +1897,7 @@ def __init__(self, fromEmail, toEmail, file, deferred, retries=5,
if not isinstance(_email, bytes):
_email = _email.encode('ascii')

toEmailFinal.append(email)
toEmailFinal.append(_email)
toEmail = toEmailFinal

self.fromEmail = Address(fromEmail)
Expand Down
28 changes: 26 additions & 2 deletions src/twisted/mail/test/test_smtp.py
Expand Up @@ -759,14 +759,38 @@ def check(ign):
return d


def test_SMTPClient(self):
def test_SMTPClientRecipientBytes(self):
"""
Test timeout for L{smtp.SMTPSenderFactory}: the response L{Deferred}
should be errback with a L{smtp.SMTPTimeoutError}.
"""
onDone = defer.Deferred()
clientFactory = smtp.SMTPSenderFactory(
'source@address', 'recipient@address',
'source@address', b'recipient@address',
BytesIO(b"Message body"), onDone,
retries=0, timeout=0.5)
return self._timeoutTest(onDone, clientFactory)


def test_SMTPClientRecipientUnicode(self):
"""
Use a L{unicode} recipient.
"""
onDone = defer.Deferred()
clientFactory = smtp.SMTPSenderFactory(
'source@address', u'recipient@address',
BytesIO(b"Message body"), onDone,
retries=0, timeout=0.5)
return self._timeoutTest(onDone, clientFactory)


def test_SMTPClientRecipientList(self):
"""
Use a L{list} of recipients.
"""
onDone = defer.Deferred()
clientFactory = smtp.SMTPSenderFactory(
'source@address', (u'recipient1@address', b'recipient2@address'),
BytesIO(b"Message body"), onDone,
retries=0, timeout=0.5)
return self._timeoutTest(onDone, clientFactory)
Expand Down

0 comments on commit 5ddbe39

Please sign in to comment.