refactor into a handle_dovecot_request function

This commit is contained in:
holger krekel
2024-03-07 10:33:43 +01:00
parent 42e50b089f
commit 4523c09738

View File

@@ -22,9 +22,16 @@ def handle_dovecot_protocol(rfile, wfile, tokens, requests_session, config: Conf
if not msg: if not msg:
break break
res = handle_dovecot_request(msg, tokens, requests_session, config)
if res:
wfile.write(res.encode("ascii"))
wfile.flush()
def handle_dovecot_request(msg, tokens, requests_session, config: Config):
short_command = msg[0] short_command = msg[0]
if short_command == "L": if short_command == "L":
wfile.write(b"N\n") return b"N\n"
elif short_command == "S": elif short_command == "S":
# See header of # See header of
# <https://github.com/dovecot/core/blob/5e7965632395793d9355eb906b173bf28d2a10ca/src/lib-storage/mailbox-attribute.h> # <https://github.com/dovecot/core/blob/5e7965632395793d9355eb906b173bf28d2a10ca/src/lib-storage/mailbox-attribute.h>
@@ -67,9 +74,7 @@ def handle_dovecot_protocol(rfile, wfile, tokens, requests_session, config: Conf
elif short_command == "C": elif short_command == "C":
# Commit transaction. # Commit transaction.
transaction_id = msg[1:].split("\t")[0] transaction_id = msg[1:].split("\t")[0]
wfile.write(transactions.pop(transaction_id, b"N\n")) return transactions.pop(transaction_id, b"N\n")
wfile.flush()
class ThreadedUnixStreamServer(ThreadingMixIn, UnixStreamServer): class ThreadedUnixStreamServer(ThreadingMixIn, UnixStreamServer):