@@ -0,0 +1,889 @@
+import email%0Afrom imaplib import IMAP4_SSL%0Aimport quopri%0A%0A%0A# Called recursively.%0Adef get_email_content(message):%0A%09if not message.is_multipart():%0A%09%09return message.get_payload()%0A%0A%09parts = %5Bget_email_content(payload) for payload in message.get_payload()%5D%0A%09return ''.join(parts)%0A%0A%0Aserver = 'imap.example.com'%0Ausername = 'matt'%0Apassword = 'Password1'%0A%0Amail = IMAP4_SSL(server)%0Amail.login(username, password)%0A%0Amail.select('INBOX')%0A%0Aok, raw_uid_list = mail.uid('search', None, 'ALL')%0Aif ok != 'OK':%0A%09raise Exception('Bad')%0A%0Auid_list = raw_uid_list%5B0%5D.split()%0Auid = uid_list%5B0%5D%0A%0Aok, data = mail.uid('fetch', uid, '(RFC822)')%0Aif ok != 'OK':%0A%09raise Exception('Bad')%0A%0Araw_email_bytes = data%5B0%5D%5B1%5D%0Aemail_message = email.message_from_bytes(raw_email_bytes)%0A%0Araw_content = get_email_content(email_message)%0Acontent = quopri.decodestring(raw_content, False)%0Afor line in content.splitlines():%0A%09print(line)%0A

Add get email body using IMAP example