mailmonster/worker.py

30 lines
595 B
Python
Raw Normal View History

2022-02-07 13:54:57 +00:00
#!/usr/bin/env python3
import pathlib
from classes.config import Config
from classes.mission import Mission
from classes.smtp import SMTP
2022-02-07 14:02:26 +00:00
config = Config.fromFile("settings.ini")
2022-02-07 13:54:57 +00:00
2022-02-07 13:59:20 +00:00
tempdir = config.getTempDir()
2022-02-07 13:54:57 +00:00
if not tempdir.exists():
tempdir.mkdir()
2022-02-07 14:05:06 +00:00
elif not tempdir.is_dir():
2022-02-07 13:54:57 +00:00
raise ValueError(f"Temp Dir {str(tempdir)} exists and is not a directory.")
messages = []
for f in tempdir.glob("*.mmm"):
mission = Mission.fromFile(f)
messages.append(mission.to_message())
2022-02-07 13:57:00 +00:00
f.unlink()
2022-02-07 13:54:57 +00:00
smtp = SMTP.fromConfig(config)
for message in messages:
smtp.send_message(message)