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!
Sample email content:
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:
import imaplib
import libgmail
import re
import email
from BeautifulSoup import BeautifulSoup
USER = '[email protected]'
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
\r\nis a line terminator, and (if this is the encoding it appears to be) all occurrences of=XXneed to be replaced with the ASCII character with hexadecimal codepoint XX?\r\ncharacters or carriage-return-linefeeds?quopriwill decode the=XXnotation for you.