From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/81954 Path: news.gmane.org!not-for-mail From: Michael Welsh Duggan Newsgroups: gmane.emacs.gnus.general Subject: Re: searching by Message-ID after copy/move; speeding things up Date: Fri, 15 Jun 2012 11:11:14 -0400 Message-ID: References: <87395ypkri.fsf@maru.md5i.com> <877gvamhzv.fsf@zelenka.enovance.com> <87395x7jgn.fsf@zelenka.enovance.com> <87k3z8ek28.fsf@zelenka.enovance.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1339773134 23397 80.91.229.3 (15 Jun 2012 15:12:14 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 15 Jun 2012 15:12:14 +0000 (UTC) Cc: Michael Welsh Duggan To: ding@gnus.org Original-X-From: ding-owner+M30224@lists.math.uh.edu Fri Jun 15 17:12:13 2012 Return-path: Envelope-to: ding-account@gmane.org Original-Received: from util0.math.uh.edu ([129.7.128.18]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SfYC0-0007Fp-EC for ding-account@gmane.org; Fri, 15 Jun 2012 17:12:08 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.math.uh.edu) by util0.math.uh.edu with smtp (Exim 4.63) (envelope-from ) id 1SfYBP-0004EE-KR; Fri, 15 Jun 2012 10:11:31 -0500 Original-Received: from mx2.math.uh.edu ([129.7.128.33]) by util0.math.uh.edu with esmtps (TLSv1:AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1SfYBN-0004E2-Ta for ding@lists.math.uh.edu; Fri, 15 Jun 2012 10:11:29 -0500 Original-Received: from quimby.gnus.org ([80.91.231.51]) by mx2.math.uh.edu with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) (envelope-from ) id 1SfYBM-0001PQ-Am for ding@lists.math.uh.edu; Fri, 15 Jun 2012 10:11:29 -0500 Original-Received: from upton.red.cert.org ([192.88.209.60]) by quimby.gnus.org with esmtp (Exim 4.72) (envelope-from ) id 1SfYBK-0003R4-Al for ding@gnus.org; Fri, 15 Jun 2012 17:11:26 +0200 Original-Received: from bucknell.indigo.cert.org (bucknell.indigo.cert.org [10.60.10.121]) by upton.red.cert.org (8.14.4/8.14.4) with ESMTP id q5FFBERe007015; Fri, 15 Jun 2012 11:11:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cert.org; s=jthatj15xw2j; t=1339773074; bh=0ImrjpSq/dzIfekmGukPsrkUCnsArVQfHGyywr9W1q4=; h=From:To:Cc:Subject:References:Date:In-Reply-To:Message-ID: MIME-Version:Content-Type:Sender:Reply-To; b=AKnusa8gZCwuSwSZp4TL1KTaM475BZzAZa0vK7hoMnEYz9JZNsbQGoT2t9hK8cST7 sc4dMUS0iZ1d4Vw5z2V0Ss0CRtpzGePi7ShHKFEO+8A1N3kcUd1Mpp7aTmMmsMIuam 7U7U7thXMdVGKpqjl4Afc4ZFl4QOlAERi07WIWfo= Original-Received: from waterbuck.yellow.cert.org (waterbuck.yellow.cert.org [10.20.128.84]) by bucknell.indigo.cert.org (8.14.4/8.14.4/2.81) with ESMTP id q5FFBEi1032130; Fri, 15 Jun 2012 11:11:14 -0400 Original-Received: (from mwd@localhost) by waterbuck.yellow.cert.org (8.14.4/8.14.4/Submit/1.6) id q5FFBEPv029219; Fri, 15 Jun 2012 11:11:14 -0400 X-Authentication-Warning: waterbuck.yellow.cert.org: mwd set sender to mwd@cert.org using -f In-Reply-To: <87k3z8ek28.fsf@zelenka.enovance.com> (Julien Danjou's message of "Fri, 15 Jun 2012 10:17:19 -0400") User-Agent: Gnus/5.130006 (Ma Gnus v0.6) Emacs/24.1.50 (gnu/linux) X-Spam-Score: -2.0 (--) List-ID: Precedence: bulk Xref: news.gmane.org gmane.emacs.gnus.general:81954 Archived-At: Julien Danjou writes: > On Thu, Jun 14 2012, Michael Welsh Duggan wrote: > >> Honestly, I'd just do a limited search. You're already doing an >> EXAMINE, so you just need to parse the results to get the EXISTS count. >> Then a "UID SEARCH N:* HEADER Message-ID ..." where N is the exist >> count minus a small constant. >> >> If the limited search fails, just re-call the function with recent set >> to nil. > > Another try. Thanks for all your work! This works with a couple of modifications. > -(defun nnimap-find-article-by-message-id (group server message-id) > - "Search for message with MESSAGE-ID in GROUP from SERVER." > +(defun nnimap-find-article-by-message-id (group server message-id &optional limit) > + "Search for message with MESSAGE-ID in GROUP from SERVER. > +If LIMIT, first try to limit the search to the N last articles." > (with-current-buffer (nnimap-buffer) > (erase-buffer) > - (nnimap-change-group group server nil t) > - (let ((sequence > - (nnimap-send-command "UID SEARCH HEADER Message-Id %S" message-id)) > - article result) > - (setq result (nnimap-wait-for-response sequence)) > - (when (and result > - (car (setq result (nnimap-parse-response)))) > - ;; Select the last instance of the message in the group. > - (and (setq article > - (car (last (cdr (assoc "SEARCH" (cdr result)))))) > - (string-to-number article)))))) > + (let* ((number-of-article > + (catch 'found > + (dolist (result (cdr (nnimap-change-group group server nil t))) > + (when (equal "EXISTS" (cadr result)) > + (throw 'found (car result)))))) > + (sequence > + (nnimap-send-command "UID SEARCH%s HEADER Message-Id %S" > + (if limit Needs to be (if (and limit number-of-article) ...) > + (format " %s:*" (- number-of-article limit)) Needs to be (- (string-to-number number-of-article) limit -1) The need for string-to-number should be obvious. The -1 is because IMAP message numbers are one-based rather than zero-based. > + "") > + message-id))) > + (when (nnimap-wait-for-response sequence) > + (let ((article (car (last (cdr (assoc "SEARCH" (nnimap-parse-response))))))) > + (if article > + (string-to-number article) > + (when limit Probably should be (and limit number-of-article) just in case. > + (nnimap-find-article-by-message-id group server message-id)))))))) > > (defun nnimap-delete-article (articles) > (with-current-buffer (nnimap-buffer) > -- > 1.7.10 > While I was at it I modified a bunch of code in nnimap that I pushed > into master. I hope I didn't break anything, but I think it's a bit > cleaner that way. If it break something we can beat me and revert > anyway. Of course I failed to read this the first time and got confused. "What is nnimap-change-group?" It always helps to read the whole thing. :) -- Michael Welsh Duggan (mwd@cert.org)