diff options
Diffstat (limited to 'script/extract.py')
-rwxr-xr-x | script/extract.py | 76 |
1 files changed, 38 insertions, 38 deletions
diff --git a/script/extract.py b/script/extract.py index ab66869..c670bef 100755 --- a/script/extract.py +++ b/script/extract.py @@ -43,8 +43,9 @@ import jwebmail.model.jwebmail_pb2 as jwebmail class MyMaildir(Maildir): - def __init__(self, dirname, *args, **kwargs): + def __init__(self, dirname, parent=None, *args, **kwargs): self.__path = Path(dirname) + self.__parent = parent self.set_msgtype("MaildirMessage") super().__init__(dirname, *args, **kwargs) @@ -95,9 +96,16 @@ class MyMaildir(Maildir): """ return type(self)( path.join(self._path, "." + folder), + parent=self, create=False, ) + def list_folders(self): + if self.__parent is not None: + return self.__parent.list_folders() + else: + return super().list_folders() + def _refresh(self): """ This override of internal method _refresh that strips out 'hidden' files. @@ -171,9 +179,13 @@ def _sort_mails(f, sort): elif sort == "sender": keyfn = _sort_by_sender elif sort == "subject": - keyfn = lambda midmsg: midmsg[1]["subject"] + # fmt: off + def keyfn(midmsg): return midmsg[1]["subject"] + # fmt: on elif sort == "size": - keyfn = lambda midmsg: path.getsize(f.get_filename(midmsg[0])) + # fmt: off + def keyfn(midmsg): return path.getsize(f.get_filename(midmsg[0])) + # fmt: on elif sort == "": keyfn = by_rec_date else: @@ -494,26 +506,27 @@ def add_folder(f, req): def method_to_run(value): - if value == "list": - return list_mails - elif value == "count": - return count_mails - elif value == "read": - return read_mail - elif value == "raw": - return raw_mail - elif value == "folders": - return folders - elif value == "move": - return move_mail - elif value == "remove": - return remove_mail - elif value == "search": - return search_mails - elif value == "add_folder": - return add_folder - else: - raise ValueError(value) + match value: + case "list": + return list_mails + case "count": + return count_mails + case "read": + return read_mail + case "raw": + return raw_mail + case "folders": + return folders + case "move": + return move_mail + case "remove": + return remove_mail + case "search": + return search_mails + case "add-folder": + return add_folder + case _: + raise ValueError(value) def parse_arguments(): @@ -521,20 +534,7 @@ def parse_arguments(): ap.add_argument("maildir_path", type=Path) ap.add_argument("os_user") ap.add_argument("mail_user") - - ap.add_argument( - "method", - choices=[ - "list", - "count", - "read", - "raw", - "folders", - "move", - "remove", - "add_folder", - ], - ) + ap.add_argument("method", type=method_to_run) return vars(ap.parse_args()) @@ -557,7 +557,7 @@ def main(): stdout.write("OPEN\n") stdout.flush() val = stdin.buffer.read() - run = method_to_run(args["method"]) + run = args["method"] reply = run(s, val) logging.debug("pb method(%s) size(%d)", args["method"], len(reply)) stdout.buffer.write(reply) |