Add "sent" directory

This commit is contained in:
Augusto Gunsch 2022-04-19 18:26:25 -03:00
parent 76ae322be1
commit e4f8b31115
3 changed files with 5 additions and 6 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
config.py
scheduled/
sent/
__pycache__/

View File

@ -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()

View File

@ -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)