-
Notifications
You must be signed in to change notification settings - Fork 332
Open
Labels
Description
It would be cool if the NOTIFY extension would be implemented, which allows
to watch for changes for multiple mailboxes over a single TCP connection.
It is supported by dovecot for example.
Here is an example that I hacked together in python3.7.5 (with ugly monkey patching):
import imaplib
client = imaplib.IMAP4('mydomain.com')
client.debug = 4
client.starttls()
imaplib.Commands["NOTIFY SET"] = ("AUTH",)
rv, data = client.login("myusername", "mypassword")
typ, dat = client._simple_command('NOTIFY SET', "(subscribed (FlagChange SubscriptionChange MessageNew MessageExpunge))")
print(client.readline())
This is the debug output
24:02.62 > b'MHJN1 STARTTLS'
24:02.68 < b'MHJN1 OK Begin TLS negotiation now.'
24:02.74 > b'MHJN2 CAPABILITY'
24:02.85 < b'* CAPABILITY IMAP4rev1 SASL-IR LOGIN-REFERRALS ID ENABLE IDLE LITERAL+ AUTH=PLAIN AUTH=LOGIN'
24:02.85 < b'MHJN2 OK Pre-login capabilities listed, post-login capabilities have more.'
24:02.85 > b'MHJN3 LOGIN [email protected] "xxxxxxx"'
24:04.76 < b'* CAPABILITY IMAP4rev1 SASL-IR LOGIN-REFERRALS ID ENABLE IDLE SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS THREAD=ORDEREDSUBJECT MULTIAPPEND URL-PARTIAL CATENATE UNSELECT CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH LIST-STATUS BINARY MOVE SNIPPET=FUZZY PREVIEW=FUZZY LITERAL+ NOTIFY SPECIAL-USE'
24:04.76 < b'MHJN3 OK Logged in'
24:04.76 > b'MHJN4 NOTIFY SET (subscribed (FlagChange SubscriptionChange MessageNew MessageExpunge))'
24:04.82 < b'MHJN4 OK NOTIFY completed (0.005 + 0.000 + 0.004 secs).'
b'* STATUS INBOX (UNSEEN 1)\r\n'
This would allow to write simple & efficient notification daemons.
Tachi107, fho, mattbeedle, RichardFevrier and rayhankinan