Changes between Version 282 and Version 283 of WikiStart


Ignore:
Timestamp:
05/24/20 08:34:23 (17 months ago)
Author:
Glyph
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • WikiStart

    v282 v283  
    227227{{{
    228228#!python
    229 from __future__ import print_function
    230 
    231229import sys
    232230
     
    235233from twisted.python import failure
    236234
    237 @defer.inlineCallbacks
    238 def main(reactor, username=b"alice", password=b"secret",
    239          strport="tls:example.com:993"):
     235
     236async def main(
     237    reactor, username="alice", password="secret", strport="tls:example.com:993"
     238):
    240239    endpoint = endpoints.clientFromString(reactor, strport)
    241240    factory = protocol.Factory.forProtocol(imap4.IMAP4Client)
    242241    try:
    243         client = yield endpoint.connect(factory)
    244         yield client.login(username, password)
    245         yield client.select('INBOX')
    246         info = yield client.fetchEnvelope(imap4.MessageSet(1))
    247         print('First message subject:', info[1]['ENVELOPE'][1])
     242        client = await endpoint.connect(factory)
     243        await client.login(username.encode("utf-8"),
     244                           password.encode("utf-8"))
     245        await client.select("INBOX")
     246        info = await client.fetchEnvelope(imap4.MessageSet(1))
     247        print("First message subject:", info[1]["ENVELOPE"][1])
    248248    except:
    249249        print("IMAP4 client interaction failed")
    250         failure.Failure().printTraceback()
    251 
    252 task.react(main, sys.argv[1:])
    253 }}}
    254 
    255 Give this a try, supplying your IMAP4 username, password, and [https://twistedmatrix.com/documents/current/core/howto/endpoints.html#auto7 client endpoint description] for your IMAP4 server.  You'll see the subject of the first message in your mailbox printed.
     250        print(failure.Failure().getTraceback())
     251
     252
     253task.react(lambda *a, **k: defer.ensureDeferred(main(*a, **k)), sys.argv[1:])
     254}}}
     255
     256Give this a try, supplying your IMAP4 username, app password ([https://support.google.com/accounts/answer/185833?hl=en generate one for gmail], [https://www.fastmail.com/help/clients/apppassword.html generate one for fastmail]), and [https://twistedmatrix.com/documents/current/core/howto/endpoints.html#auto7 client endpoint description] for your IMAP4 server.  You'll see the subject of the first message in your mailbox printed.
    256257
    257258See the TwistedMail documentation for more information.