marrow / mailer

A light-weight, modular, message representation and mail delivery framework for Python.
MIT License
279 stars 62 forks source link

Check Python 3 compatibility. #33

Closed amcgregor closed 7 years ago

amcgregor commented 12 years ago

Issues with SMTPlib and str vs. bytes header values; specifically those of the address values such as From.

Needs more research on Python 3's smtp library. On the following MIME message:

Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
From: =?utf-8?q?Alice_Bevan-McGregor?= <alice@gothcandy.com>
Subject: =?utf-8?q?This_is_a_test_message=2E?=
Date: =?utf-8?q?Wed=2C_23_Nov_2011_00=3A27=3A51_-0500?=
To: =?utf-8?q?Your_Name_Here?= <alice.mcgregor@me.com>
X-Mailer: =?utf-8?q?marrow=2Emailer_4=2E0=2E0b3?=

Testing!

I'm getting:

ERROR:marrow.mailer.transport.smtp:<20111123052751.23872.75835@Lucifer.local> EXCEPTION TypeError
Traceback (most recent call last):
  File "/Users/amcgregor/Projects/Marrow/src/marrow.mailer/marrow/mailer/transport/smtp.py", line 119, in send_with_smtp
    self.connection.sendmail(sender, recipients, content)
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/smtplib.py", line 741, in sendmail
    (code, resp) = self.mail(from_addr, esmtp_opts)
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/smtplib.py", line 482, in mail
    self.putcmd("mail", "FROM:%s%s" % (quoteaddr(sender), optionlist))
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/smtplib.py", line 143, in quoteaddr
    m = email.utils.parseaddr(addr)[1]
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/email/utils.py", line 192, in parseaddr
    addrs = _AddressList(addr).addresslist
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/email/_parseaddr.py", line 471, in __init__
    self.addresslist = self.getaddrlist()
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/email/_parseaddr.py", line 224, in getaddrlist
    ad = self.getaddress()
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/email/_parseaddr.py", line 234, in getaddress
    self.gotonext()
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/email/_parseaddr.py", line 207, in gotonext
    if self.field[self.pos] in self.LWS + '\n\r':
TypeError: 'in <string>' requires string as left operand, not int
amcgregor commented 9 years ago
Traceback (most recent call last):
  File "mtest.py", line 24, in <module>
    msg.send()
  File "/Users/amcgregor/Library/Environments/marrow/lib/python3.4/site-packages/marrow/mailer/message.py", line 332, in send
    return self.mailer.send(self)
  File "/Users/amcgregor/Library/Environments/marrow/lib/python3.4/site-packages/marrow/mailer/__init__.py", line 146, in send
    result = self.manager.deliver(message)
  File "/Users/amcgregor/Library/Environments/marrow/lib/python3.4/site-packages/marrow/mailer/manager/immediate.py", line 43, in deliver
    result = transport.deliver(message)
  File "/Users/amcgregor/Library/Environments/marrow/lib/python3.4/site-packages/marrow/mailer/transport/smtp.py", line 105, in deliver
    self.send_with_smtp(message)
  File "/Users/amcgregor/Library/Environments/marrow/lib/python3.4/site-packages/marrow/mailer/transport/smtp.py", line 114, in send_with_smtp
    content = bytes(message)
TypeError: 'Message' object is not iterable

The above traceback occurs with a minimal (immediate, smtp) test case under Python 3.4, and likely earlier Python versions in the 3.x branch.

amcgregor commented 9 years ago

Additionally, the following traceback occurs when using Mailgun SMTP delivery with forced SSL: (mail.transport.tls=ssl and mail.transport.port=465)

Delivery of message <20150127231531.4298.74643@Lucifer.local> failed.
Traceback (most recent call last):
  File "/Users/amcgregor/Library/Environments/marrow/lib/python3.4/site-packages/marrow/mailer/manager/util.py", line 50, in __enter__
    transport = pool.transports.get(False)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/queue.py", line 164, in get
    raise Empty
queue.Empty

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "mtest.py", line 24, in <module>
    msg.send()
  File "/Users/amcgregor/Library/Environments/marrow/lib/python3.4/site-packages/marrow/mailer/message.py", line 332, in send
    return self.mailer.send(self)
  File "/Users/amcgregor/Library/Environments/marrow/lib/python3.4/site-packages/marrow/mailer/__init__.py", line 146, in send
    result = self.manager.deliver(message)
  File "/Users/amcgregor/Library/Environments/marrow/lib/python3.4/site-packages/marrow/mailer/manager/immediate.py", line 41, in deliver
    with self.transport() as transport:
  File "/Users/amcgregor/Library/Environments/marrow/lib/python3.4/site-packages/marrow/mailer/manager/util.py", line 57, in __enter__
    transport.startup()
  File "/Users/amcgregor/Library/Environments/marrow/lib/python3.4/site-packages/marrow/mailer/transport/smtp.py", line 50, in startup
    self.connect_to_server()
  File "/Users/amcgregor/Library/Environments/marrow/lib/python3.4/site-packages/marrow/mailer/transport/smtp.py", line 78, in connect_to_server
    connection.connect(self.host, self.port)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/smtplib.py", line 321, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/smtplib.py", line 920, in _get_socket
    server_hostname=server_hostname)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/ssl.py", line 364, in wrap_socket
    _context=self)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/ssl.py", line 578, in __init__
    self.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/ssl.py", line 805, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: TLSV1_ALERT_DECODE_ERROR] tlsv1 alert decode error (_ssl.c:600)
amcgregor commented 9 years ago

From @nandoflorestan on IRC:

I am trying to do my part for open source development and I need marrow.mailer to work on Python 3.4, so I went ahead and created a py34 branch in my fork of marrow.mailer, but many tests are failing even on Python 2.7. Looks like this is being developed without any attention to the automated tests! I would appreciate some help on getting them all to pass when you have some time.

https://github.com/nandoflorestan/marrow.mailer/tree/py34

I already have some commits on the branch linked above.

seanthegeek commented 8 years ago

Any progress on this?