[Twisted-Python] [Request] IMAP Server Sample code
exarkun at divmod.com
exarkun at divmod.com
Wed Mar 3 18:57:20 EST 2004
On Tue, 02 Mar 2004 11:49:29 +0000, David Burton <david at zeos.org> wrote:
>Hi guys, I'm new to the list, but I've had a look through the site and
> the mailing list archives, looking for some sample code which would help
> me in setting up the basics of an IMAP server - specifically to get mail
> from a POP account (which is easy enough), store it in a database
> (again, easy enough), and set up the interface to the database messages
> (and possible other non-email goodies) using IMAP (currently not a clue).
> I've tried looking through the API and the source code, but I don't know
> what I should be returning from the likes of authenticateLogin to
> confirm (or refect logins), and what to return via listCapabilities (I'm
> currently . Any lists of which methods should generally work without
> overriding, which ones should be overridden, what needs to be returned,
> etc gratefully received.
twisted.protocols.imap4.IMAP4Server is written so that, in most cases, it need not be subclassed. The preferred way to implement a server is to implement the interfaces IMAP4Server depends on. The two required interfaces are IAccount and IMailbox, both of which are defined in twisted.protocols.imap4. There are several other optional interfaces as well. Ideally, accounts and mailboxes are hooked up to an IMAP4Server protocol instance via twisted.cred. Here is a brief example:
from twisted.cred import portal
from twisted.protocols import imap4
__implements__ = (imap4.IAccount,)
# Actually implement the interface here
# Cleanup logic goes here
__implements__ = (portal.IRealm,)
def requestAvatar(self, avatarID, mind, *interfaces):
if imap4.IAccount not in interfaces:
return imap4.IAccount, Account(avatarID), logout
p = portal.Portal(Realm())
# Contrive to have your ServerFactory's buildProtocol
# set the "portal" attribute of the IMAP4Server instance
# it creates to the `p' defined above.
For more information, refer to the cred and component howtos available on the Twisted website.
More information about the Twisted-Python