Merge pull request #2176 from pbiering/pr2171-overtake
Append domain to login before trying IMAP connection (reviewed)
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
* Improvement: catch lack of support of PERIOD in vobject <= 0.9.9
|
* Improvement: catch lack of support of PERIOD in vobject <= 0.9.9
|
||||||
* Fix: sharing: backmap of REPORT/PROPPATCH hrefs is now URL-encode-aware (edit of a shared collection failed when the principal contains '@')
|
* Fix: sharing: backmap of REPORT/PROPPATCH hrefs is now URL-encode-aware (edit of a shared collection failed when the principal contains '@')
|
||||||
* Workaround: remove trailing spaces on TZID and TZNAME appended by buggy Microsoft clients
|
* Workaround: remove trailing spaces on TZID and TZNAME appended by buggy Microsoft clients
|
||||||
|
* Extension: [auth] imap_append_domain option (optional)
|
||||||
|
|
||||||
## 3.7.5
|
## 3.7.5
|
||||||
* Add: [sharing] conversion_bday_summary_template (customize summary)
|
* Add: [sharing] conversion_bday_summary_template (customize summary)
|
||||||
|
|||||||
@@ -1389,6 +1389,14 @@ One of:
|
|||||||
|
|
||||||
Default: `tls`
|
Default: `tls`
|
||||||
|
|
||||||
|
##### imap_append_domain
|
||||||
|
|
||||||
|
_(>= 3.7.6)_
|
||||||
|
|
||||||
|
Append `@` + domain to login before trying IMAP connection
|
||||||
|
|
||||||
|
Default: (unset)
|
||||||
|
|
||||||
##### oauth2_token_endpoint
|
##### oauth2_token_endpoint
|
||||||
|
|
||||||
_(>= 3.5.0)_
|
_(>= 3.5.0)_
|
||||||
|
|||||||
4
config
4
config
@@ -161,6 +161,10 @@
|
|||||||
# Value: tls | starttls | none
|
# Value: tls | starttls | none
|
||||||
#imap_security = tls
|
#imap_security = tls
|
||||||
|
|
||||||
|
# Append '@' + domain to login before trying IMAP connection (optional)
|
||||||
|
# Value: domain.tld
|
||||||
|
#imap_append_domain =
|
||||||
|
|
||||||
# OAuth2 token endpoint URL
|
# OAuth2 token endpoint URL
|
||||||
#oauth2_token_endpoint = <URL>
|
#oauth2_token_endpoint = <URL>
|
||||||
|
|
||||||
|
|||||||
@@ -48,6 +48,11 @@ class Auth(auth.BaseAuth):
|
|||||||
logger.info("auth imap port (autoselected): %d", self._port)
|
logger.info("auth imap port (autoselected): %d", self._port)
|
||||||
else:
|
else:
|
||||||
logger.info("auth imap port: %d", self._port)
|
logger.info("auth imap port: %d", self._port)
|
||||||
|
self._append_domain = self.configuration.get("auth", "imap_append_domain")
|
||||||
|
if self._append_domain is None or len(self._append_domain) == 0:
|
||||||
|
logger.info("auth imap append domain not used")
|
||||||
|
else:
|
||||||
|
logger.info("auth imap append domain: %s", self._append_domain)
|
||||||
|
|
||||||
def _login(self, login, password) -> str:
|
def _login(self, login, password) -> str:
|
||||||
try:
|
try:
|
||||||
@@ -63,21 +68,25 @@ class Auth(auth.BaseAuth):
|
|||||||
connection = imaplib.IMAP4(host=self._host, port=self._port)
|
connection = imaplib.IMAP4(host=self._host, port=self._port)
|
||||||
if self._security == "starttls":
|
if self._security == "starttls":
|
||||||
connection.starttls(ssl.create_default_context())
|
connection.starttls(ssl.create_default_context())
|
||||||
|
if self._append_domain is None or len(self._append_domain) == 0:
|
||||||
|
imaplogin = login
|
||||||
|
else:
|
||||||
|
imaplogin = login + "@" + self._append_domain
|
||||||
try:
|
try:
|
||||||
if "AUTH=PLAIN" in connection.capabilities:
|
if "AUTH=PLAIN" in connection.capabilities:
|
||||||
logger.debug("IMAP authentication PLAIN selected for user %r via %s:%d (security: %s)", login, self._host, self._port, self._security)
|
logger.debug("IMAP authentication PLAIN selected for user %r via %s:%d (security: %s)", imaplogin, self._host, self._port, self._security)
|
||||||
connection.authenticate(
|
connection.authenticate(
|
||||||
"PLAIN",
|
"PLAIN",
|
||||||
lambda _: "{0}\x00{0}\x00{1}".format(login, password).encode(),
|
lambda _: "{0}\x00{0}\x00{1}".format(imaplogin, password).encode(),
|
||||||
)
|
)
|
||||||
elif "AUTH=LOGIN" in connection.capabilities:
|
elif "AUTH=LOGIN" in connection.capabilities:
|
||||||
logger.debug("IMAP authentication LOGIN selected for user %r via %s:%d (security: %s)", login, self._host, self._port, self._security)
|
logger.debug("IMAP authentication LOGIN selected for user %r via %s:%d (security: %s)", imaplogin, self._host, self._port, self._security)
|
||||||
connection.login(login, password)
|
connection.login(imaplogin, password)
|
||||||
else:
|
else:
|
||||||
logger.error("IMAP server is neither supporting AUTH=PLAIN or AUTH=LOGIN: %s:%d (security: %s)", self._host, self._port, self._security)
|
logger.error("IMAP server is neither supporting AUTH=PLAIN or AUTH=LOGIN: %s:%d (security: %s)", self._host, self._port, self._security)
|
||||||
return ""
|
return ""
|
||||||
except imaplib.IMAP4.error as e:
|
except imaplib.IMAP4.error as e:
|
||||||
logger.warning("IMAP authentication failed for user %r: %s", login, e, exc_info=False)
|
logger.warning("IMAP authentication failed for user %r: %s", imaplogin, e, exc_info=False)
|
||||||
return ""
|
return ""
|
||||||
connection.logout()
|
connection.logout()
|
||||||
return login
|
return login
|
||||||
|
|||||||
@@ -440,6 +440,10 @@ DEFAULT_CONFIG_SCHEMA: types.CONFIG_SCHEMA = OrderedDict([
|
|||||||
"value": "tls",
|
"value": "tls",
|
||||||
"help": "Secure the IMAP connection: *tls*|starttls|none",
|
"help": "Secure the IMAP connection: *tls*|starttls|none",
|
||||||
"type": imap_security}),
|
"type": imap_security}),
|
||||||
|
("imap_append_domain", {
|
||||||
|
"value": "",
|
||||||
|
"help": "Append '@' + domain to login before trying IMAP connection",
|
||||||
|
"type": str}),
|
||||||
("oauth2_token_endpoint", {
|
("oauth2_token_endpoint", {
|
||||||
"value": "",
|
"value": "",
|
||||||
"help": "OAuth2 token endpoint URL",
|
"help": "OAuth2 token endpoint URL",
|
||||||
|
|||||||
Reference in New Issue
Block a user