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 config.py
scheduled/ scheduled/
sent/
__pycache__/ __pycache__/

View File

@ -40,6 +40,7 @@ for mail in Path('scheduled').glob('*.mail'):
msg['To'] = to_address msg['To'] = to_address
smtp.send_message(msg) smtp.send_message(msg)
mail.unlink() os.makedirs('sent', exist_ok=True)
mail.rename(Path('sent') / mail.name)
smtp.quit() smtp.quit()

View File

@ -1,6 +1,7 @@
#!/bin/python3.9 #!/bin/python3.9
import os, tempfile, subprocess, re, sys import os, tempfile, subprocess, re, sys
from datetime import datetime, timedelta from datetime import datetime, timedelta
from uuid import uuid4
os.chdir(os.path.dirname(__file__)) os.chdir(os.path.dirname(__file__))
@ -29,11 +30,7 @@ if not to or not subject:
print('ERROR: recipient or subject empty') print('ERROR: recipient or subject empty')
exit(1) exit(1)
filename = f'scheduled/{to}:{subject}.mail' filename = f'scheduled/{to}:{subject.lower().replace(" ", "_")}.{uuid4().hex}.mail'
if os.path.exists(filename):
print('ERROR: an email for this recipient with the same subject is already scheduled')
exit(1)
with open(filename, 'w') as file: with open(filename, 'w') as file:
file.write(msg) file.write(msg)