From e4f8b31115117f507b396f2730d8ce11a56c5afd Mon Sep 17 00:00:00 2001 From: Augusto Gunsch Date: Tue, 19 Apr 2022 18:26:25 -0300 Subject: [PATCH] Add "sent" directory --- .gitignore | 1 + mailman.py | 3 ++- schedule.py | 7 ++----- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index b14b41a..493d4f4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ config.py scheduled/ +sent/ __pycache__/ diff --git a/mailman.py b/mailman.py index 97d6bdd..606dbcd 100755 --- a/mailman.py +++ b/mailman.py @@ -40,6 +40,7 @@ for mail in Path('scheduled').glob('*.mail'): msg['To'] = to_address smtp.send_message(msg) - mail.unlink() + os.makedirs('sent', exist_ok=True) + mail.rename(Path('sent') / mail.name) smtp.quit() diff --git a/schedule.py b/schedule.py index 5e95ca1..a6cb315 100755 --- a/schedule.py +++ b/schedule.py @@ -1,6 +1,7 @@ #!/bin/python3.9 import os, tempfile, subprocess, re, sys from datetime import datetime, timedelta +from uuid import uuid4 os.chdir(os.path.dirname(__file__)) @@ -29,11 +30,7 @@ if not to or not subject: print('ERROR: recipient or subject empty') exit(1) -filename = f'scheduled/{to}:{subject}.mail' - -if os.path.exists(filename): - print('ERROR: an email for this recipient with the same subject is already scheduled') - exit(1) +filename = f'scheduled/{to}:{subject.lower().replace(" ", "_")}.{uuid4().hex}.mail' with open(filename, 'w') as file: file.write(msg)