A few days ago I stumbled upon this magic decoder ring for IMAP.
The "Ten Commandments of How to Write an IMAP client"

https://www.washington.edu/imap/documentation/commndmt.txt

The part I was most clearly missing was that for IMAP it is better to
open multiple sockets (one per mail folder on the server) than it is to
switch between folders with the same ssl socket.

The core loop of my imap code now does:

        for (;;) {
                my $more;
                do {
                        $more = fetch_mailbox($config, $tracker, $client, 
$mailbox, $validity);
                } while ($more > 0);

                my @idle_data;
                do {
                        my $max_idle = 15;
                        $client->idle() or die("idle failed!\n");
                        @idle_data = $client->idle_data($max_idle*60);
                        $client->done();
                } while (scalar(@idle_data) == 0);
        }

Where all I do with idle is wait until it gives me something, and
reissue it every 15 minutes so the connection doesn't time out.

The only filter I have found useful to add is when imap idle returns
nothing to just loop instead of trying to fetch mail.  I have not found
anything in the data idle returns that would save me work in the mailbox
fetching loop.

In my limited testing firing up a bunch of ssl sockets and fetching from
the all simultaneously appears much faster, and maybe a little more
stable.  Than switching between mailboxes.

Eric

--
unsubscribe: [email protected]
archive: https://public-inbox.org/meta/

Reply via email to