diff options
Diffstat (limited to 'script')
-rwxr-xr-x | script/extract.py | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/script/extract.py b/script/extract.py index 3a3a17c..ab66869 100755 --- a/script/extract.py +++ b/script/extract.py @@ -33,7 +33,7 @@ from datetime import datetime from email.message import EmailMessage from itertools import islice from mailbox import Maildir, MaildirMessage -from os import environ, getpid, path, setuid +from os import environ, getpid, mkdir, path, setuid from pathlib import Path from pwd import getpwnam from sys import exit as sysexit @@ -448,7 +448,7 @@ def move_mail(f, req): fname = Path(f.get_filename(r.mid)) - assert r.to_f in f.list_folders() + assert r.to_f in f.list_folders() or r.to_f == "" sep = -2 if not r.from_f else -3 @@ -476,6 +476,23 @@ def remove_mail(f, req): return jwebmail.RemoveResp().SerializeToString() +def add_folder(f, req): + r = jwebmail.AddFolderReq() + r.ParseFromString(req) + + name = path.join(f._path, "." + r.name.translate(str.maketrans("/", "."))) + + if path.isdir(name): + return jwebmail.AddFolderResp(status=1).SerializeToString() + + mkdir(name) + mkdir(path.join(name, "cur")) + mkdir(path.join(name, "new")) + mkdir(path.join(name, "tmp")) + + return jwebmail.AddFolderResp(status=0).SerializeToString() + + def method_to_run(value): if value == "list": return list_mails @@ -493,6 +510,8 @@ def method_to_run(value): return remove_mail elif value == "search": return search_mails + elif value == "add_folder": + return add_folder else: raise ValueError(value) @@ -504,7 +523,17 @@ def parse_arguments(): ap.add_argument("mail_user") ap.add_argument( - "method", choices=["list", "count", "read", "raw", "folders", "move", "remove"] + "method", + choices=[ + "list", + "count", + "read", + "raw", + "folders", + "move", + "remove", + "add_folder", + ], ) return vars(ap.parse_args()) |