parsing downloaded mail via POP3

Kevin F neurogasm at gmail.com
Wed Mar 22 15:58:00 EST 2006


I have the following script:

emails = []
for msg in messagesInfo:
         msgNum = int(msg.split()[0])
         msgSize = int(msg.split()[1])
         if(msgSize < 20000):
            message = server.retr(msgNum)[1]
            Message = join(message, “\n”)
emails.append(message)


It downloads messages for me via my POP3 server, however, the message 
format (attached below) includes ridiculous amounts of data and I just 
want to return the from, subject, and body.  Any pointers on how to do this?

/// sample message downloaded

fe5.bluebottle.com (fe5 [209.144.225.81])', '\t by 
bluebottle-be1.bluebottle.com (Cyrus v2.2.8) with LMTPA;', '\t Tue, 21 
Mar 2006 23:47:22 -0600', 'X-Sieve: CMU Sieve 2.2', 'Received: from 
fe7.bluebottle.com (fe7 [209.144.225.70])', '\tby fe5.bluebottle.com 
(8.13.4/8.13.4) with ESMTP id k2M5hhkd023264', '\tfor 
<opim399fengk at bluebottle.com>; Tue, 21 Mar 2006 23:44:35 -0600', 
'Received: from smtp-relay.wharton.upenn.edu 
(smtp-relay.wharton.upenn.edu [130.91.161.218])', '\tby 
fe7.bluebottle.com (8.13.4/8.13.4) with ESMTP id k2M5hea4022775', 
'\t(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO)', 
'\tfor <opim399fengk at bluebottle.com>; Tue, 21 Mar 2006 23:43:41 -0600', 
'Received: from FAIRMOUNT.wharton.upenn.edu 
(fairmount2.wharton.Upenn.Edu [128.91.87.58])', '\tby 
smtp-relay.wharton.upenn.edu (8.13.1/8.13.1) with ESMTP id 
k2M5heQv007094', '\tfor <opim399fengk at bluebottle.com>; Wed, 22 Mar 2006 
00:43:40 -0500', 'X-DomainKeys: Sendmail DomainKeys Filter v0.3.2 
smtp-relay.wharton.upenn.edu k2M5heQv007094', 'DomainKey-Signature: 
a=rsa-sha1; s=smtp-relay; d=wharton.upenn.edu; c=nofws; q=dns;', 
'\tb=TZ7xn8PLJNMsq8iCl7eqlME0EDnCC7fKUvpKmALqe1FQ5gG/fG+V/bomQMKyblplJ', 
'\tlg6wTqPoeao6lkM4yu+Rw==', 'Received: from webmail1.wharton.upenn.edu 
([172.16.32.58]) by FAIRMOUNT.wharton.upenn.edu with Microsoft 
SMTPSVC(6.0.3790.1830);', '\t Wed, 22 Mar 2006 00:43:39 -0500', 
'Received: from [165.123.150.168] ([165.123.150.168]) by 
webmail1.wharton.upenn.edu over TLS secured channel with Microsoft 
SMTPSVC(6.0.3790.1830);', '\t Wed, 22 Mar 2006 00:43:39 -0500', 
'User-Agent: Microsoft-Entourage/11.0.0.040405', 'Date: Wed, 22 Mar 2006 
00:43:37 -0500', 'Subject: KNOCKITY-----KNOCK-----WHOS-----THERE', 
'From: Kevin Feng <fengk at wharton.upenn.edu>', 'To: 
"opim399fengk at bluebottle.com" <opim399fengk at bluebottle.com>', 
'Message-ID: <C0464E39.4E34%fengk at wharton.upenn.edu>', 'Mime-version: 
1.0', 'Content-type: text/plain;', '\tcharset="US-ASCII"', 
'Content-transfer-encoding: 7bit', 'X-OriginalArrivalTime: 22 Mar 2006 
05:43:39.0441 (UTC) FILETIME=[921A4210:01C64D73]', 'X-Virus-Scanned: 
ClamAV version 0.88, clamav-milter version 0.87 on fe7.bluebottle.com', 
'X-Virus-Status: Clean', 'Trusted-Delivery-Validation-State: Not 
validated', '', 'ANITA-----ANITA WHO----ANITA BETTER JOKE', '', ''], 2266)



More information about the Python-list mailing list