How do I only print out the message instead of the whole text
Question: This is my Python code to read an email:

    
    
    import imaplib
    
    mailserver=imaplib.IMAP4_SSL('imap.gmail.com',993)
    user = 'm****l@gmail.com'
    passs = 'm****s'
    mailserver.login(user,passs)
    
    status, count = mailserver.select('Inbox')
    status, data = mailserver.fetch(count[0],'(UID BODY[TEXT])')
    
    print(data)
    
    mailserver.close()
    mailserver.logout() 
    

It prints out the whole html portion of the message. How do I only print out
the message itself?


Answer: 
    import imaplib
    
    mailserver=imaplib.IMAP4_SSL('imap.gmail.com',993)
    user = 'm****l@gmail.com'
    passs = 'm****s'
    mailserver.login(user,passs)
    
    status, count = mailserver.select('Inbox')
    status, data = mailserver.fetch(count[0],'(RFC822)')
    
    print(data)
    
    # Something like this
    import email
    msg = email.message_from_string(data[0][1])
    print(msg['Subject'], msg['Body'])
    
    mailserver.close()
    mailserver.logout() 
    

I posted a self reminder in a gist if you are curious.

<https://gist.github.com/jmunsch/11374042>

