Skip to content

Q (Query Builder)

email_profile.clients.imap.query.Q

Composable query expressions for IMAP search.

Source code in email_profile/clients/imap/query.py
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
class Q:
    """Composable query expressions for IMAP search."""

    @staticmethod
    def subject(value: str) -> _Expr:
        return _Expr(f'(SUBJECT "{_ascii(value)}")')

    @staticmethod
    def from_(value: str) -> _Expr:
        return _Expr(f'(FROM "{_ascii(value)}")')

    @staticmethod
    def to(value: str) -> _Expr:
        return _Expr(f'(TO "{_ascii(value)}")')

    @staticmethod
    def cc(value: str) -> _Expr:
        return _Expr(f'(CC "{_ascii(value)}")')

    @staticmethod
    def body(value: str) -> _Expr:
        return _Expr(f'(BODY "{_ascii(value)}")')

    @staticmethod
    def text(value: str) -> _Expr:
        return _Expr(f'(TEXT "{_ascii(value)}")')

    @staticmethod
    def since(value: date) -> _Expr:
        return _Expr(f"(SINCE {_imap_date(value)})")

    @staticmethod
    def before(value: date) -> _Expr:
        return _Expr(f"(BEFORE {_imap_date(value)})")

    @staticmethod
    def on(value: date) -> _Expr:
        return _Expr(f"(ON {_imap_date(value)})")

    @staticmethod
    def larger(n: int) -> _Expr:
        return _Expr(f"(LARGER {n})")

    @staticmethod
    def smaller(n: int) -> _Expr:
        return _Expr(f"(SMALLER {n})")

    @staticmethod
    def unseen() -> _Expr:
        return _Expr("(UNSEEN)")

    @staticmethod
    def seen() -> _Expr:
        return _Expr("(SEEN)")

    @staticmethod
    def answered() -> _Expr:
        return _Expr("(ANSWERED)")

    @staticmethod
    def flagged() -> _Expr:
        return _Expr("(FLAGGED)")

    @staticmethod
    def deleted() -> _Expr:
        return _Expr("(DELETED)")

    @staticmethod
    def undeleted() -> _Expr:
        return _Expr("(UNDELETED)")

    @staticmethod
    def all() -> _Expr:
        return _Expr("ALL")

    @staticmethod
    def uid(value: str) -> _Expr:
        return _Expr(f"UID {value}")

    @staticmethod
    def uid_set(uids: list[str]) -> _Expr:
        return _Expr(f"UID {','.join(uids)}")

    @staticmethod
    def header(name: str, value: str) -> _Expr:
        return _Expr(f'(HEADER {name} "{_ascii(value)}")')

all() staticmethod

Source code in email_profile/clients/imap/query.py
137
138
139
@staticmethod
def all() -> _Expr:
    return _Expr("ALL")

answered() staticmethod

Source code in email_profile/clients/imap/query.py
121
122
123
@staticmethod
def answered() -> _Expr:
    return _Expr("(ANSWERED)")

before(value) staticmethod

Source code in email_profile/clients/imap/query.py
97
98
99
@staticmethod
def before(value: date) -> _Expr:
    return _Expr(f"(BEFORE {_imap_date(value)})")

body(value) staticmethod

Source code in email_profile/clients/imap/query.py
85
86
87
@staticmethod
def body(value: str) -> _Expr:
    return _Expr(f'(BODY "{_ascii(value)}")')

cc(value) staticmethod

Source code in email_profile/clients/imap/query.py
81
82
83
@staticmethod
def cc(value: str) -> _Expr:
    return _Expr(f'(CC "{_ascii(value)}")')

deleted() staticmethod

Source code in email_profile/clients/imap/query.py
129
130
131
@staticmethod
def deleted() -> _Expr:
    return _Expr("(DELETED)")

flagged() staticmethod

Source code in email_profile/clients/imap/query.py
125
126
127
@staticmethod
def flagged() -> _Expr:
    return _Expr("(FLAGGED)")

from_(value) staticmethod

Source code in email_profile/clients/imap/query.py
73
74
75
@staticmethod
def from_(value: str) -> _Expr:
    return _Expr(f'(FROM "{_ascii(value)}")')

header(name, value) staticmethod

Source code in email_profile/clients/imap/query.py
149
150
151
@staticmethod
def header(name: str, value: str) -> _Expr:
    return _Expr(f'(HEADER {name} "{_ascii(value)}")')

larger(n) staticmethod

Source code in email_profile/clients/imap/query.py
105
106
107
@staticmethod
def larger(n: int) -> _Expr:
    return _Expr(f"(LARGER {n})")

on(value) staticmethod

Source code in email_profile/clients/imap/query.py
101
102
103
@staticmethod
def on(value: date) -> _Expr:
    return _Expr(f"(ON {_imap_date(value)})")

seen() staticmethod

Source code in email_profile/clients/imap/query.py
117
118
119
@staticmethod
def seen() -> _Expr:
    return _Expr("(SEEN)")

since(value) staticmethod

Source code in email_profile/clients/imap/query.py
93
94
95
@staticmethod
def since(value: date) -> _Expr:
    return _Expr(f"(SINCE {_imap_date(value)})")

smaller(n) staticmethod

Source code in email_profile/clients/imap/query.py
109
110
111
@staticmethod
def smaller(n: int) -> _Expr:
    return _Expr(f"(SMALLER {n})")

subject(value) staticmethod

Source code in email_profile/clients/imap/query.py
69
70
71
@staticmethod
def subject(value: str) -> _Expr:
    return _Expr(f'(SUBJECT "{_ascii(value)}")')

text(value) staticmethod

Source code in email_profile/clients/imap/query.py
89
90
91
@staticmethod
def text(value: str) -> _Expr:
    return _Expr(f'(TEXT "{_ascii(value)}")')

to(value) staticmethod

Source code in email_profile/clients/imap/query.py
77
78
79
@staticmethod
def to(value: str) -> _Expr:
    return _Expr(f'(TO "{_ascii(value)}")')

uid(value) staticmethod

Source code in email_profile/clients/imap/query.py
141
142
143
@staticmethod
def uid(value: str) -> _Expr:
    return _Expr(f"UID {value}")

uid_set(uids) staticmethod

Source code in email_profile/clients/imap/query.py
145
146
147
@staticmethod
def uid_set(uids: list[str]) -> _Expr:
    return _Expr(f"UID {','.join(uids)}")

undeleted() staticmethod

Source code in email_profile/clients/imap/query.py
133
134
135
@staticmethod
def undeleted() -> _Expr:
    return _Expr("(UNDELETED)")

unseen() staticmethod

Source code in email_profile/clients/imap/query.py
113
114
115
@staticmethod
def unseen() -> _Expr:
    return _Expr("(UNSEEN)")