IMAP4 and Python

Python’s IMAPv4 client library imaplib is a really light-weight wrapper over the IMAP4 protocol. As such, it isn’t that intuitive to use. The best reference I’ve found on it is a cheat-sheet over here.

Basic usage is to create a IMAP connection object, using the imaplib.IMAP4() or imaplib.IMAP4_SSL() functions. Login to the server. You then select() a mailbox and search() within it to retrieve messages. If the search was successful, it will return a tuple with the first element being “OK”, and the second element is an array with the first item being a list of matching message identifiers. Each identifier can be passed to the fetch() command.

Search queries look like '(FROM " (SUBJECT "Coolio")'. You can also use ALL, OR, and NOT operators.

3 Replies to “IMAP4 and Python”

    1. Huh. Interesting idea. There have of course been games where you mail your move/turn to a mail server, and it does the processing, but you are envisioning a game server actually hooked up to the IMAP server itself, right?

  1. Well like the game server communicates with players over IMAP, so players use whatever inbox on whatever IMAP-friendly gadget to play the game. (Obviously this suggests a turn-based, HTML-ish game!)

Leave a Reply