--- smtplib.py.orig 2006-07-10 16:13:22.000000000 -0400 +++ smtplib.py 2006-07-12 08:22:31.000000000 -0400 @@ -52,13 +52,23 @@ __all__ = ["SMTPException","SMTPServerDisconnected","SMTPResponseException", "SMTPSenderRefused","SMTPRecipientsRefused","SMTPDataError", "SMTPConnectError","SMTPHeloError","SMTPAuthenticationError", - "quoteaddr","quotedata","SMTP"] + "quoteaddr","quotedata","SMTP", "AUTH_PLAIN", "AUTH_CRAM_MD5", + "AUTH_LOGIN"] SMTP_PORT = 25 CRLF="\r\n" 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.""" @@ -505,7 +515,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: @@ -535,11 +545,6 @@ def encode_plain(user, password): return encode_base64("%s\0%s\0%s" % (user, 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() @@ -552,11 +557,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 2006-07-12 07:52:02.000000000 -0400 +++ libsmtplib.tex 2006-07-12 07:43:26.000000000 -0400 @@ -160,9 +160,11 @@ \note{Many sites disable SMTP \samp{VRFY} in order to foil spammers.} \end{methoddesc} -\begin{methoddesc}{login}{user, password} +\begin{methoddesc}{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,