2022-04-19 13:43:17 -04:00
|
|
|
#!/bin/python3.9
|
|
|
|
import os, tempfile, subprocess, re, sys
|
|
|
|
from datetime import datetime, timedelta
|
2022-04-19 17:26:25 -04:00
|
|
|
from uuid import uuid4
|
2022-04-19 13:43:17 -04:00
|
|
|
|
|
|
|
os.chdir(os.path.dirname(__file__))
|
|
|
|
|
|
|
|
EDITOR = os.environ.get('EDITOR', 'vim')
|
|
|
|
|
|
|
|
os.makedirs('scheduled', exist_ok=True)
|
|
|
|
|
|
|
|
tomorrow = datetime.utcnow() + timedelta(days=1)
|
2022-04-26 10:02:39 -04:00
|
|
|
tomorrow = tomorrow.replace(microsecond=0, second=0, minute=15*int(tomorrow.minute/15))
|
2022-04-19 13:43:17 -04:00
|
|
|
initial_msg = f'To: \nSubject: \nScheduled to (UTC): {tomorrow.isoformat()}\n---- Body ----'
|
|
|
|
|
|
|
|
with tempfile.NamedTemporaryFile() as file:
|
|
|
|
file.write(bytes(initial_msg, encoding='utf-8'))
|
|
|
|
file.flush()
|
|
|
|
|
|
|
|
subprocess.call([EDITOR, file.name])
|
|
|
|
|
|
|
|
file.seek(0)
|
|
|
|
msg = file.read().decode()
|
|
|
|
|
|
|
|
|
|
|
|
to = re.findall(r'To: (.*)\n', msg)[0]
|
|
|
|
subject = re.findall(r'Subject: (.*)\n', msg)[0]
|
|
|
|
|
|
|
|
if not to or not subject:
|
|
|
|
print('ERROR: recipient or subject empty')
|
|
|
|
exit(1)
|
|
|
|
|
2022-04-19 17:26:25 -04:00
|
|
|
filename = f'scheduled/{to}:{subject.lower().replace(" ", "_")}.{uuid4().hex}.mail'
|
2022-04-19 13:43:17 -04:00
|
|
|
|
|
|
|
with open(filename, 'w') as file:
|
|
|
|
file.write(msg)
|