[Twisted-Python] twisted.mail.imap4.MessageSet object & imap4 server example

Abe Fettig abe at fettig.net
Thu Jun 2 15:39:32 EDT 2005


Sebastjan Trepca wrote:
> Hi!
> 
> 1. I don't understand how to use this object. When the fetch method is
> called, this object is passed containing the requested messages which
> you then return, right? But is there any easy way to just iterate
> through it and get the requested UIDis, even if LAST is not set.

MessageSet is iterable; you can say "for uid in MessageSet: doStuff()".
You have to set MessageSet.last yourself though if it wasn't specified
by the client; set it to the value of the last uid (or sequence ID)
available.

if not messageSet.last: messageSet.last = self.getUIDNext()-1

will probably do the trick.

> 2. Where could I find some IMAP4 server examples? 

You can look at the Hep IMAP server code here:

http://svn.yarnproject.org/websvn/filedetails.php?repname=hep&path=%2Fhep%2Fservices%2Fimap.py&rev=0&sc=0

It might be a little hard to understand as it's using the Hep server and
Yarn to translate between IMAP and other protocols, but hopefully you'll
find it helpful.

Abe




More information about the Twisted-Python mailing list