Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IMAPClient IDLE Command Skipping Email Notifications #611

Open
AbdulrhmanSayedAli opened this issue Oct 15, 2024 · 0 comments
Open

IMAPClient IDLE Command Skipping Email Notifications #611

AbdulrhmanSayedAli opened this issue Oct 15, 2024 · 0 comments

Comments

@AbdulrhmanSayedAli
Copy link

AbdulrhmanSayedAli commented Oct 15, 2024

I am using the IMAPClient library to implement an email notifier using the IMAP IDLE command to wait for incoming email notifications. However, the IDLE command seems to be skipping some email notifications when multiple emails are sent in quick succession.

For example, when I send 3 emails in a row, the code only receives a notification for the first one. After the first notification, it seems to miss the others, even though they arrive in the inbox.

Here’s the relevant code snippet:

IDLE_TIMEOUT = 15 * 60
def email_notifier():
    with IMAPClient(host=HOST) as client:
        client.login(USERNAME, PASSWORD)
        client.select_folder(MAILBOX)

        while True:
            try:
                # Wait for up to {IDLE_TIMEOUT} seconds for an IDLE response
                client.idle()

                responses = client.idle_check(timeout=IDLE_TIMEOUT)
                if not responses:
                    print("Server sent: nothing")
                else:
                    print("Server sent:", responses)
                    new_emails_orders = []
                    for response in responses:
                        if response[1].decode() == "EXISTS":
                            new_emails_orders.append(response[0])
                    if new_emails_orders:
                        task_queue.put(new_emails_orders)
                client.idle_done()
            except KeyboardInterrupt:
                print("Shutting down.")
                break

        client.idle_done()
        print("\nIDLE mode done")
        client.logout()

What I Tried:

  • Adjusted the IDLE_TIMEOUT value to be as short as 2 seconds and as long as 15 minutes, but the issue persists.
  • When I do not renew the idle command, it works fine, but based on my research, the IDLE command will automatically close after 30 minutes of inactivity, and it doesn't handle network exceptions well.

Environment
IMAPClient version: ^3.0.1
Python version: 3.11.4
OS: Windows 11
IMAP Server: imap.gmail.com

Is there a better way to handle the IDLE command to ensure it's always active, doesn't miss any notifications, and properly handles network exceptions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant