From 358ea2d32be88428df0c2739990a117132e98410 Mon Sep 17 00:00:00 2001 From: Mark Powers Date: Tue, 27 Oct 2020 20:11:18 -0500 Subject: Add multiple queries to email utils, add wiki from email. --- email_helper.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'email_helper.py') diff --git a/email_helper.py b/email_helper.py index 84440ea..47bee20 100644 --- a/email_helper.py +++ b/email_helper.py @@ -51,6 +51,9 @@ def get_body(msg): def get_from(msg): return msg.get("From") +def get_date(msg): + return msg.get("Date") + def get_content_type(msg): return msg.get_content_type() @@ -58,21 +61,25 @@ def set_unseen(imap, idx): imap.store(idx, '-FLAGS', '\\SEEN') def get_what(msg, what): - if what == "subject": - return get_subject(msg) - elif what == "body": - return get_body(msg) - elif what == "from": - return get_from(msg) - elif what == "content_type": - return get_content_type + ret = {} + if "subject" in what: + ret["subject"] = get_subject(msg) + if "body" in what: + ret["body"] = get_body(msg) + if "from" in what: + ret["from"] = get_from(msg) + if "content_type" in what: + ret["content_type"] = get_content_type(msg) + if "date" in what: + ret["date"] = get_date(msg) + return ret def parse(imap, index, check_what, criteria, return_what): res, msg = imap.fetch(index, "(RFC822)") for response in msg: if isinstance(response, tuple): msg = email.message_from_bytes(response[1]) - if criteria in get_what(msg, check_what): + if criteria in get_what(msg, check_what)[check_what]: return get_what(msg, return_what) def filter_unread(check_what, criteria, return_what): -- cgit v1.2.3