diff options
Diffstat (limited to 'src/jwebmail/model')
-rw-r--r-- | src/jwebmail/model/de.jmhoffmann.jwebmail.mail-storage.varlink | 35 | ||||
-rw-r--r-- | src/jwebmail/model/read_mails.py | 43 |
2 files changed, 60 insertions, 18 deletions
diff --git a/src/jwebmail/model/de.jmhoffmann.jwebmail.mail-storage.varlink b/src/jwebmail/model/de.jmhoffmann.jwebmail.mail-storage.varlink index 3be999b..850ff19 100644 --- a/src/jwebmail/model/de.jmhoffmann.jwebmail.mail-storage.varlink +++ b/src/jwebmail/model/de.jmhoffmann.jwebmail.mail-storage.varlink @@ -58,23 +58,54 @@ type MIMEPart ( body: MailBody ) +# sorting by subject is deprecated type Sort ( direction: (asc, desc), - parameter: (date, size, sender) + parameter: (date, size, sender, subject) +) + +type Bound ( + param: string, + id: string ) method Init(unix_user: string, mailbox_path: string) -> () + +# deprecated: use ListSearch instead method List(folder: string, start: int, end: int, sort: Sort) -> (mail_heads: []ListMailHeader) + method Stats(folder: string) -> (mail_count: int, unread_count: int, byte_size: int) + method Show(folder: string, mid: string) -> (mail: Mail) -method Raw(folder: string, mid: string, path: ?string) -> (header: MIMEHeader, body: string) # body is base64 encoded + +# body is base64 encoded +method Raw(folder: string, mid: string, path: ?string) -> (header: MIMEHeader, body: string) + +# deprecated: use ListSearch instead method Search(folder: string, pattern: string) -> (found: []ListMailHeader) + method Folders() -> (folders: []string) + method Move(mid: string, from_folder: string, to_folder: string) -> () + method Remove(folder: string, mid: string) -> () + method AddFolder(name: string) -> (status: (created, skiped)) +method ListSearch( + folder: string, + bound: ?Bound, + direction: (after, before), + limit: int, + sort: Sort, + search: ?string +) -> ( + mail_heads: []ListMailHeader, + first: bool, + last: bool +) + error NotInitialized() error InvalidFolder(folder: string) 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"]) + [""] |