@@ -248,6 +248,7 @@ def __init__(self, host='', port=0, local_hostname=None,
248
248
self .esmtp_features = {}
249
249
self .command_encoding = 'ascii'
250
250
self .source_address = source_address
251
+ self ._auth_challenge_count = 0
251
252
252
253
if host :
253
254
(code , msg ) = self .connect (host , port )
@@ -633,10 +634,13 @@ def auth(self, mechanism, authobject, *, initial_response_ok=True):
633
634
if initial_response is not None :
634
635
response = encode_base64 (initial_response .encode ('ascii' ), eol = '' )
635
636
(code , resp ) = self .docmd ("AUTH" , mechanism + " " + response )
637
+ self ._auth_challenge_count = 1
636
638
else :
637
639
(code , resp ) = self .docmd ("AUTH" , mechanism )
640
+ self ._auth_challenge_count = 0
638
641
# If server responds with a challenge, send the response.
639
- if code == 334 :
642
+ while code == 334 :
643
+ self ._auth_challenge_count += 1
640
644
challenge = base64 .decodebytes (resp )
641
645
response = encode_base64 (
642
646
authobject (challenge ).encode ('ascii' ), eol = '' )
@@ -662,7 +666,7 @@ def auth_plain(self, challenge=None):
662
666
def auth_login (self , challenge = None ):
663
667
""" Authobject to use with LOGIN authentication. Requires self.user and
664
668
self.password to be set."""
665
- if challenge is None :
669
+ if challenge is None or self . _auth_challenge_count < 2 :
666
670
return self .user
667
671
else :
668
672
return self .password
0 commit comments