Best/safest way to fetch raw email headers from an Inbox with Python?

Hello,

I am looking into writing a Python script that can help me grab some key variables from a raw email file such as the message_id and the names as they appear next to the emails (I am connecting to a commercial inbox such as Outlook or Gmail). Based on my research far, it looks like the IMAPclient library is a good bet and it will also allow me to use encryption. I wanted to come here and ask to get a second opinion on if there is a better or safer way of grabbing what I need from the emails without relying on any storage. I would like for the whole thing to run in a single docker container without storing anything after it passes along what I need. I would appreciate any suggestions such as alternative libraries etc.