import os from imap_tools import MailBox # Configuration imap_server = os.getenv('IMAP_SERVER') email_account = os.getenv('EMAIL_ACCOUNT') password = os.getenv('EMAIL_PASSWORD') # Fetch all mails of a mailbox via IMAP def fetch_emails() -> list[dict]: mailbox = MailBox(imap_server) mailbox.login(email_account, password) msgs = list() for msg in mailbox.fetch(mark_seen=False): msgs.append({ "uid": msg.uid, "from": msg.from_, "to": ', '.join(msg.to), "subject": msg.subject, "text": msg.text, "date": msg.date_str }) mailbox.logout() return msgs