Question

J'utilise imaplib2 ( documents ) pour interagir avec un serveur IMAP.

J'utilise la commande au ralenti, avec un délai d'attente et un rappel.

Le problème est, je ne vois aucun moyen de dire si le rappel a été déclenchée par le délai d'attente étant atteint, ou s'il y avait un changement sur le serveur que je dois vérifier.

je reçois juste chaque ('OK', ['IDLE terminated (Success)']) temps.

Voici la sortie de débogage pour les deux cas:

Timedout:

15:43.94 MainThread server IDLE started, timeout in 5.00 secs
15:48.94 imap.gmail.com handler server IDLE timedout
15:48.94 imap.gmail.com handler server IDLE finished
15:48.94 imap.gmail.com writer > DONE\r\n
15:49.17 imap.gmail.com reader < DDDM6 OK IDLE terminated (Success)\r\n
15:49.17 imap.gmail.com handler _request_pop(DDDM6, ('OK', ['IDLE terminated (Success)']))

Quelque chose est arrivé:

18:41.34 MainThread server IDLE started, timeout in 50.00 secs
19:01.35 imap.gmail.com reader < * 1 EXISTS\r\n
19:01.37 imap.gmail.com handler server IDLE finished
19:01.37 imap.gmail.com writer > DONE\r\n
19:01.59 imap.gmail.com reader < BFCN6 OK IDLE terminated (Success)\r\n
19:01.59 imap.gmail.com handler _request_pop(BFCN6, ('OK', ['IDLE terminated (Success)']))

Qu'est-ce que je manque?

La fonctionnalité tout simplement pas exister dans imaplib2?

Était-ce utile?

La solution

Piers Lauder (author of imaplib2) just answered this question on the imaplib2-devel mailing list. He said:

I think the way to test if an IDLE has timed out is to execute:

instance.response('IDLE')

which will return:

('IDLE', ['TIMEOUT'])

if the reason that the idle returned as a timeout, rather than something else (such as ('IDLE', [None])).

I agree that this should be documented, so I'll fix the imaplib2.html document

Autres conseils

You'll have to manually check for new messages each time you get this response. You can store the UIDs of messages in a list and compare new UIDs with it upon each callback. This way you can easily tell if there are new messages or a timeout.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top