diff options
-rwxr-xr-x | script/extract.py | 76 | ||||
-rw-r--r-- | src/jwebmail/__init__.py | 6 | ||||
-rw-r--r-- | src/jwebmail/model/read_mails.py | 2 | ||||
-rw-r--r-- | src/jwebmail/webmail.py | 4 |
4 files changed, 44 insertions, 44 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) diff --git a/src/jwebmail/__init__.py b/src/jwebmail/__init__.py index d692c30..ff6d17c 100644 --- a/src/jwebmail/__init__.py +++ b/src/jwebmail/__init__.py @@ -36,7 +36,7 @@ else: toml_read_file = dict(load=toml_load, text=True) -__version__ = "2.6.0.dev0" +__version__ = "2.6.0.dev1" csrf = CSRFProtect() @@ -46,9 +46,9 @@ def validate_config(app): assert "@" in conf["JWEBMAIL"]["ADMIN_MAIL"] - assert os_path.abspath(conf["JWEBMAIL"]["READ_MAILS"]["BACKEND"]) + assert os_path.isfile(conf["JWEBMAIL"]["READ_MAILS"]["BACKEND"]) - assert os_path.abspath( + assert os_path.isfile( conf["JWEBMAIL"]["READ_MAILS"].setdefault("AUTHENTICATOR", "qmail-authuser") ) diff --git a/src/jwebmail/model/read_mails.py b/src/jwebmail/model/read_mails.py index 633c358..5c63bdd 100644 --- a/src/jwebmail/model/read_mails.py +++ b/src/jwebmail/model/read_mails.py @@ -116,7 +116,7 @@ class QMailAuthuser: def add_folder(self, name): req = pb2.AddFolderReq(name=name) - resp = self.build_and_run("add_folder", req.SerializeToString()) + resp = self.build_and_run("add-folder", req.SerializeToString()) r = pb2.AddFolderResp() r.ParseFromString(resp) return r.status diff --git a/src/jwebmail/webmail.py b/src/jwebmail/webmail.py index 9c446c2..7b2e352 100644 --- a/src/jwebmail/webmail.py +++ b/src/jwebmail/webmail.py @@ -203,7 +203,7 @@ def move(folder=""): get_read_mails_logged_in().move(m, folder, to_folder) flash(gettext("succ_move")) - return redirect(url_for("displayheaders"), 303) + return redirect(url_for("displayheaders", folder=folder), 303) def remove(folder=""): @@ -224,7 +224,7 @@ def remove(folder=""): get_read_mails_logged_in().move(m, folder, "Trash") flash(gettext("succ_remove")) - return redirect(url_for("displayheaders"), 303) + return redirect(url_for("displayheaders", folder=folder), 303) def sendmail(): |