tldr: Can someone show me how to properly format this Python iMAP example so it works?
from https://docs.python.org/2.4/lib/imap4-example.html
<
import imaplib
# you want to connect to a server; specify which server
server= imaplib.IMAP4_SSL('imap.googlemail.com')
# after connecting, tell the server who you are
server.login('email@gmail.com', 'password')
# this will show you a list of available folders
# possibly your Inbox is called INBOX, but check the list of mailboxes
code, mailboxen= server.list()
print mailboxen
# if it's called INBOX, then…
server.select("INBOX")
The rest of your code seems correct.