Search code examples
phpgmailoauth-2.0imapgmail-imap

Check thousands of gmail mailboxes from ~1 server


I'm working on a Chrome extension that interacts both with the Gmail UI as well as Gmail's IMAP implementation.

The back-end of my app needs to monitor all incoming e-mails for each user and update the DB whenever a message/sender of interest is received.

I can set up a "user initiated" poll, where I scan all new messages whenever they have my app loaded, but there are draw backs since my app is then only up-to-date when the user is in browser. I'd like to be up to date at all times...

Off-hand I've considered a simple server poll of every user, such as:

For x = 0 to All users
    Fetch ALL msg where UID > lastMessageID
        if msg.sender == something i care about
            UPDATE table...
<repeat>

And I've also thought about using IMAP IDLE such as:

For all users, establish imap idle call
    for any user whos imap idle returned
        if msg.sender == something i care about
            UPDATE table...

What I'm trying to figure out though is which is going to scale better as I'll need to monitor 5-10k accounts minimum...

Is there anything I'm missing? Is there a simpler way of doing this for a large number of accounts?

  • Note, other than scanning the messages and updating a table -- I do not need to store any of the messages.

Solution

  • To implement IDLE is a better option since it will not put a load on server too.

    In case of Polling its the responsibility of client to monitor every changes. For example if a mail is deleted from some other client(like web interface or through some mobile device) then to monitor such situations you will have to scan the entire mailboxes every single time you do a polling.

    whereas

    In case of IDLE its the responsibility of Server to let you about any changes that happens in the state of mailbox be it a mail move, read or delete operation. Also scalability should not be an issue with IDLE command.