From df59f9dec32d7f8f08706fd3eb5b784deaa0abfc Mon Sep 17 00:00:00 2001 From: "Jannis M. Hoffmann" Date: Sun, 5 Mar 2023 19:06:55 +0100 Subject: improved performance of qmauth.py by only parsing mail headers when in list mode --- script/qmauth.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'script/qmauth.py') 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) -- cgit v1.2.3