Parses IMAP BODYSTRUCTURE to extract email metadata and structure.
# Source: https://github.com/akinfold/hermes-yandex-mail | License: MIT | Copyright 2026 Roman Akinfeev
# Provided via justclaw.it.com; keep this notice with the code.
"""Bounded parsing of IMAP BODYSTRUCTURE (RFC 3501, section 7.4.2)."""
from __future__ import annotations
import re
from dataclasses import dataclass
from email.message import Message
from urllib.parse import unquote
from .message import decode_header_value
#: An RFC 2231 extended value: charset, language, then percent-encoded text.
_EXTENDED_VALUE = re.compile(r"([A-Za-z0-9!#$&+^_`{}~-]+)'[A-Za-z0-9-]*'(.*)", re.DOTALL)
#: Matched in place rather than on a slice, so a large literal is not copied
#: once for every token in front of it.
_ATOM = re.compile(rb"[^\s()]+")
_LITERAL = re.compile(rb"\{([0-9]+)\}\r\n")
class
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key