SunQuest
 
       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  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Actuate Whitepapers 
VeriSign Whitepapers 
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? 
PYTHON

Python Email Libraries, part 1: POP3
By: Michael Swanson
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 22
    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:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    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


       · You should run your code before pasting it into your article. It's full of errors...
       · I'm Mike Swanson, the author of this article.I'm sorry my code isn't working for...
       · it was quite helpful. some small bugs are there but its ok.
       · Hi there, I found this very useful so thanks. However there are a few errors in this...
     

       

    PYTHON ARTICLES

    - SSH with Twisted
    - Mobile Programming in Python using PyS60: UI...
    - Python: Count on It
    - Python Strings: Spinning Yarns
    - Python: More Fun with Strings
    - Python: Stringing You Along
    - Python Operators
    - Bluetooth Programming in Python: Network Pro...
    - Python Sets
    - Python Conditionals, Lists, Dictionaries, an...
    - Python: Input and Variables
    - Introduction to Python Programming
    - Mobile Programming in Python using PyS60: Ge...
    - Bluetooth Programming using Python
    - Finishing the PyMailGUI Client: User Help To...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway