def build_content_type_by_extension() -> dict[str, str]: mapping: dict[str, str] = {} for content_type, raw_extensions in CONTENT_TYPE_EXTENSION_GROUPS: for extension in raw_extensions.split(): normalized_extension = extension.strip().lower().strip(",") if normalized_extension: mapping.setdefault(normalized_extension, content_type) return mapping CONTENT_TYPE_BY_EXTENSION = build_content_type_by_extension() ATTACHMENT_SUFFIX_PATTERN = re.compile( r"^(?P