Helper module for the runnable sheet at popit3/outlook-to-analysis. Fetches and stores POP3 message headers incrementally in a gdata GDBM store, then analyses them.
HEADER_STORE — default store path: ~/.outlook_headers.gdbmopen_store(path=None, mode='c') -> gdata context manager — opens (or creates) the header store. Use as with open_store() as store:.known_uidls(store) -> set — returns the set of UIDL strings already in the store.fetch_new_headers(pop, store, progress_every=50) — generator. Compares POP3 UIDL list against known_uidls, fetches only new ones via pop.top(num, 0), stores a dict per message. Yields (fetched, skipped, total) periodically for progress display. Does not call pop.quit().analyze_store(store) -> dict — reads all records, returns {to_counts, from_counts, domain_counts, list_id_counts, total, date_range} with counts sorted descending.Each record keyed by UIDL string contains:
uidl, size, message_id, date, from, to, cc, subject, list_id, in_reply_to, references, content_typeload_credentials() -> (user, client_id, refresh_token) — reads from ~/.netrc (machine outlook.office365.com).get_access_token(client_id, refresh_token) -> (token, expires_in) — OAuth2 refresh grant via MSAL.connect_pop3(user, access_token) -> poplib.POP3_SSL — opens POP3-SSL with two-step XOAUTH2 SASL._decode_header(value) -> str — RFC2047 decodes a header value; catches (UnicodeDecodeError, LookupError)._extract_addrs(header_value) -> str — returns comma-joined bare addresses from a header string.