feat(mail): add governed JMAP mailbox sync and search
Module Package Release / publish-packages (push) Successful in 12s
Module Package Release / publish-packages (push) Successful in 12s
This commit is contained in:
@@ -3,6 +3,7 @@ from __future__ import annotations
|
||||
import fnmatch
|
||||
import json
|
||||
import re
|
||||
import urllib.parse
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Any, Iterable, Mapping
|
||||
|
||||
@@ -33,7 +34,7 @@ class MailProfileError(RuntimeError):
|
||||
|
||||
MAIL_PROFILE_POLICY_SETTINGS_KEY = "mail_profile_policy"
|
||||
PROFILE_SCOPE_TYPES = {"system", "tenant", "user", "group", "campaign"}
|
||||
PROFILE_PATTERN_KEYS = ("smtp_hosts", "imap_hosts", "envelope_senders", "from_headers", "recipient_domains")
|
||||
PROFILE_PATTERN_KEYS = ("smtp_hosts", "imap_hosts", "jmap_hosts", "envelope_senders", "from_headers", "recipient_domains")
|
||||
PROFILE_SCOPE_ORDER = {"system": 0, "tenant": 1, "user": 2, "group": 2, "campaign": 3}
|
||||
MAIL_POLICY_LIMIT_KEYS = (
|
||||
"allowed_profile_ids",
|
||||
@@ -44,11 +45,13 @@ MAIL_POLICY_LIMIT_KEYS = (
|
||||
"imap_credentials.inherit",
|
||||
"whitelist.smtp_hosts",
|
||||
"whitelist.imap_hosts",
|
||||
"whitelist.jmap_hosts",
|
||||
"whitelist.envelope_senders",
|
||||
"whitelist.from_headers",
|
||||
"whitelist.recipient_domains",
|
||||
"blacklist.smtp_hosts",
|
||||
"blacklist.imap_hosts",
|
||||
"blacklist.jmap_hosts",
|
||||
"blacklist.envelope_senders",
|
||||
"blacklist.from_headers",
|
||||
"blacklist.recipient_domains",
|
||||
@@ -711,11 +714,19 @@ def _domain_from_email(value: str | None) -> str | None:
|
||||
return text.rsplit("@", 1)[1] or None
|
||||
|
||||
|
||||
def _assert_transport_values_allowed(policy: EffectiveMailProfilePolicy, smtp: SmtpConfig | dict[str, Any] | None, imap: ImapConfig | dict[str, Any] | None) -> None:
|
||||
def _assert_transport_values_allowed(
|
||||
policy: EffectiveMailProfilePolicy,
|
||||
smtp: SmtpConfig | dict[str, Any] | None,
|
||||
imap: ImapConfig | dict[str, Any] | None,
|
||||
jmap: dict[str, Any] | None = None,
|
||||
) -> None:
|
||||
smtp_host = smtp.host if isinstance(smtp, SmtpConfig) else smtp.get("host") if isinstance(smtp, dict) else None
|
||||
imap_host = imap.host if isinstance(imap, ImapConfig) else imap.get("host") if isinstance(imap, dict) else None
|
||||
jmap_url = jmap.get("session_url") if isinstance(jmap, dict) else None
|
||||
jmap_host = urllib.parse.urlsplit(str(jmap_url)).hostname if jmap_url else None
|
||||
_assert_policy_value(policy, "smtp_hosts", str(smtp_host) if smtp_host else None)
|
||||
_assert_policy_value(policy, "imap_hosts", str(imap_host) if imap_host else None)
|
||||
_assert_policy_value(policy, "jmap_hosts", str(jmap_host) if jmap_host else None)
|
||||
|
||||
|
||||
def assert_mail_policy_allows_transport(
|
||||
@@ -724,6 +735,7 @@ def assert_mail_policy_allows_transport(
|
||||
tenant_id: str,
|
||||
smtp: SmtpConfig | dict[str, Any] | None,
|
||||
imap: ImapConfig | dict[str, Any] | None = None,
|
||||
jmap: dict[str, Any] | None = None,
|
||||
campaign_id: str | None = None,
|
||||
owner_user_id: str | None = None,
|
||||
owner_group_id: str | None = None,
|
||||
@@ -735,7 +747,7 @@ def assert_mail_policy_allows_transport(
|
||||
owner_user_id=owner_user_id,
|
||||
owner_group_id=owner_group_id,
|
||||
)
|
||||
_assert_transport_values_allowed(policy, smtp, imap)
|
||||
_assert_transport_values_allowed(policy, smtp, imap, jmap)
|
||||
|
||||
|
||||
def assert_mail_policy_allows_send(
|
||||
|
||||
Reference in New Issue
Block a user