--- smtplib.py.orig 2007-04-03 12:30:12.000000000 -0400 +++ smtplib.py 2007-04-03 12:28:32.000000000 -0400 @@ -52,7 +52,8 @@ __all__ = ["SMTPException","SMTPServerDisconnected","SMTPResponseException", "SMTPSenderRefused","SMTPRecipientsRefused","SMTPDataError", "SMTPConnectError","SMTPHeloError","SMTPAuthenticationError", - "quoteaddr","quotedata","SMTP","SMTP_SSL"] + "quoteaddr","quotedata","SMTP", "STMP_SSL", + "AUTH_PLAIN", "AUTH_CRAM_MD5", "AUTH_LOGIN"] SMTP_PORT = 25 SMTP_SSL_PORT = 465 @@ -60,6 +61,15 @@ OLDSTYLE_AUTH = re.compile(r"auth=(.*)", re.I) +AUTH_PLAIN = "PLAIN" +AUTH_CRAM_MD5 = "CRAM-MD5" +AUTH_LOGIN = "LOGIN" + +# List of authentication methods we support: from preferred to +# less preferred methods. Except for the purpose of testing the weaker +# ones, we prefer stronger methods like CRAM-MD5: +PREFERRED_AUTHS = [AUTH_CRAM_MD5, AUTH_PLAIN, AUTH_LOGIN] + # Exception classes used by this module. class SMTPException(Exception): """Base class for all exceptions raised by this module.""" @@ -503,7 +513,7 @@ # some useful methods - def login(self, user, password): + def login(self, user, password, preferred_auths=PREFERRED_AUTHS): """Log in on an SMTP server that requires authentication. The arguments are: @@ -533,11 +543,6 @@ def encode_plain(user, password): return encode_base64("\0%s\0%s" % (user, password), eol="") - - AUTH_PLAIN = "PLAIN" - AUTH_CRAM_MD5 = "CRAM-MD5" - AUTH_LOGIN = "LOGIN" - if self.helo_resp is None and self.ehlo_resp is None: if not (200 <= self.ehlo()[0] <= 299): (code, resp) = self.helo() @@ -550,11 +555,6 @@ # Authentication methods the server supports: authlist = self.esmtp_features["auth"].split() - # List of authentication methods we support: from preferred to - # less preferred methods. Except for the purpose of testing the weaker - # ones, we prefer stronger methods like CRAM-MD5: - preferred_auths = [AUTH_CRAM_MD5, AUTH_PLAIN, AUTH_LOGIN] - # Determine the authentication method we'll use authmethod = None for method in preferred_auths: --- libsmtplib.tex.orig 2007-04-03 12:30:35.000000000 -0400 +++ libsmtplib.tex 2007-04-03 10:08:04.000000000 -0400 @@ -195,9 +195,11 @@ \note{Many sites disable SMTP \samp{VRFY} in order to foil spammers.} \end{methoddesc} -\begin{methoddesc}[SMTP]{login}{user, password} +\begin{methoddesc}[SMTP]{login}{user, password,\optional{, preferred_auths=[]}} Log in on an SMTP server that requires authentication. The arguments are the username and the password to authenticate with. +The default order (AUTH_CRAM_MD5, AUTH_PLAIN, AUTH_LOGIN) used to select +the AUTH method may be overridden with the optional preferred_auths parameter. If there has been no previous \samp{EHLO} or \samp{HELO} command this session, this method tries ESMTP \samp{EHLO} first. This method will return normally if the authentication was successful,