Gnus development mailing list
 help / color / mirror / Atom feed
From: Michael Welsh Duggan <mwd@cert.org>
To: ding@gnus.org
Cc: Michael Welsh Duggan <md5i@md5i.com>
Subject: Re: searching by Message-ID after copy/move; speeding things up
Date: Fri, 15 Jun 2012 11:11:14 -0400	[thread overview]
Message-ID: <tnt62as1ugd.fsf@waterbuck.yellow.cert.org> (raw)
In-Reply-To: <87k3z8ek28.fsf@zelenka.enovance.com> (Julien Danjou's message of "Fri, 15 Jun 2012 10:17:19 -0400")

Julien Danjou <julien@danjou.info> 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)



  reply	other threads:[~2012-06-15 15:11 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-14  4:42 Michael Welsh Duggan
2012-06-14  8:10 ` Julien Danjou
2012-06-14 19:51   ` Michael Welsh Duggan
2012-06-14 19:59     ` Julien Danjou
2012-06-14 20:11       ` Michael Welsh Duggan
2012-06-15 14:17         ` Julien Danjou
2012-06-15 15:11           ` Michael Welsh Duggan [this message]
2012-06-19  8:53             ` Julien Danjou
2012-06-19 15:33               ` Michael Welsh Duggan
2012-06-25 11:23                 ` Julien Danjou
2012-06-25 14:00                   ` Michael Welsh Duggan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tnt62as1ugd.fsf@waterbuck.yellow.cert.org \
    --to=mwd@cert.org \
    --cc=ding@gnus.org \
    --cc=md5i@md5i.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).