Access Gmail account via a local socks5 proxy and delete some emails based on specific criterion

I want to do the following job:

  1. Access my Gmail account via a local socks5 proxy running on 127.0.0.1:18888;
  2. Delete some emails based on specific criterion, say, all emails whose from/to/cc/bcc fileds are not including the Gmail account itself.

Any tips for using Python to achieve this?

Regards,
HY

The standard library contains a module to access IMAP servers, imaplib. Alternatively, Google provide a Gmail API that may be useful.

To use a SOCKS proxy, you’ll want to use a module like PySocks.