summaryrefslogtreecommitdiff
path: root/script/extract.py
diff options
context:
space:
mode:
authorJannis M. Hoffmann <jannis@fehcom.de>2024-11-16 23:27:12 +0100
committerJannis M. Hoffmann <jannis@fehcom.de>2024-11-16 23:27:12 +0100
commitf123729ed492f70de3db35c042874e5750bbea72 (patch)
tree6f303cd679992c4812b6ab6dae0fb4b950b68177 /script/extract.py
parent84d7234b661a161e198206bba45cbe077c9da33e (diff)
properly implement move and remove
added add_folder method to jwebmail api
Diffstat (limited to 'script/extract.py')
-rwxr-xr-xscript/extract.py35
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())