mguessan / davmail

DavMail POP/IMAP/SMTP/Caldav/Carddav/LDAP Exchange and Office 365 Gateway - Synced with main subversion repository at
http://davmail.sourceforge.net
GNU General Public License v2.0
557 stars 82 forks source link

no oauth dialog #252

Open julianuu opened 1 year ago

julianuu commented 1 year ago

From what I understood, davmail should initiate an oauth authentication dialog on startup. However it doesn't.

In my config I have

davmail.oauth.tenantId=(some id that works with mutt_oauth2.py)
davmail.oauth.clientId=(some id that works with mutt_oauth2.py)
davmail.mode=O365Manual
davmail.server=true
davmail.url=https://outlook.office365.com/EWS/Exchange.asmx
davmail.oauth.redirectUri=https://login.microsoftonline.com/common/oauth2/nativeclient

The log is

2022-11-11 13:36:41,554 DEBUG [main] davmail.DavGateway  - Start DavMail in server mode
2022-11-11 13:36:41,595 INFO  [main] davmail  - DavMail Gateway 6.0.1-3390 listening on SMTP port 1025 POP port 1110 IMAP port 1143 CALDAV port 1080 LDAP port 1389
2022-11-11 13:36:41,740 DEBUG [CheckRelease] davmail.http.HttpClientAdapter  - GET http://davmail.sourceforge.net/version.txt
2022-11-11 13:36:41,843 DEBUG [CheckRelease] davmail.http.HttpClientAdapter  - Redirect http://davmail.sourceforge.net/version.txt to https://davmail.sourceforge.net/version.txt
2022-11-11 13:36:41,854 DEBUG [CheckRelease] davmail.http.DavGatewaySSLSocketFactory  - createSocket davmail.sourceforge.net 443
2022-11-11 13:36:42,884 DEBUG [CheckRelease] davmail.DavGateway  - DavMail released version: 6.0.1-3390

I use arch linux, I have the current version of davmail, downloaded directly or via AUR. My window manager does not have a tray bar. Could that be the problem?

What am I missing?

mguessan commented 1 year ago

Well you just started DavMail, you didn't initiate any connections.

You have to configure your mail client to connect through DavMail. Note that a quick test is to access the Caldav/HTTP endpoint

doronbehar commented 1 year ago

It would have been also nice if it was possible to run davmail with .server=true and still make davmail show a prompt when oath is required. In my case, my provider requires me to refresh the oauth tokens every few weeks, and I have to run davmail interactively in order to refresh these tokens when they expire.

The ideal behavior IMO is the following: When refreshing oauth token is required, davmail would run firefox ${oauth url} (or a configurable command), and spawned a small http server on localhost that would get the token by itself, and thus spare me the copy-paste.

doronbehar commented 10 months ago

I wrote a python wrapper script, that runs davmail by itself, reads the stdout and opens firefox with the oauth2 login url if needed. I even went further and used the cool tool brotab to iterate the tabs of the browser and pastes that resulting auth link into davmail. This is fully automatic, but it requires brotab installed (including the browser extension).

The script can be modified to run a different browser, and to not use brotab but something else (perhaps spawn zenity).

I thought this may be useful to some people here.

Script ```python #!/usr/bin/env python # Wrapper around this issue: https://github.com/mguessan/davmail/issues/252 import subprocess from time import sleep import atexit import re import sys def cleanup(): timeout_sec = 5 p_sec = 0 for second in range(timeout_sec): if davmail.poll() == None: sleep(1) p_sec += 1 if p_sec >= timeout_sec: davmail.terminate() print('@@@@ cleaned up davmail process!') atexit.register(cleanup) def getBrotabURL(): while True: print("@@@@ Trying out brotab once") sleep(1) brotab=subprocess.Popen( ["brotab", "list"], stdout=subprocess.PIPE ) for bline in brotab.stdout: browserURL = re.split(b'\t+', bline)[2] if re.match(b'https://login.microsoftonline.com/common/oauth2/nativeclient\?code', browserURL): return browserURL davmail = subprocess.Popen( ["davmail"], stdin=subprocess.PIPE, stdout=subprocess.PIPE ); try: linePrevious = "" for line in davmail.stdout: lineStriped = line.decode().strip() print(lineStriped) if "proceed through authentication steps" in lineStriped: subprocess.run(["firefox", linePrevious]) authURL = getBrotabURL() print("@@@@ Got auth URL from brotab: {}".format(authURL)) # Read this line (doesn't ending on \n): # `Authentication code: ` davmail.stdout.read(21) davmail.stdin.write(authURL) davmail.stdin.flush() linePrevious = lineStriped except KeyboardInterrupt: print("@@@@ Closing!") sys.exit(2) ```