ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-Tutor
python-Tutor
RE: [Tutor] retreiving email file attachments
by Jim Haak other posts by this author
Jun 11 2002 6:30PM messages near this date
Re: [Tutor] parsing--is this right? | [Tutor] Creating an Identifier or Object Name from a String?
Jeff,

Thanks very much.  That works great.  

Jim Haak 

*-----Original Message-----
*From: Jeff Shannon [mailto:jeff@[...].com]
*Sent: Monday, June 10, 2002 5:44 PM
*To: Jim Haak
*Cc: 'tutor@python.org'
*Subject: Re: [Tutor] retreiving email file attachments
*
*
*
*
*Jim Haak wrote:
*
*>  Does anyone have an example of using poplib to read an Inbox and then
*>  passing the messages to the email package?   I am trying to 
*parse zipped
*>  attachments.  [...]
*> 
*>  Since the email module wants a file, I've tried writing all 
*the 'lines' to a
*>  file, but that doesn't seem to work.
*
*I haven't done this myself, but here's some ideas for you to research.
*
*The POP3.retr() method returns a tuple, the second member of 
*which is (iirc) a
*list of lines.  You can probably safely discard the other two items.
*
*lines = pop.retr(n)[1]
*
*You need to feed a file to the email module, but saving all of 
*this to a file
*would be pointless.  The solution is the StringIO (or better 
*yet, cStringIO),
*which will convert a string into a file-like object.
*
*import cStringIO
*fakefile = cStringIO.StringIO( '\n'.join(lines) )
*
*I use '\n'.join() to convert the list of lines into a single 
*string with newline
*separators, then feed that to StringIO to create a file-like 
*object.  This
*object is (for most purposes) no different than the object returned by
*open(filename).  You should then be able to give this StringIO 
*object to the
*email package.
*
*Hope that this helps...
*
*Jeff Shannon
*Technician/Programmer
*Credit International
*
*
*


_______________________________________________
Tutor maillist  -  Tutor@[...].org
http://mail.python.org/mailman/listinfo/tutor

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved