Skip to content

Commit a0da4d4

Browse files
committed
Close client on failed IMAP login (consistency with SMTP/POP)
1 parent 652c6e8 commit a0da4d4

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

emailproxy.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,7 @@ def process_data(self, byte_data, censor_server_log=False):
931931
self.send(b'+ \r\n') # request data (RFC 7888's non-synchronising literals don't require this)
932932
elif len(split_string) > 1:
933933
# credentials as a single literal doesn't seem to be valid (RFC 9051), but some clients do this
934+
self.login_literal_length_awaited = 0
934935
self.authenticate_connection(split_string[0], ' '.join(split_string[1:]))
935936
else:
936937
super().process_data(byte_data) # probably an invalid command, but just let the server handle it
@@ -1320,11 +1321,15 @@ def process_data(self, byte_data):
13201321
# as with SMTP, but all well-known servers provide a non-STARTTLS variant, so left unimplemented for now
13211322
str_response = byte_data.decode('utf-8', 'replace').rstrip('\r\n')
13221323

1323-
# if authentication succeeds, remove our proxy from the client and ignore all further communication
1324+
# if authentication succeeds (or fails), remove our proxy from the client and ignore all further communication
13241325
# don't use a regex here as the tag must match exactly; RFC 3501 specifies uppercase 'OK', so startswith is fine
13251326
if str_response.startswith('%s OK' % self.client_connection.authentication_tag):
13261327
Log.info(self.info_string(), '[ Successfully authenticated IMAP connection - removing proxy ]')
13271328
self.client_connection.authenticated = True
1329+
elif str_response.startswith('%s NO' % self.client_connection.authentication_tag):
1330+
super().process_data(byte_data) # an error occurred - just send to the client and exit
1331+
self.close()
1332+
return
13281333

13291334
# intercept pre-auth CAPABILITY response to advertise only AUTH=PLAIN (+SASL-IR) and re-enable LOGIN if required
13301335
if IMAP_CAPABILITY_MATCHER.match(str_response):

0 commit comments

Comments
 (0)