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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
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
171
172
173
@staticmethod
def all() -> _Expr:
    return _Expr("ALL")

answered() staticmethod

Source code in email_profile/clients/imap/query.py
155
156
157
@staticmethod
def answered() -> _Expr:
    return _Expr("(ANSWERED)")

before(value) staticmethod

Source code in email_profile/clients/imap/query.py
131
132
133
@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
119
120
121
@staticmethod
def body(value: str) -> _Expr:
    return _Expr(f'(BODY "{_ascii(value)}")')

cc(value) staticmethod

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

deleted() staticmethod

Source code in email_profile/clients/imap/query.py
163
164
165
@staticmethod
def deleted() -> _Expr:
    return _Expr("(DELETED)")

flagged() staticmethod

Source code in email_profile/clients/imap/query.py
159
160
161
@staticmethod
def flagged() -> _Expr:
    return _Expr("(FLAGGED)")

from_(value) staticmethod

Source code in email_profile/clients/imap/query.py
107
108
109
@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
183
184
185
@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
139
140
141
@staticmethod
def larger(n: int) -> _Expr:
    return _Expr(f"(LARGER {n})")

on(value) staticmethod

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

seen() staticmethod

Source code in email_profile/clients/imap/query.py
151
152
153
@staticmethod
def seen() -> _Expr:
    return _Expr("(SEEN)")

since(value) staticmethod

Source code in email_profile/clients/imap/query.py
127
128
129
@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
143
144
145
@staticmethod
def smaller(n: int) -> _Expr:
    return _Expr(f"(SMALLER {n})")

subject(value) staticmethod

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

text(value) staticmethod

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

to(value) staticmethod

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

uid(value) staticmethod

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

uid_set(uids) staticmethod

Source code in email_profile/clients/imap/query.py
179
180
181
@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
167
168
169
@staticmethod
def undeleted() -> _Expr:
    return _Expr("(UNDELETED)")

unseen() staticmethod

Source code in email_profile/clients/imap/query.py
147
148
149
@staticmethod
def unseen() -> _Expr:
    return _Expr("(UNSEEN)")