diff options
Diffstat (limited to 'src/jwebmail/model/read_mails.py')
-rw-r--r-- | src/jwebmail/model/read_mails.py | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/src/jwebmail/model/read_mails.py b/src/jwebmail/model/read_mails.py index 8a19224..b2e1191 100644 --- a/src/jwebmail/model/read_mails.py +++ b/src/jwebmail/model/read_mails.py @@ -27,7 +27,7 @@ class QMailAuthuser: self._client = None self._connection = None - def read_headers_for(self, folder, start, end, sort): + def list_search(self, folder, bound, after, limit, sort, search): sort_val = dict() if sort[0] == "!": sort = sort[1:] @@ -41,17 +41,32 @@ class QMailAuthuser: case _: raise ValueError(f"invalid sort parameter {sort!r}") - req = self._connection.List(folder=folder, start=start, end=end, sort=sort_val) - return [ - { - "message_handle": lmh["mid"], - "byte_size": lmh["byte_size"], - "unread": lmh["unread"], - "date_received": lmh["rec_date"], - "head": self._mail_header(lmh["header"]), - } - for lmh in req["mail_heads"] - ] + if bound is not None: + param, mid = bound.split("_", 1) + bound = {"param": param, "id": mid} + + req = self._connection.ListSearch( + folder=folder, + bound=bound, + direction="after" if after else "before", + limit=limit, + sort=sort_val, + search=search, + ) + return ( + [ + { + "message_handle": lmh["mid"], + "byte_size": lmh["byte_size"], + "unread": lmh["unread"], + "date_received": lmh["rec_date"], + "head": self._mail_header(lmh["header"]), + } + for lmh in req["mail_heads"] + ], + req["first"], + req["last"], + ) def count(self, folder): resp = self._connection.Stats(folder=folder) @@ -75,10 +90,6 @@ class QMailAuthuser: "body": b64decode(resp["body"]), } - def search(self, pattern, folder): - resp = self._connection.Search(folder=folder, pattern=pattern) - return resp - def folders(self): resp = self._connection.Folders() return list(resp["folders"]) + [""] |