python imaplib reading gmail
<p>I am using imaplib to read gmail messages in my python command window.  The only problem is if that the emails come with with newlines and return carriages.  Also, the text does not seem to be formatted correct.  Instead of Amount: $36.49, it returns =2436.49. How can I go about cleaning up this text? Thanks! </p>

<p>Sample email content:</p>

<pre><code>r\nItem name: Scanner\r\nItem=23: 130585100869\r\nPurchase Date: Oct 7, 2011\r\nUnit Price: =2436.49 USD\r\nQty: 1\r\nAmount: =2436.49USD\r\nSubtotal: =2436.49 USD\r\nShipping and handling: =240.00 USD\r\nInsurance - not offered
</code></pre>

<p>Code:</p>

<pre><code>import imaplib
import libgmail
import re
import email
from BeautifulSoup import BeautifulSoup

USER = 'email@gmail.com'
PASSWORD = 'password'

#connecting to the gmail imap server
imap_server = imaplib.IMAP4_SSL('imap.gmail.com', 993)
imap_server.login(USER, PASSWORD)
imap_server.select('Inbox')

typ, response = imap_server.search(None, '(SUBJECT "payment received")')

Data = []

for i in response[0].split():
    results, data = imap_server.fetch(i, "(RFC822)")
    Data.append(data)
    break

for i in Data:
    print i
</code></pre>
