Commit efad50e1 authored by scmalte's avatar scmalte

mails.py: first experiments with creating mails for Thunderbird

parent ed8f0e2d
import logging
import mailbox
import os
import pathlib
from .utils import logging as logutils
DEFAULT_MAIL_BODY_FILE="mail_per_cluster.txt"
DEFAULT_STUDENTS_RECEIVE_MAILS_AS_HEADER="To" # To, CC, BCC
def main(
mail_body_file=DEFAULT_MAIL_BODY_FILE,
students_receive_mails_as_header=DEFAULT_STUDENTS_RECEIVE_MAILS_AS_HEADER):
logutils.configure_level_and_format()
# draft_mbox = "D:\\Program_Data\\Thunderbird Portable\\Data\\profile\\ImapMail\\mail.ethz.ch\\Drafts"
unsent_mbox = "D:\\Program_Data\\Thunderbird Portable\\Data\\profile\\Mail\\Local Folders\\Unsent Messages"
# thunderbird_local_folder_dir = "D:\\Program_Data\\Thunderbird Portable\\Data\\profile\\Mail\\Local Folders\\"
mbox_path = pathlib.Path(unsent_mbox)
mbox_msf_path = pathlib.Path(unsent_mbox + ".msf")
logging.warn("ATTENTION: If you continue, the files\n {}\n {} will be overwritten, if they exist. Make sure that do not have any pending unsent messages!".format(mbox_path, mbox_msf_path))
if (input("Do you want to continue (enter 'yes')? ").lower() != "yes"):
logging.debug("Exiting program because user did not confirm to continue")
exit(0)
# Delete mailbox file and corresponding summary/index file
mbox_path.unlink(missing_ok=True)
mbox_msf_path.unlink(missing_ok=True)
with open(mail_body_file) as body_fh:
mail_body = body_fh.read()
mbox = mailbox.mbox(mbox_path)
mbox.lock()
try:
msg = mailbox.mboxMessage()
msg.set_unixfrom('author Sat Feb 7 01:05:34 2009')
msg['From'] = "malte@schwerhoff.de"
msg['To'] = "scmalte@inf.ethz.ch, malte.schwerhoff@inf.ethz.h"
msg['Subject'] = 'Sample message 1'
msg.set_payload('This is the body.\\nFrom (should be escaped).\nThere are 3 lines.\n')
mbox.add(msg)
mbox.flush()
msg = mailbox.mboxMessage()
msg.set_unixfrom('author')
msg['From'] = "malte@schwerhoff.de"
msg['To'] = "mun123456789@gmail.com"
msg['CC'] = "scmalte@inf.ethz.ch"
msg['BCC'] = " malte.schwerhoff@inf.ethz.h"
msg['Subject'] = 'Sample message 2'
msg.set_payload(mail_body)
mbox.add(msg)
mbox.flush()
finally:
mbox.unlock()
if __name__ == "__main__":
main()
......@@ -31,7 +31,8 @@ setup(
'mu-moss = mossutils.moss:main',
'mu-revise = mossutils.revise:main',
'mu-cluster = mossutils.cluster:main',
'mu-aggr = mossutils.aggr:main'
'mu-aggr = mossutils.aggr:main',
'mu-mails = mossutils.mails:main'
]
},
zip_safe=False)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment