Python
  Home arrow Python arrow Page 3 - Python Email Libraries, part 1: POP3
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PYTHON

Python Email Libraries, part 1: POP3
By: Michael Swanson
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 25
    2005-05-11


    Table of Contents:
  • Python Email Libraries, part 1: POP3
  • The POP Protocol
  • Getting Message Info
  • Getting Messages from the Server

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Python Email Libraries, part 1: POP3 - Getting Message Info
    ( Page 3 of 4 )

    Once you’re connected to the server, the natural thing you’ll want to do is download a list of messages available on the server for download.  This is done using the list operation. This method returns a Python list data structure, where the first element is the server’s response, and the second element is another list of strings, each of which contains a message number and message size. An example of how you might do this follows:

     messagesInfo = server.list()[1]
     numMessages = len(messageInfo)

    One important thing to note is that the list method can alternatively take an argument that specifies a subset of messages whose information to return. How to actually do this is described in the POP RFC.

    Protocol Definition Concerns
     
    One thing to note regarding the POP3 library concerns the list operation in the first line of the above code. As you can see, it pulls the second element off of the list to work with and ignores the first. This is because almost all methods in the POP3 library return a list, and the first element of that list is almost always the server’s response to the command, usually a string of something like “OK” or “BAD” telling you whether or not the server was able to process the request.

    Throughout this article, I will generally assume that the commands we send to the server will work correctly in order to focus more on the actual workings of the POP library. However, when you work with this library in any sort of production level software, this first element of the response list is invaluable for error detection and recovery. You can check this response in the case that you get no data back from a request to find out if there really is no data, or if your request was in some way flawed. If you want to know the exact possibilities for this server response field, they are defined in RFC 1725. 



     
     
    >>> More Python Articles          >>> More By Michael Swanson
     

       

    PYTHON ARTICLES

    - Tuples and Other Python Object Types
    - The Dictionary Python Object Type
    - String and List Python Object Types
    - Introducing Python Object Types
    - Mobile Programming using PyS60: Advanced UI ...
    - Nested Functions in Python
    - Python Parameters, Functions and Arguments
    - Python Statements and Functions
    - Statements and Iterators in Python
    - Sequences and Sets in Python
    - Python Expressions and Operators
    - Dictionaries, Variables and Statements in Py...
    - Data Types in Python
    - The Python Language
    - SSH with Twisted





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek