Skip to content

Commit 48086aa

Browse files
committed
Add native macOS notifications; improve SSL failure error message
Fixes #14
1 parent ea2fda1 commit 48086aa

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Please note that debug mode may also result in your login credentials being prin
5252
It is often helpful to be able to view the raw connection details when debugging (i.e., without using your email client). This can be achieved using `telnet` on macOS/Linux, or [Putty](https://www.chiark.greenend.org.uk/~sgtatham/putty/) on Windows. For example, to test the Office 365 IMAP server from the [example configuration](emailproxy.config), first open a connection using `telnet localhost 1993`, and then send a login command: `a1 login [email protected] password`, replacing `[email protected]` with your email address, and `password` with any value you like during testing (see above for why the password is irrelevant). If you have already authorised your account with the proxy you should see a response starting with `a1 OK LOGIN`; if not, this command should trigger a notification from the proxy about authorising your account.
5353

5454
### Dependencies and setup
55-
On macOS the setup and installation instructions above should automatically install all required dependencies. Any error messages you may encounter (for example, with your `pip` version and `cryptograpy`, or `pillow` and `imagingft` dependencies) normally point to clear explanations of how to resolve these issues. Please [open an issue](https://github.com/simonrob/email-oauth2-proxy/issues) if you encounter any other problems here.
55+
On macOS the setup and installation instructions above should automatically install all required dependencies. Any error messages you may encounter (for example, with your `pip` version and `cryptograpy`, or `pillow` and `imagingft` dependencies, or [macOS SSL failures](https://github.com/simonrob/email-oauth2-proxy/issues/14#issuecomment-1077379254)) normally give clear explanations of the issues and point to instructions for resolving these problems. Please [open an issue](https://github.com/simonrob/email-oauth2-proxy/issues) if you encounter any other problems here.
5656

5757
When first launching on Linux you may encounter errors similar to `Namespace […] not available`. This is caused by missing dependencies for [pystray](https://github.com/moses-palmer/pystray/) and [pywebview](https://github.com/r0x0r/pywebview/), which are used to display the menu bar icon and login windows. See the [pywebview dependencies](https://pywebview.flowrl.com/guide/installation.html#dependencies) page and [issue 1](https://github.com/simonrob/email-oauth2-proxy/issues/1#issuecomment-831746642) in this repository for a summary and suggestions about how to resolve this.
5858

@@ -68,6 +68,7 @@ Please feel free to [open an issue](https://github.com/simonrob/email-oauth2-pro
6868
## Potential improvements (pull requests welcome)
6969
- Full feature parity on different platforms (e.g., live menu updating; suspend on sleep)
7070
- Testing with different providers (currently verified only with Office 365 and Gmail)
71+
- Clickable account authorisation notifications
7172
- STARTTLS for IMAP?
7273
- POP3?
7374
- Package as .app/.exe etc?

emailproxy.py

+18-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
__author__ = 'Simon Robinson'
55
__copyright__ = 'Copyright (c) 2021 Simon Robinson'
66
__license__ = 'Apache 2.0'
7-
__version__ = '2022-03-21' # ISO 8601
7+
__version__ = '2022-03-24' # ISO 8601
88

99
import argparse
1010
import asyncore
@@ -906,6 +906,9 @@ def handle_accepted(self, connection, address):
906906
error_text = '%s encountered an SSL error - is the server\'s starttls setting correct? Current ' \
907907
'value: %s' % (self.info_string(), self.custom_configuration['starttls'])
908908
Log.info(error_text)
909+
if sys.platform == 'darwin':
910+
Log.info('If you repeatedly encounter this error, please check that you have correctly configured '
911+
'python root certificates - see: https://github.com/simonrob/email-oauth2-proxy/issues/14')
909912
connection.send(b'%s\r\n' % self.bye_message(error_text).encode('utf-8'))
910913
connection.close()
911914
else:
@@ -1471,15 +1474,25 @@ def toggle_verbose(_, item):
14711474
global VERBOSE
14721475
VERBOSE = not item.checked
14731476

1477+
# noinspection PyUnresolvedReferences
14741478
def notify(self, title, text):
14751479
if self.icon and self.icon.HAS_NOTIFICATION:
14761480
self.icon.remove_notification()
14771481
self.icon.notify('%s: %s' % (title, text))
1482+
14781483
elif sys.platform == 'darwin':
1479-
for replacement in (('\\', '\\\\'), ('"', '\\"')): # direct use of osascript requires a bit of sanitisation
1480-
text = text.replace(*replacement)
1481-
title = title.replace(*replacement)
1482-
os.system('osascript -e \'display notification "%s" with title "%s"\'' % (text, title))
1484+
user_notification = AppKit.NSUserNotification.alloc().init()
1485+
user_notification.setTitle_(title)
1486+
user_notification.setInformativeText_(text)
1487+
notification_centre = AppKit.NSUserNotificationCenter.defaultUserNotificationCenter()
1488+
try:
1489+
notification_centre.deliverNotification_(user_notification)
1490+
except Exception:
1491+
for replacement in (('\\', '\\\\'), ('"', '\\"')): # osascript approach requires a bit of sanitisation
1492+
text = text.replace(*replacement)
1493+
title = title.replace(*replacement)
1494+
os.system('osascript -e \'display notification "%s" with title "%s"\'' % (text, title))
1495+
14831496
else:
14841497
Log.info(title, text) # last resort
14851498

0 commit comments

Comments
 (0)