diff --git a/prototyping/email_stuff_2.py b/prototyping/email_stuff_2.py new file mode 100644 index 0000000..15cf562 --- /dev/null +++ b/prototyping/email_stuff_2.py @@ -0,0 +1,53 @@ +# %% +import datetime +import json +import os +from pathlib import Path + +from imbox import Imbox + +cred_file = Path("../credentials.json") +with open(cred_file, "r") as f: + CREDENTIALS = json.load(f) + +for key, value in CREDENTIALS.items(): + os.environ[key] = value + +IMAP_HOST = os.environ["IMAP_HOST"] +IMAP_PORT = os.environ["IMAP_PORT"] +IMAP_USER = os.environ["IMAP_USER"] +IMAP_PASS = os.environ["IMAP_PASS"] + + +with Imbox( + hostname=os.environ["IMAP_HOST"], + port=os.environ["IMAP_PORT"], + username=os.environ["IMAP_USER"], + password=os.environ["IMAP_PASS"], + ssl=True, + ssl_context=None, + starttls=False, +) as imbox: + # Get all folders + status, folders_with_additional_info = imbox.folders() + + # Gets all messages from the inbox + all_inbox_messages = imbox.messages() + + # Messages received after specific date + inbox_messages_received_after = imbox.messages(date__gt=datetime.date(2018, 7, 30)) + + # Messages whose subjects contain a string + inbox_messages_subject_christmas = imbox.messages(subject="Christmas") + + for uid, message in all_inbox_messages: + print(uid, message.subject, message.date) + # # Every message is an object with the following keys + + # message.sent_from + # message.sent_to + # message.subject + # message.headers + # message.message_id + # message.date + # message.body.plain