summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJannis M. Hoffmann <jannis@fehcom.de>2024-04-12 15:46:14 +0200
committerJannis M. Hoffmann <jannis@fehcom.de>2024-04-12 15:46:14 +0200
commitc08892e55d6ccf4b5759308835c0a4eda29c5213 (patch)
tree4af352dce74672c741ee87fecb705879eb186c94
parent8faa2973a26818561d316c9eccd136bbf086546f (diff)
fix json and raw formating for read
-rwxr-xr-xscript/extract.py6
-rwxr-xr-xscript/moveto3.py7
-rw-r--r--src/jwebmail/model/read_mails.py5
-rw-r--r--src/jwebmail/render_mail.py2
4 files changed, 10 insertions, 10 deletions
diff --git a/script/extract.py b/script/extract.py
index a54f992..3a3a17c 100755
--- a/script/extract.py
+++ b/script/extract.py
@@ -30,6 +30,7 @@ import re
from argparse import ArgumentParser
from base64 import b64encode
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
@@ -395,9 +396,10 @@ def raw_mail(f, req):
if hasattr(b, "__next__"):
raise QMAuthError("can not stop at multipart section", path=pth)
-
- if isinstance(b, str):
+ elif isinstance(b, str):
b = b.encode()
+ elif isinstance(b, EmailMessage):
+ b = b.as_bytes()
return jwebmail.RawResp(header=h, body=b).SerializeToString()
diff --git a/script/moveto3.py b/script/moveto3.py
index fba5ddd..408ff1a 100755
--- a/script/moveto3.py
+++ b/script/moveto3.py
@@ -1,7 +1,6 @@
#!/usr/bin/env python3
import argparse
import os
-import sys
def main():
@@ -9,12 +8,12 @@ def main():
ap.add_argument("-a", default="qmail-authuser", dest="pam")
ap.add_argument("fd", type=int)
ap.add_argument("prog")
- ap.add_argument("args", nargs='*')
+ ap.add_argument("args", nargs="*")
vals = ap.parse_args()
if vals.fd < 3:
- raise ValueError(f"fd({fd}) must be 3 or greater")
+ raise ValueError(f"fd({vals.fd}) must be 3 or greater")
if vals.fd != 3:
os.dup2(vals.fd, 3)
@@ -25,5 +24,5 @@ def main():
raise ValueError("should not be reachable")
-if __name__ == '__main__':
+if __name__ == "__main__":
main()
diff --git a/src/jwebmail/model/read_mails.py b/src/jwebmail/model/read_mails.py
index e35299f..769589f 100644
--- a/src/jwebmail/model/read_mails.py
+++ b/src/jwebmail/model/read_mails.py
@@ -69,7 +69,6 @@ class QMailAuthuser:
"unread_mails": r.unread_count,
}
- #
def show(self, folder, msgid):
req = pb2.ShowReq(folder=folder, mid=msgid)
resp = self.build_and_run("read", req.SerializeToString())
@@ -136,8 +135,8 @@ class QMailAuthuser:
"reply_to": [cls._address(x) for x in h.reply_to if x],
"to": [cls._address(x) for x in h.send_to if x],
"subject": h.subject,
- "comments": h.comments,
- "keywords": h.keywords,
+ "comments": list(h.comments),
+ "keywords": list(h.keywords),
"mime": cls._mime_header(h.mime),
}
diff --git a/src/jwebmail/render_mail.py b/src/jwebmail/render_mail.py
index d348721..bbac94b 100644
--- a/src/jwebmail/render_mail.py
+++ b/src/jwebmail/render_mail.py
@@ -122,7 +122,7 @@ def render_message(subtype, msg, path):
R += _format_header(gettext("CC"), msg["head"].get("cc"))
R += _format_header(gettext("BCC"), msg["head"].get("bcc"))
R += f"<dt>{escape(gettext('Date'))}</dt>"
- date = escape(msg['head']['date'])
+ date = escape(msg["head"]["date"])
R += f"<dd><time datetime='{date}' class=jwm-tolocaltime>{date}</time></dd>\n"
R += f"<dt>{escape(gettext('Content-Type'))}</dt>"
R += f"<dd>{to_mime_type(msg['head']['mime'])}</dd>\n"