summaryrefslogtreecommitdiff
path: root/script/qmauth.py
diff options
context:
space:
mode:
Diffstat (limited to 'script/qmauth.py')
-rwxr-xr-xscript/qmauth.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/script/qmauth.py b/script/qmauth.py
index 3cad208..1dcc8e3 100755
--- a/script/qmauth.py
+++ b/script/qmauth.py
@@ -28,12 +28,12 @@ import logging
import re
from argparse import ArgumentParser
+from base64 import b64encode
from datetime import datetime
-from functools import cache
from glob import glob
from itertools import islice
from mailbox import Maildir, MaildirMessage
-from os import environ, getpid, path, setuid, stat
+from os import environ, getpid, path, setuid
from pathlib import Path
from pwd import getpwnam
from sys import exit as sysexit, stdout
@@ -219,7 +219,8 @@ def _get_body(mail):
ret = mail.get_content()
if ret.isascii():
return ret.decode(encoding='ascii')
- raise ValueError(f"unsupported content type in leaf part {mail.get_content_type()}")
+ else:
+ return b64encode(ret).decode(encoding='ascii')
if (mctype := mail.get_content_maintype()) == 'message':
msg = mail.get_content()
@@ -235,7 +236,7 @@ def _get_body(mail):
}
for part in mail.iter_parts():
head = _get_mime_head_info(part)
- if not head['content_disposition'] == 'attachment':
+ if head['content_disposition'] != 'attachment':
body = _get_body(part)
else:
body = None
@@ -279,11 +280,15 @@ def _descent(xx):
def raw_mail(f, subfolder, mid, path):
if subfolder:
f = f.get_folder(subfolder)
+
+ msg = f.get(mid, None)
+ if not msg:
+ raise QMAuthError("no such message", mid=mid)
pth = [int(seg) for seg in path.split('.')] if path else []
mail = {
'head': {"content_maintype": "message", "content_subtype": "rfc822"},
- 'body': f[mid],
+ 'body': msg,
}
for n in pth: