diff options
author | Jannis M. Hoffmann <jannis@fehcom.de> | 2023-03-05 19:06:55 +0100 |
---|---|---|
committer | Jannis M. Hoffmann <jannis@fehcom.de> | 2023-03-05 19:06:55 +0100 |
commit | df59f9dec32d7f8f08706fd3eb5b784deaa0abfc (patch) | |
tree | 690235284e33c4a29821c0a8fca3198291127b11 | |
parent | 44ac82d9c5f5c246dba82c401619f7d48daadfa7 (diff) |
improved performance of qmauth.py
by only parsing mail headers when in list mode
-rwxr-xr-x | script/qmauth.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/script/qmauth.py b/script/qmauth.py index 0c63c7d..38e5d58 100755 --- a/script/qmauth.py +++ b/script/qmauth.py @@ -21,13 +21,14 @@ Exit codes:: 111 reserved """ +import email.parser +import email.policy import json import logging import re from argparse import ArgumentParser from datetime import datetime -from email import message_from_binary_file, policy from functools import cache from glob import glob from mailbox import Maildir, MaildirMessage @@ -80,7 +81,7 @@ def _get_rcv_time(mid): return float(mid[:idx]) -def startup(maildir, su, user): +def startup(maildir, su, user, headers_only): del environ['PATH'] @@ -96,7 +97,7 @@ def startup(maildir, su, user): maildir / user, create=False, factory=lambda x: MaildirMessage( - message_from_binary_file(x, policy=policy.default) + email.parser.BytesParser(policy=email.policy.default).parse(x, headersonly=headers_only) ), ) @@ -339,7 +340,12 @@ if __name__ == '__main__': ) args = vars(ap.parse_args()) logging.debug("started with %s", args) - s = startup(args.pop('maildir_path'), args.pop('os_user'), args.pop('mail_user')) + s = startup( + args.pop('maildir_path'), + args.pop('os_user'), + args.pop('mail_user'), + args['run'] == list_mails, + ) logging.debug("setuid successful") run = args.pop('run') reply = run(s, **args) |