marrow / mailer

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

smtp transport needlessly calls connect #4

Closed namn closed 13 years ago

namn commented 13 years ago

Python docs says:

If the optional host and port parameters are given, the SMTP connect() method is called with those parameters during initialization.

Therefore, connect_to_server makes an extra call to SMTP.connect. This is not only needless but wrong also. Deep within smtplib, SMTP.file is only created in getreply. And getreply is called in connect. Another call to connect, hence, will create another socket, but getreply always refers to the old file (socket).

It is debatable whether this is smtplib or marrow.mailer.transport.smtp though. I would like to see smtplib's connect refresh its file as well as sock variables. But an easier fix, one that you have control over, is to fix smtp transport ;).

amcgregor commented 13 years ago

Since the debug level needs to be set prior to a connection being made, marrow.mailer's smtp transport should not supply arguments to the SMTP connection's initialization handler that would cause it to connect. Explicit is better than implicit.

Additionally, improper handling of internal file handles in the Python smtp package is a bug in Python; an additional bug report should be filed there.