Skip to content

Commit 1164a43

Browse files
committed
Handle SSLWantReadError when using local certificates (see #9)
1 parent a17b059 commit 1164a43

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ An IMAP/SMTP proxy that transparently adds OAuth 2.0 authentication for client a
66
Many email services that provide IMAP/SMTP access require the use of OAuth 2.0 to authenticate the connection, but not all clients support this method. This script creates a simple local proxy that intercepts the standard IMAP/SMTP authentication commands and transparently replaces them with the appropriate (X)OAuth 2.0 commands and credentials. Your email client can continue to use the traditional `login` or `auth`/`authenticate` options, with no need to make it aware of OAuth's existence.
77

88
### Example use-cases
9-
- You need to use an Office 365 email account, but don't get on with Outlook. The email client you like doesn't support OAuth2.
9+
- You need to use an Office 365 email account, but don't get on with Outlook. The email client you like doesn't support OAuth 2.0.
1010
- You currently use Gmail with your raw account credentials (i.e., username/password). You've received a notification that Google is disabling this access at the end of May 2022, but you don't want to use an [App Password](https://support.google.com/accounts/answer/185833) (or cannot enable this option).
11-
- You have an account already set up in an email client, but you need to switch it to OAuth2 authentication. You can edit the server details, but the client forces you to delete and re-add the account to enable OAuth2, and you don't want to do this.
12-
- You run a server with multiple services that use IMAP/SMTP, and you don't want to have to set up OAuth2 independently on each one.
11+
- You have an account already set up in an email client, but you need to switch it to OAuth 2.0 authentication. You can edit the server details, but the client forces you to delete and re-add the account to enable OAuth 2.0, and you don't want to do this.
12+
- You run a server with multiple services that use IMAP/SMTP, and you don't want to have to set up OAuth 2.0 independently on each one.
1313

1414
In all of these cases and more, this proxy script can help. Follow the instructions below to get started, and please [open an issue](https://github.com/simonrob/email-oauth2-proxy/issues) with any problems or suggestions.
1515

emailproxy.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -526,20 +526,22 @@ def get_data(self):
526526
try:
527527
byte_data = self.recv(RECEIVE_BUFFER_SIZE)
528528
return byte_data
529-
except BlockingIOError:
529+
except ssl.SSLWantReadError:
530+
Log.info(
531+
'Warning: ignoring client-side SSLWantReadError (see github.com/simonrob/email-oauth2-proxy/issues/9)')
530532
return
531533
except OSError:
532534
self.handle_error()
533-
return
534535

535536
def handle_read(self):
536537
byte_data = self.get_data()
538+
if not byte_data:
539+
return
537540

538541
# client is established after server; this state should not happen unless already closing
539542
if not self.server_connection:
540-
if byte_data:
541-
Log.debug(self.proxy_type, self.connection_info,
542-
'Data received without server connection - ignoring and closing:', byte_data)
543+
Log.debug(self.proxy_type, self.connection_info,
544+
'Data received without server connection - ignoring and closing:', byte_data)
543545
self.close()
544546
return
545547

@@ -788,16 +790,16 @@ def get_data(self):
788790
return
789791
except OSError:
790792
self.handle_error()
791-
return
792793

793794
def handle_read(self):
794795
byte_data = self.get_data()
796+
if not byte_data:
797+
return
795798

796799
# data received before client is connected (or after client has disconnected) - ignore
797800
if not self.client_connection:
798-
if byte_data:
799-
Log.debug(self.proxy_type, self.connection_info, 'Data received without client connection - ignoring:',
800-
byte_data)
801+
Log.debug(self.proxy_type, self.connection_info, 'Data received without client connection - ignoring:',
802+
byte_data)
801803
return
802804

803805
# we have already authenticated - nothing to do; just pass data directly to client, ignoring overridden method

0 commit comments

Comments
 (0)