From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS6315 166.70.0.0/16 X-Spam-Status: No, score=-3.6 required=3.0 tests=AWL,BAYES_00, RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from out03.mta.xmission.com (out03.mta.xmission.com [166.70.13.233]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id DDB1F1F4C0; Tue, 29 Oct 2019 14:40:55 +0000 (UTC) Received: from in02.mta.xmission.com ([166.70.13.52]) by out03.mta.xmission.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.87) (envelope-from ) id 1iPSg1-00083a-NU; Tue, 29 Oct 2019 08:40:53 -0600 Received: from ip68-227-160-95.om.om.cox.net ([68.227.160.95] helo=x220.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.87) (envelope-from ) id 1iPSg0-0005MZ-VA; Tue, 29 Oct 2019 08:40:53 -0600 From: ebiederm@xmission.com (Eric W. Biederman) To: Eric Wong Cc: Date: Tue, 29 Oct 2019 09:40:47 -0500 Message-ID: <87eeyvmx74.fsf@x220.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1iPSg0-0005MZ-VA;;;mid=<87eeyvmx74.fsf@x220.int.ebiederm.org>;;;hst=in02.mta.xmission.com;;;ip=68.227.160.95;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX1/5OTaN/QavBiLYfptpqw8q+D09I2VSy8A= X-SA-Exim-Connect-IP: 68.227.160.95 X-SA-Exim-Mail-From: ebiederm@xmission.com Subject: I have figured out IMAP IDLE X-SA-Exim-Version: 4.2.1 (built Thu, 05 May 2016 13:38:54 -0600) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) List-Id: 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