simonrob / email-oauth2-proxy

An IMAP/POP/SMTP proxy that transparently adds OAuth 2.0 authentication for email clients that don't support this method.
Apache License 2.0
797 stars 86 forks source link

11.1 won't start because of empty display name. #204

Closed w5pny closed 10 months ago

w5pny commented 10 months ago

The version I've been running that was the current git September 12, 2023 runs fine, but the current version (11.1) won;t start because get_display() is passed an empty string.

Syslog:

Nov  2 16:28:31 maui systemd[1]: Started Email OAuth 2.0 Proxy.
Nov  2 16:28:31 maui python3[66688]: Unable to init server: Could not connect: Connection refused
Nov  2 16:28:31 maui python3[66688]: message repeated 3 times: [ Unable to init server: Could not connect: Connection refused]
Nov  2 16:28:31 maui python3[66688]: Traceback (most recent call last):
Nov  2 16:28:31 maui python3[66688]:   File "/usr/local/lib/emailproxy/emailproxy.py", line 64, in <module>
Nov  2 16:28:31 maui python3[66688]:     import pystray  # the menu bar/taskbar GUI
Nov  2 16:28:31 maui python3[66688]:   File "/usr/local/lib/python3.8/dist-packages/pystray/__init__.py", line 64, in <module>
Nov  2 16:28:31 maui python3[66688]:     Icon = backend().Icon
Nov  2 16:28:31 maui python3[66688]:   File "/usr/local/lib/python3.8/dist-packages/pystray/__init__.py", line 56, in backend
Nov  2 16:28:31 maui python3[66688]:     return candidate()
Nov  2 16:28:31 maui python3[66688]:   File "/usr/local/lib/python3.8/dist-packages/pystray/__init__.py", line 36, in xorg
Nov  2 16:28:31 maui python3[66688]:     from . import _xorg as backend; return backend
Nov  2 16:28:31 maui python3[66688]:   File "/usr/local/lib/python3.8/dist-packages/pystray/_xorg.py", line 36, in <module>
Nov  2 16:28:31 maui python3[66688]:     display = Xlib.display.Display()
Nov  2 16:28:31 maui python3[66688]:   File "/usr/local/lib/python3.8/dist-packages/Xlib/display.py", line 89, in __init__
Nov  2 16:28:31 maui python3[66688]:     self.display = _BaseDisplay(display)
Nov  2 16:28:31 maui python3[66688]:   File "/usr/local/lib/python3.8/dist-packages/Xlib/display.py", line 71, in __init__
Nov  2 16:28:31 maui python3[66688]:     protocol_display.Display.__init__(self, *args, **keys)
Nov  2 16:28:31 maui python3[66688]:   File "/usr/local/lib/python3.8/dist-packages/Xlib/protocol/display.py", line 84, in __init__
Nov  2 16:28:31 maui python3[66688]:     name, protocol, host, displayno, screenno = connect.get_display(display)
Nov  2 16:28:31 maui python3[66688]:   File "/usr/local/lib/python3.8/dist-packages/Xlib/support/connect.py", line 73, in get_display
Nov  2 16:28:31 maui python3[66688]:     return mod.get_display(display)
Nov  2 16:28:31 maui python3[66688]:   File "/usr/local/lib/python3.8/dist-packages/Xlib/support/unix_connect.py", line 59, in get_display
Nov  2 16:28:31 maui python3[66688]:     raise error.DisplayNameError(display)
Nov  2 16:28:31 maui python3[66688]: Xlib.error.DisplayNameError: Bad display name ""
Nov  2 16:28:31 maui systemd[1]: emailproxy.service: Main process exited, code=exited, status=1/FAILURE
Nov  2 16:28:31 maui systemd[1]: emailproxy.service: Failed with result 'exit-code'.
Nov  2 16:28:31 maui systemd[1]: emailproxy.service: Scheduled restart job, restart counter is at 1.
Nov  2 16:28:31 maui systemd[1]: Stopped Email OAuth 2.0 Proxy.
Nov  2 16:28:31 maui systemd[1]: Started Email OAuth 2.0 Proxy.
Nov  2 16:28:31 maui python3[66692]: Unable to init server: Could not connect: Connection refused
Nov  2 16:28:31 maui python3[66692]: message repeated 3 times: [ Unable to init server: Could not connect: Connection refused]
Nov  2 16:28:31 maui python3[66692]: Traceback (most recent call last):
Nov  2 16:28:31 maui python3[66692]:   File "/usr/local/lib/emailproxy/emailproxy.py", line 64, in <module>
Nov  2 16:28:31 maui python3[66692]:     import pystray  # the menu bar/taskbar GUI
Nov  2 16:28:31 maui python3[66692]:   File "/usr/local/lib/python3.8/dist-packages/pystray/__init__.py", line 64, in <module>
Nov  2 16:28:31 maui python3[66692]:     Icon = backend().Icon
Nov  2 16:28:31 maui python3[66692]:   File "/usr/local/lib/python3.8/dist-packages/pystray/__init__.py", line 56, in backend
Nov  2 16:28:31 maui python3[66692]:     return candidate()
Nov  2 16:28:31 maui python3[66692]:   File "/usr/local/lib/python3.8/dist-packages/pystray/__init__.py", line 36, in xorg
Nov  2 16:28:31 maui python3[66692]:     from . import _xorg as backend; return backend
Nov  2 16:28:31 maui python3[66692]:   File "/usr/local/lib/python3.8/dist-packages/pystray/_xorg.py", line 36, in <module>
Nov  2 16:28:31 maui python3[66692]:     display = Xlib.display.Display()
Nov  2 16:28:31 maui python3[66692]:   File "/usr/local/lib/python3.8/dist-packages/Xlib/display.py", line 89, in __init__
Nov  2 16:28:31 maui python3[66692]:     self.display = _BaseDisplay(display)
Nov  2 16:28:31 maui python3[66692]:   File "/usr/local/lib/python3.8/dist-packages/Xlib/display.py", line 71, in __init__
Nov  2 16:28:31 maui python3[66692]:     protocol_display.Display.__init__(self, *args, **keys)
Nov  2 16:28:31 maui python3[66692]:   File "/usr/local/lib/python3.8/dist-packages/Xlib/protocol/display.py", line 84, in __init__
Nov  2 16:28:31 maui python3[66692]:     name, protocol, host, displayno, screenno = connect.get_display(display)
Nov  2 16:28:31 maui python3[66692]:   File "/usr/local/lib/python3.8/dist-packages/Xlib/support/connect.py", line 73, in get_display
Nov  2 16:28:31 maui python3[66692]:     return mod.get_display(display)
Nov  2 16:28:31 maui python3[66692]:   File "/usr/local/lib/python3.8/dist-packages/Xlib/support/unix_connect.py", line 59, in get_display
Nov  2 16:28:31 maui python3[66692]:     raise error.DisplayNameError(display)
Nov  2 16:28:31 maui python3[66692]: Xlib.error.DisplayNameError: Bad display name ""
Nov  2 16:28:31 maui systemd[1]: emailproxy.service: Main process exited, code=exited, status=1/FAILURE
Nov  2 16:28:31 maui systemd[1]: emailproxy.service: Failed with result 'exit-code'.
Nov  2 16:28:32 maui systemd[1]: emailproxy.service: Scheduled restart job, restart counter is at 2.
Nov  2 16:28:32 maui systemd[1]: Stopped Email OAuth 2.0 Proxy.
Nov  2 16:28:32 maui systemd[1]: Started Email OAuth 2.0 Proxy.
Nov  2 16:28:32 maui python3[66696]: Unable to init server: Could not connect: Connection refused
Nov  2 16:28:32 maui python3[66696]: message repeated 3 times: [ Unable to init server: Could not connect: Connection refused]
Nov  2 16:28:32 maui python3[66696]: Traceback (most recent call last):
Nov  2 16:28:32 maui python3[66696]:   File "/usr/local/lib/emailproxy/emailproxy.py", line 64, in <module>
Nov  2 16:28:32 maui python3[66696]:     import pystray  # the menu bar/taskbar GUI
Nov  2 16:28:32 maui python3[66696]:   File "/usr/local/lib/python3.8/dist-packages/pystray/__init__.py", line 64, in <module>
Nov  2 16:28:32 maui python3[66696]:     Icon = backend().Icon
Nov  2 16:28:32 maui python3[66696]:   File "/usr/local/lib/python3.8/dist-packages/pystray/__init__.py", line 56, in backend
Nov  2 16:28:32 maui python3[66696]:     return candidate()
Nov  2 16:28:32 maui python3[66696]:   File "/usr/local/lib/python3.8/dist-packages/pystray/__init__.py", line 36, in xorg
Nov  2 16:28:32 maui python3[66696]:     from . import _xorg as backend; return backend
Nov  2 16:28:32 maui python3[66696]:   File "/usr/local/lib/python3.8/dist-packages/pystray/_xorg.py", line 36, in <module>
Nov  2 16:28:32 maui python3[66696]:     display = Xlib.display.Display()
Nov  2 16:28:32 maui python3[66696]:   File "/usr/local/lib/python3.8/dist-packages/Xlib/display.py", line 89, in __init__
Nov  2 16:28:32 maui python3[66696]:     self.display = _BaseDisplay(display)
Nov  2 16:28:32 maui python3[66696]:   File "/usr/local/lib/python3.8/dist-packages/Xlib/display.py", line 71, in __init__
Nov  2 16:28:32 maui python3[66696]:     protocol_display.Display.__init__(self, *args, **keys)
Nov  2 16:28:32 maui python3[66696]:   File "/usr/local/lib/python3.8/dist-packages/Xlib/protocol/display.py", line 84, in __init__
Nov  2 16:28:32 maui python3[66696]:     name, protocol, host, displayno, screenno = connect.get_display(display)
Nov  2 16:28:32 maui python3[66696]:   File "/usr/local/lib/python3.8/dist-packages/Xlib/support/connect.py", line 73, in get_display
Nov  2 16:28:32 maui python3[66696]:     return mod.get_display(display)
Nov  2 16:28:32 maui python3[66696]:   File "/usr/local/lib/python3.8/dist-packages/Xlib/support/unix_connect.py", line 59, in get_display
Nov  2 16:28:32 maui python3[66696]:     raise error.DisplayNameError(display)
Nov  2 16:28:32 maui python3[66696]: Xlib.error.DisplayNameError: Bad display name ""
Nov  2 16:28:32 maui systemd[1]: emailproxy.service: Main process exited, code=exited, status=1/FAILURE
Nov  2 16:28:32 maui systemd[1]: emailproxy.service: Failed with result 'exit-code'.
Nov  2 16:28:32 maui systemd[1]: emailproxy.service: Scheduled restart job, restart counter is at 3.
Nov  2 16:28:32 maui systemd[1]: Stopped Email OAuth 2.0 Proxy.
Nov  2 16:28:32 maui systemd[1]: Started Email OAuth 2.0 Proxy.
Nov  2 16:28:32 maui python3[66700]: Unable to init server: Could not connect: Connection refused
Nov  2 16:28:32 maui python3[66700]: message repeated 3 times: [ Unable to init server: Could not connect: Connection refused]
Nov  2 16:28:32 maui python3[66700]: Traceback (most recent call last):
Nov  2 16:28:32 maui python3[66700]:   File "/usr/local/lib/emailproxy/emailproxy.py", line 64, in <module>
Nov  2 16:28:32 maui python3[66700]:     import pystray  # the menu bar/taskbar GUI
Nov  2 16:28:32 maui python3[66700]:   File "/usr/local/lib/python3.8/dist-packages/pystray/__init__.py", line 64, in <module>
Nov  2 16:28:32 maui python3[66700]:     Icon = backend().Icon
Nov  2 16:28:32 maui python3[66700]:   File "/usr/local/lib/python3.8/dist-packages/pystray/__init__.py", line 56, in backend
Nov  2 16:28:32 maui python3[66700]:     return candidate()
Nov  2 16:28:32 maui python3[66700]:   File "/usr/local/lib/python3.8/dist-packages/pystray/__init__.py", line 36, in xorg
Nov  2 16:28:32 maui python3[66700]:     from . import _xorg as backend; return backend
Nov  2 16:28:32 maui python3[66700]:   File "/usr/local/lib/python3.8/dist-packages/pystray/_xorg.py", line 36, in <module>
Nov  2 16:28:32 maui python3[66700]:     display = Xlib.display.Display()
Nov  2 16:28:32 maui python3[66700]:   File "/usr/local/lib/python3.8/dist-packages/Xlib/display.py", line 89, in __init__
Nov  2 16:28:32 maui python3[66700]:     self.display = _BaseDisplay(display)
Nov  2 16:28:32 maui python3[66700]:   File "/usr/local/lib/python3.8/dist-packages/Xlib/display.py", line 71, in __init__
Nov  2 16:28:32 maui python3[66700]:     protocol_display.Display.__init__(self, *args, **keys)
Nov  2 16:28:32 maui python3[66700]:   File "/usr/local/lib/python3.8/dist-packages/Xlib/protocol/display.py", line 84, in __init__
Nov  2 16:28:32 maui python3[66700]:     name, protocol, host, displayno, screenno = connect.get_display(display)
Nov  2 16:28:32 maui python3[66700]:   File "/usr/local/lib/python3.8/dist-packages/Xlib/support/connect.py", line 73, in get_display
Nov  2 16:28:32 maui python3[66700]:     return mod.get_display(display)
Nov  2 16:28:32 maui python3[66700]:   File "/usr/local/lib/python3.8/dist-packages/Xlib/support/unix_connect.py", line 59, in get_display
Nov  2 16:28:32 maui python3[66700]:     raise error.DisplayNameError(display)
Nov  2 16:28:32 maui python3[66700]: Xlib.error.DisplayNameError: Bad display name ""
Nov  2 16:28:32 maui systemd[1]: emailproxy.service: Main process exited, code=exited, status=1/FAILURE
Nov  2 16:28:32 maui systemd[1]: emailproxy.service: Failed with result 'exit-code'.
Nov  2 16:28:33 maui systemd[1]: emailproxy.service: Scheduled restart job, restart counter is at 4.
Nov  2 16:28:33 maui systemd[1]: Stopped Email OAuth 2.0 Proxy.
Nov  2 16:28:33 maui systemd[1]: Started Email OAuth 2.0 Proxy.
Nov  2 16:28:33 maui python3[66703]: Unable to init server: Could not connect: Connection refused
Nov  2 16:28:33 maui python3[66703]: message repeated 3 times: [ Unable to init server: Could not connect: Connection refused]
Nov  2 16:28:33 maui python3[66703]: Traceback (most recent call last):
Nov  2 16:28:33 maui python3[66703]:   File "/usr/local/lib/emailproxy/emailproxy.py", line 64, in <module>
Nov  2 16:28:33 maui python3[66703]:     import pystray  # the menu bar/taskbar GUI
Nov  2 16:28:33 maui python3[66703]:   File "/usr/local/lib/python3.8/dist-packages/pystray/__init__.py", line 64, in <module>
Nov  2 16:28:33 maui python3[66703]:     Icon = backend().Icon
Nov  2 16:28:33 maui python3[66703]:   File "/usr/local/lib/python3.8/dist-packages/pystray/__init__.py", line 56, in backend
Nov  2 16:28:33 maui python3[66703]:     return candidate()
Nov  2 16:28:33 maui python3[66703]:   File "/usr/local/lib/python3.8/dist-packages/pystray/__init__.py", line 36, in xorg
Nov  2 16:28:33 maui python3[66703]:     from . import _xorg as backend; return backend
Nov  2 16:28:33 maui python3[66703]:   File "/usr/local/lib/python3.8/dist-packages/pystray/_xorg.py", line 36, in <module>
Nov  2 16:28:33 maui python3[66703]:     display = Xlib.display.Display()
Nov  2 16:28:33 maui python3[66703]:   File "/usr/local/lib/python3.8/dist-packages/Xlib/display.py", line 89, in __init__
Nov  2 16:28:33 maui python3[66703]:     self.display = _BaseDisplay(display)
Nov  2 16:28:33 maui python3[66703]:   File "/usr/local/lib/python3.8/dist-packages/Xlib/display.py", line 71, in __init__
Nov  2 16:28:33 maui python3[66703]:     protocol_display.Display.__init__(self, *args, **keys)
Nov  2 16:28:33 maui python3[66703]:   File "/usr/local/lib/python3.8/dist-packages/Xlib/protocol/display.py", line 84, in __init__
Nov  2 16:28:33 maui python3[66703]:     name, protocol, host, displayno, screenno = connect.get_display(display)
Nov  2 16:28:33 maui python3[66703]:   File "/usr/local/lib/python3.8/dist-packages/Xlib/support/connect.py", line 73, in get_display
Nov  2 16:28:33 maui python3[66703]:     return mod.get_display(display)
Nov  2 16:28:33 maui python3[66703]:   File "/usr/local/lib/python3.8/dist-packages/Xlib/support/unix_connect.py", line 59, in get_display
Nov  2 16:28:33 maui python3[66703]:     raise error.DisplayNameError(display)
Nov  2 16:28:33 maui python3[66703]: Xlib.error.DisplayNameError: Bad display name ""
Nov  2 16:28:33 maui systemd[1]: emailproxy.service: Main process exited, code=exited, status=1/FAILURE
Nov  2 16:28:33 maui systemd[1]: emailproxy.service: Failed with result 'exit-code'.
Nov  2 16:28:33 maui systemd[1]: emailproxy.service: Scheduled restart job, restart counter is at 5.
Nov  2 16:28:33 maui systemd[1]: Stopped Email OAuth 2.0 Proxy.
Nov  2 16:28:33 maui systemd[1]: emailproxy.service: Start request repeated too quickly.
Nov  2 16:28:33 maui systemd[1]: emailproxy.service: Failed with result 'exit-code'.
Nov  2 16:28:33 maui systemd[1]: Failed to start Email OAuth 2.0 Proxy.

Reverting to my previous version works fine....

simonrob commented 10 months ago

Thanks for reporting this. Are you running in --no-gui mode?

If so, could you try editing line 65 of the 2023-11-01 version to start except Exceptionrather than except ImportError and see whether this helps?

I suspect the reason for this is that the previous approach didn't try importing GUI-mode requirements if the proxy was running in non-GUI mode. This was changed to support packaging the proxy as a python module, but didn't account for situations where you have pystray installed but it isn't set up.

w5pny commented 10 months ago

Yes -- I run in --no-gui mode...

The edit you suggested on line 65 of the 2023-11-01 version DID solve the start up error and 2023-11-01 seems to be working ok now with this edit in place.

Hope this helps...

w5pny commented 10 months ago

The syslog for starting version 2023-11-01 has "Unable to init server: Could not connect: Connection refused" repeated 3 times.

What is this about??? Is it to be expected???

The syslog follows:

Nov  3 08:22:49 maui systemd[1]: Started Email OAuth 2.0 Proxy.
Nov  3 08:22:49 maui python3[222683]: Unable to init server: Could not connect: Connection refused
Nov  3 08:22:49 maui python3[222683]: message repeated 3 times: [ Unable to init server: Could not connect: Connection refused]
Nov  3 08:22:50 maui Email OAuth 2.0 Proxy: Initialising Email OAuth 2.0 Proxy (version 2023-11-01) from config file /usr/local/lib/emailproxy/emailproxy.config
Nov  3 08:22:50 maui Email OAuth 2.0 Proxy: Starting IMAP server at [::]:1993 (unsecured) proxying outlook.office365.com:993 (SSL/TLS)
Nov  3 08:22:50 maui Email OAuth 2.0 Proxy: Starting POP server at [::]:1995 (unsecured) proxying outlook.office365.com:995 (SSL/TLS)
Nov  3 08:22:50 maui Email OAuth 2.0 Proxy: Starting SMTP server at [::]:1587 (unsecured) proxying smtp.office365.com:587 (STARTTLS)
Nov  3 08:22:50 maui Email OAuth 2.0 Proxy: Initialised Email OAuth 2.0 Proxy - listening for authentication requests. Connect your email client to begin
Nov  3 08:22:54 maui tracker-store[222616]: OK
Nov  3 08:22:54 maui systemd[3890]: tracker-store.service: Succeeded.
Nov  3 08:24:19 maui Email OAuth 2.0 Proxy: Accepting new connection from [::ffff:127.0.0.1]:38710 to POP server at [::]:1995 (unsecured) proxying outlook.office365.com:995 (SSL/TLS)
Nov  3 08:24:20 maui Email OAuth 2.0 Proxy: Rotating stored secrets for account w5pny@w5pny.com to use new cryptographic parameters
Nov  3 08:24:21 maui Email OAuth 2.0 Proxy: POP ([::]:1995; w5pny@w5pny.com) [ Successfully authenticated POP connection - releasing session ]
Nov  3 08:24:23 maui Email OAuth 2.0 Proxy: Accepting new connection from [::ffff:127.0.0.1]:38726 to POP server at [::]:1995 (unsecured) proxying outlook.office365.com:995 (SSL/TLS)
Nov  3 08:24:25 maui Email OAuth 2.0 Proxy: POP ([::]:1995; w5pny@w5pny.com) [ Successfully authenticated POP connection - releasing session ]
Nov  3 08:24:27 maui Email OAuth 2.0 Proxy: Accepting new connection from [::ffff:127.0.0.1]:54264 to POP server at [::]:1995 (unsecured) proxying outlook.office365.com:995 (SSL/TLS)
Nov  3 08:24:28 maui Email OAuth 2.0 Proxy: POP ([::]:1995; w5pny@w5pny.com) [ Successfully authenticated POP connection - releasing session ]
Nov  3 08:24:33 maui Email OAuth 2.0 Proxy: Accepting new connection from [::ffff:127.0.0.1]:54274 to POP server at [::]:1995 (unsecured) proxying outlook.office365.com:995 (SSL/TLS)
Nov  3 08:24:35 maui Email OAuth 2.0 Proxy: POP ([::]:1995; w5pny@w5pny.com) [ Successfully authenticated POP connection - releasing session ]
Nov  3 08:24:48 maui Email OAuth 2.0 Proxy: Accepting new connection from [::ffff:127.0.0.1]:42394 to POP server at [::]:1995 (unsecured) proxying outlook.office365.com:995 (SSL/TLS)
Nov  3 08:24:49 maui Email OAuth 2.0 Proxy: POP ([::]:1995; w5pny@w5pny.com) [ Successfully authenticated POP connection - releasing session ]
simonrob commented 10 months ago

Great! Glad that has resolved this.

The other syslog message may also be related - you could try changing line 64 from import pystray to pass?

If that removes the message, I can partly incorporate the old behaviour just for pystray to work around this.

w5pny commented 10 months ago

Changing "import pystray" to "pass" fixed those syslog messages!

Nov  3 10:08:19 maui systemd[1]: Started Email OAuth 2.0 Proxy.
Nov  3 10:08:19 maui Email OAuth 2.0 Proxy: Initialising Email OAuth 2.0 Proxy (version 2023-11-01) from config file /usr/local/lib/emailproxy/emailproxy.config
Nov  3 10:08:19 maui Email OAuth 2.0 Proxy: Starting IMAP server at [::]:1993 (unsecured) proxying outlook.office365.com:993 (SSL/TLS)
Nov  3 10:08:19 maui Email OAuth 2.0 Proxy: Starting POP server at [::]:1995 (unsecured) proxying outlook.office365.com:995 (SSL/TLS)
Nov  3 10:08:19 maui Email OAuth 2.0 Proxy: Starting SMTP server at [::]:1587 (unsecured) proxying smtp.office365.com:587 (STARTTLS)
Nov  3 10:08:19 maui Email OAuth 2.0 Proxy: Initialised Email OAuth 2.0 Proxy - listening for authentication requests. Connect your email client to begin
simonrob commented 10 months ago

Great - thanks for confirming. I'll make this change when I get chance. Thanks for reporting this and helping find the root cause.