Skip to content

F (Fetch Builder)

email_profile.clients.imap.fetch.F

Composable IMAP fetch specification.

Source code in email_profile/clients/imap/fetch.py
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
class F:
    """Composable IMAP fetch specification."""

    __slots__ = ("_spec",)

    def __init__(self, spec: str) -> None:
        self._spec = spec

    def mount(self) -> str:
        return self._spec

    def __add__(self, other: F) -> F:
        left = self._spec.strip("()")
        right = other._spec.strip("()")
        return F(f"({left} {right})")

    def __repr__(self) -> str:
        return f"F({self._spec!r})"

    @staticmethod
    def rfc822() -> F:
        return F("(RFC822)")

    @staticmethod
    def flags() -> F:
        return F("(FLAGS)")

    @staticmethod
    def all_headers() -> F:
        return F("(BODY.PEEK[HEADER])")

    @staticmethod
    def header(name: str) -> F:
        return F(f"(BODY.PEEK[HEADER.FIELDS ({name.upper()})])")

    @staticmethod
    def headers(*names: str) -> F:
        fields = " ".join(n.upper() for n in names)
        return F(f"(BODY.PEEK[HEADER.FIELDS ({fields})])")

    @staticmethod
    def body_text() -> F:
        return F("(BODY.PEEK[HEADER] BODY.PEEK[TEXT])")

    @staticmethod
    def body_peek() -> F:
        return F("(BODY.PEEK[])")

    @staticmethod
    def envelope() -> F:
        return F("(ENVELOPE)")

    @staticmethod
    def size() -> F:
        return F("(RFC822.SIZE)")

__slots__ = ('_spec',) class-attribute instance-attribute

__add__(other)

Source code in email_profile/clients/imap/fetch.py
38
39
40
41
def __add__(self, other: F) -> F:
    left = self._spec.strip("()")
    right = other._spec.strip("()")
    return F(f"({left} {right})")

__init__(spec)

Source code in email_profile/clients/imap/fetch.py
32
33
def __init__(self, spec: str) -> None:
    self._spec = spec

__repr__()

Source code in email_profile/clients/imap/fetch.py
43
44
def __repr__(self) -> str:
    return f"F({self._spec!r})"

all_headers() staticmethod

Source code in email_profile/clients/imap/fetch.py
54
55
56
@staticmethod
def all_headers() -> F:
    return F("(BODY.PEEK[HEADER])")

body_peek() staticmethod

Source code in email_profile/clients/imap/fetch.py
71
72
73
@staticmethod
def body_peek() -> F:
    return F("(BODY.PEEK[])")

body_text() staticmethod

Source code in email_profile/clients/imap/fetch.py
67
68
69
@staticmethod
def body_text() -> F:
    return F("(BODY.PEEK[HEADER] BODY.PEEK[TEXT])")

envelope() staticmethod

Source code in email_profile/clients/imap/fetch.py
75
76
77
@staticmethod
def envelope() -> F:
    return F("(ENVELOPE)")

flags() staticmethod

Source code in email_profile/clients/imap/fetch.py
50
51
52
@staticmethod
def flags() -> F:
    return F("(FLAGS)")

header(name) staticmethod

Source code in email_profile/clients/imap/fetch.py
58
59
60
@staticmethod
def header(name: str) -> F:
    return F(f"(BODY.PEEK[HEADER.FIELDS ({name.upper()})])")

headers(*names) staticmethod

Source code in email_profile/clients/imap/fetch.py
62
63
64
65
@staticmethod
def headers(*names: str) -> F:
    fields = " ".join(n.upper() for n in names)
    return F(f"(BODY.PEEK[HEADER.FIELDS ({fields})])")

mount()

Source code in email_profile/clients/imap/fetch.py
35
36
def mount(self) -> str:
    return self._spec

rfc822() staticmethod

Source code in email_profile/clients/imap/fetch.py
46
47
48
@staticmethod
def rfc822() -> F:
    return F("(RFC822)")

size() staticmethod

Source code in email_profile/clients/imap/fetch.py
79
80
81
@staticmethod
def size() -> F:
    return F("(RFC822.SIZE)")