imap_append_domain: make "@" mandatory and add some failsafe checks

This commit is contained in:
Peter Bieringer
2026-07-05 12:54:57 +02:00
parent b3770c4f2d
commit 38a4715a7f
4 changed files with 7 additions and 8 deletions

View File

@@ -1393,7 +1393,7 @@ Default: `tls`
_(>= 3.7.6)_ _(>= 3.7.6)_
Append domain to login before trying IMAP connection like @domain.tld Append `@` + domain to login before trying IMAP connection
Default: (unset) Default: (unset)

4
config
View File

@@ -161,8 +161,8 @@
# Value: tls | starttls | none # Value: tls | starttls | none
#imap_security = tls #imap_security = tls
# Append domain to login before trying IMAP connection # Append '@' + domain to login before trying IMAP connection (optional)
# Value: none | @domain.tld # Value: domain.tld
#imap_append_domain = #imap_append_domain =
# OAuth2 token endpoint URL # OAuth2 token endpoint URL

View File

@@ -49,7 +49,7 @@ class Auth(auth.BaseAuth):
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") self._append_domain = self.configuration.get("auth", "imap_append_domain")
if self._append_domain == "none": if self._append_domain is None or len(self._append_domain) == 0:
logger.info("auth imap append domain not used") logger.info("auth imap append domain not used")
else: else:
logger.info("auth imap append domain: %s", self._append_domain) logger.info("auth imap append domain: %s", self._append_domain)
@@ -68,10 +68,10 @@ 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 not self._append_domain: if self._append_domain is None or len(self._append_domain) == 0:
imaplogin = login imaplogin = login
else: else:
imaplogin = login + self._append_domain 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)", imaplogin, 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)
@@ -81,7 +81,6 @@ class Auth(auth.BaseAuth):
) )
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)", imaplogin, 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)
print("using imaplogin: %r", imaplogin)
connection.login(imaplogin, 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)

View File

@@ -442,7 +442,7 @@ DEFAULT_CONFIG_SCHEMA: types.CONFIG_SCHEMA = OrderedDict([
"type": imap_security}), "type": imap_security}),
("imap_append_domain", { ("imap_append_domain", {
"value": "", "value": "",
"help": "Append domain to login before trying IMAP connection like @domain.tld", "help": "Append '@' + domain to login before trying IMAP connection",
"type": str}), "type": str}),
("oauth2_token_endpoint", { ("oauth2_token_endpoint", {
"value": "", "value": "",