[Twisted-Python] Need working examples of imap4 client.

Pywinder Singh pywinder at monkeydriveengine.com
Thu Jul 2 11:11:02 EDT 2009


A very belated reply...

Thanks again for the code. From there, I was able to make a tool to clone
imap mailboxes from server to server. Right now, it's a beast held together
with rubber bands, and completely ignores use of a lot of other twisted
practices and conveniences (application, connection persistance, etc...).
At some point I'll clean it up and share, but in the mean time, if anybody
has any specific questions, let me know and I'll be happy to share what I
learned.



On Fri, Jun 12, 2009 at 4:40 AM, Alex Clemesha <clemesha at gmail.com> wrote:

> Hi,
>
> I've wondered myself how to do this, so thanks Phil.
>
> I extended Phil's solution to work with Gmail, which boils
> down to using SSL and setting the correct servername and port, see here:
> http://gist.github.com/128521
>
> Pywinder, you should be able to just change the username/password
> and it will work for you (you might have to have the python ssl module
> installed - post again if that is the case and it's not working for you)
>
> How to do useful stuff with the 'mailboxes' function in the script is
> another question (which I dont know the answer to).  Maybe post
> your usage if you have a chance.
>
>
> -Alex
>
>
>
>
>
> On Thu, Jun 11, 2009 at 5:45 PM, Pywinder
> Singh<pywinder at monkeydriveengine.com> wrote:
> > Phil,
> >
> > Much obliged.
> >
> > Was able to isolate and confirm that the real issue is that login is
> hanging
> > for some reason, and causing the timeout message. I suspect SSL/TLS
> issues,
> > which at least gives me a decided place to start investigating.
> >
> > Thanks again for the code, it was sanity inducing to say the least. ;)
> >
> >
> > Phil Mayers wrote:
> >>
> >> Pywinder Singh wrote:
> >> >
> >> > Ideally, I'd love to see a snipped which is able to log into an imap
> >> > server and gets a list of mailboxes.  If the example on the site works
> >>
> >> Here you go:
> >>
> >> #!/usr/bin/python
> >>
> >> from twisted.internet import reactor, protocol, defer
> >> from twisted.mail import imap4
> >>
> >> # change these...
> >> username = '?'
> >> password = '?'
> >> servername = '?'
> >>
> >> def mailboxes(list):
> >>      for flags,sep,mbox in list:
> >>          print mbox
> >>
> >> def loggedin(res, proto):
> >>      d = proto.list('','*')
> >>      d.addCallback(mailboxes)
> >>      return d
> >>
> >> def connected(proto):
> >>      print "connected", proto
> >>      d = proto.login(username, password)
> >>      d.addCallback(loggedin, proto)
> >>      return d
> >>
> >> def failed(f):
> >>      print "failed", f
> >>      return f
> >>
> >> def done(_):
> >>      reactor.callLater(0, reactor.stop)
> >>
> >> def main():
> >>      c = protocol.ClientCreator(reactor, imap4.IMAP4Client)
> >>      d = c.connectTCP(servername, 143)
> >>      d.addCallbacks(connected, failed)
> >>      d.addBoth(done)
> >>
> >> reactor.callLater(0, main)
> >> reactor.run()
> >>
> >>
> >> This example makes use of deferred chaining i.e. returning a deferred
> >> from a callback handler, so you'll want to understand that.
> >
> >
> > _______________________________________________
> > Twisted-Python mailing list
> > Twisted-Python at twistedmatrix.com
> > http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
> >
> >
>
>
>
> --
> Alex Clemesha
> clemesha.org
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20090702/54a4510b/attachment.htm 


More information about the Twisted-Python mailing list