I am trying to use python to collect my emails on my NAS and manage them according to my needs. I have two email accounts, one with gmail and the other with my university. I want to synchronize them in a smart way.

When I use my laptop, I can just use imaplib and the following line of code to connect both to GMail (as in the example) and to the university account: