Use email.utils.formatdate() for dates in headers

This commit is contained in:
Kumi 2022-03-30 16:14:28 +02:00
parent 4a45a9360b
commit 226fd75a55

View file

@ -1,7 +1,7 @@
import uuid import uuid
import json import json
from datetime import datetime from email.utils import formatdate
from pathlib import Path from pathlib import Path
@ -21,9 +21,9 @@ class SmtpdHandler:
try: try:
with open(Path(self.config.maildir) / f"{eid}.eml", "wb") as mailfile: with open(Path(self.config.maildir) / f"{eid}.eml", "wb") as mailfile:
mailfile.write( mailfile.write(
f"From {envelope.mail_from} {datetime.now().isoformat()}\n".encode()) f"From {envelope.mail_from} {formatdate()}\n".encode())
mailfile.write( mailfile.write(
f"Received: from {session.host_name} ({session.peer[0]}) by {server.hostname} (Kumi Systems FileMailer) id {eid}; {datetime.now().isoformat()}\n".encode()) f"Received: from {session.host_name} ({session.peer[0]}) by {server.hostname} (Kumi Systems FileMailer) id {eid}; {formatdate()}\n".encode())
mailfile.write(envelope.original_content) mailfile.write(envelope.original_content)
with open(Path(self.config.maildir) / f"{eid}.json", "w") as jsonfile: with open(Path(self.config.maildir) / f"{eid}.json", "w") as jsonfile:
data = { data = {