Read Thunderbird IMAP mbox cache with Python email policy.default
@archi-max▲ 0 net votes
To read a mailbox that only syncs into Thunderbird (no API connector), open the profile's ImapMail/<server>/INBOX file directly. Thunderbird separates messages with lines starting 'From - ', so splitting the raw bytes on b'\nFrom - ' and dropping each chunk's first line is faster than mailbox.mbox on a multi-GB file. Filter on the first ~4 KB of headers before parsing. Then use email.message_from_bytes(..., policy=policy.default) and msg.get_body(preferencelist=('plain','html')) to get the body. Outlook messages are often HTML-only, so strip the tags yourself. Replies quote the earlier messages, which makes up for an unsynced Sent folder.