-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuv
More file actions
52 lines (43 loc) · 1.25 KB
/
uv
File metadata and controls
52 lines (43 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
To: arthur@naefe.eu
Subject: Plaintext Test Mail
From: noreply@example.com
Content-Type: text/plain; charset="utf-8"
This is a test email sent via mssendmail using plain text.
#!/usr/bin/env python3
import sys
import logging
from email import message_from_file
from email.policy import default
from uuid import uuid4
from dotenv import load_dotenv
from pathlib import Path
# prefer config from /etc/mssendmail
env_paths = [
Path("/etc/mssendmail/.env"),
Path(__file__).resolve().parent.parent / ".env"
]
for path in env_paths:
if path.exists():
load_dotenv(path)
break
LOG_DIR = os.getenv("LOG_DIR")
# Logging konfigurieren
log_path = LOG_DIR / "queue_writer.log"
logging.basicConfig(
filename=log_path,
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(message)s"
)
QUEUE_DIR = os.getenv("QUEUE_DIR")
QUEUE_DIR.mkdir(exist_ok=True)
def save_to_queue(msg):
msg_id = uuid4().hex
queue_file = QUEUE_DIR / f"{msg_id}.eml"
with open(queue_file, "w", encoding="utf-8") as f:
f.write(msg.as_string())
logging.info(f"Saved to queue To: {msg.get('To', '')} - {queue_file}")
def main():
msg = message_from_file(sys.stdin, policy=default)
save_to_queue(msg)
if __name__ == "__main__":
main()