# HG changeset patch # User Goffi # Date 1740731015 -3600 # Node ID 6baea959dc332c3a1af24e616069dc9ee71c6633 # Parent 1bedcc6712e97566b77e7a01b1885708df067d15 component email gateway: convert `autocrypt` header: Autocrypt header must be transmitted in both directions to allow opportunistic end-to-end encryption with this protocol. Moved email validation regex to `tools/common/regex.py`, as it can be used in other locations. rel 456 diff -r 1bedcc6712e9 -r 6baea959dc33 libervia/backend/plugins/plugin_comp_email_gateway/__init__.py --- a/libervia/backend/plugins/plugin_comp_email_gateway/__init__.py Fri Feb 28 09:23:35 2025 +0100 +++ b/libervia/backend/plugins/plugin_comp_email_gateway/__init__.py Fri Feb 28 09:23:35 2025 +0100 @@ -57,7 +57,7 @@ EmailGWPubsubService, ) from libervia.backend.plugins.plugin_exp_gre import GRE, GetDataHandler -from libervia.backend.plugins.plugin_sec_gre_encrypted_openpgp import NS_GRE_OPENPGP +from libervia.backend.plugins.plugin_sec_gre_encrypter_openpgp import NS_GRE_OPENPGP from libervia.backend.plugins.plugin_sec_gre_formatter_mime import NS_GRE_MIME from libervia.backend.plugins.plugin_xep_0033 import ( AddressType, @@ -69,6 +69,7 @@ from libervia.backend.plugins.plugin_xep_0131 import HeadersData, Urgency, XEP_0131 from libervia.backend.plugins.plugin_xep_0373 import binary_to_ascii_armor from libervia.backend.plugins.plugin_xep_0498 import XEP_0498 +from libervia.backend.tools.common import regex from libervia.backend.tools.utils import aio from .imap import IMAPClientFactory @@ -105,8 +106,6 @@ PREFIX_KEY_CREDENTIALS = "CREDENTIALS_" KEY_CREDENTIALS = f"{PREFIX_KEY_CREDENTIALS}{{from_jid}}" -email_pattern = re.compile(r"[^@]+@[^@]+\.[^@]+") - class FileMetadata(NamedTuple): path: Path @@ -535,6 +534,8 @@ else: importance = urgency msg["Importance"] = importance + if getattr(extra.headers, "autocrypt", None): + msg["Autocrypt"] = extra.headers.autocrypt await smtp.sendmail( credentials["smtp_host"].encode(), @@ -722,7 +723,7 @@ if key == "user_email": # XXX: This is a minimal check. A complete email validation is notoriously # difficult. - if not email_pattern.match(value): + if not regex.RE_EMAIL.match(value): raise StanzaError( "bad-request", text=f"Invalid email address: {value}" ) @@ -907,6 +908,10 @@ else: log.warning("Ignoring invalid importance header: {importance!r}") + autocrypt = email["autocrypt"] + if autocrypt: + headers["autocrypt"] = autocrypt + if headers: extra["headers"] = HeadersData(**headers).model_dump( mode="json", exclude_none=True diff -r 1bedcc6712e9 -r 6baea959dc33 libervia/backend/tools/common/regex.py --- a/libervia/backend/tools/common/regex.py Fri Feb 28 09:23:35 2025 +0100 +++ b/libervia/backend/tools/common/regex.py Fri Feb 28 09:23:35 2025 +0100 @@ -31,6 +31,8 @@ TEXT_MAX_LEN = 60 # min lenght is currently deactivated TEXT_WORD_MIN_LENGHT = 0 +# basic email validation +RE_EMAIL = re.compile(r"[^@]+@[^@]+\.[^@]+") def re_join(exps):