Gnus development mailing list
 help / color / mirror / Atom feed
From: Dave Love <fx@gnu.org>
To: "ding\@gnus.org" <ding@gnus.org>
Cc: Bjorn Solberg <bjorn_ding2@hekneby.org>,
	"emacs-devel@gnu.org" <emacs-devel@gnu.org>
Subject: Re: IMAP and Exchange 2007 - imap-fetch-safe
Date: Sat, 17 Jan 2009 20:58:01 +0000	[thread overview]
Message-ID: <871vv1d50m.fsf@liv.ac.uk> (raw)
In-Reply-To: <87fxjn9l7g.fsf@mocca.josefsson.org> (Simon Josefsson's message of "Tue, 13 Jan 2009 17:20:35 +0000")

[-- Attachment #1: Type: text/plain, Size: 1795 bytes --]

Simon Josefsson <simon@josefsson.org> writes:

> Maybe the problem is a condition-case within another condition-case
> work?  I recall problems related to this when run as an async process
> filter.

Yes -- signals from process filters are normally caught; I wasn't
thinking or looking closely enough at what the code does originally.  I
must have had debug-on-error set when testing, but I was sure I'd
actually tried it in fresh Emacs.

> Maybe it is possible to re-write the approach without using
> condition-case, that would likely be easier to debug anyway.

I'm not sure it would be easier, but see the comment in the patch below.
I made it before reading this, and at least the fix over my previous
code is just an extra binding.  It works for me in a fresh Emacs, and
isn't broken in Emacs 22.

> I'd prefer to avoid sending the Exchange bug-workaround approach
> ("1,*:*") to any server that does not need it.  I've seen servers that
> (internally) open up all e-mails in the folder and searches them, but
> for the 1,* approach was able to return data quickly.

Obviously that's a good reason.  Previous comments about efficiency that
I was referred to seemed to be about something different.

> This may be old
> information now, but generally I don't see why imap.el should send poor
> protocol output to all servers just because Exchange is broken.

[It does have workarounds for various other servers, not that I want to
defend Exchange in any way.  Exchange 2007 is doing horrible things like
messing with MIME parts, which I don't think the previous version did,
and I wish I could avoid it.]

Anyhow, per the comment in the patch, is there a good reason -- other
than simplicity? -- to use FETCH rather than UID like other clients?
I'm speaking mostly in ignorance of IMAP...


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 3149 bytes --]

2009-01-17  Dave Love  <fx@gnu.org>

	* imap.el (imap-fetch-safe): Bind debug-on-error.
	(imap-debug): Add imap-fetch-safe.

Index: imap.el
===================================================================
RCS file: /usr/local/cvsroot/gnus/lisp/imap.el,v
retrieving revision 7.52
diff -u -r7.52 imap.el
--- imap.el	8 Jan 2009 20:51:29 -0000	7.52
+++ imap.el	17 Jan 2009 19:33:31 -0000
@@ -1798,25 +1800,38 @@
 of the UIDS specification, and the cdr is the one which works with
 Exchange 2007 or, potentially, other buggy servers.
 See `imap-enable-exchange-bug-workaround'."
-  ;; We don't unconditionally use the alternative (valid) form, since
-  ;; this is said to be significantly inefficient.  The first time we
-  ;; get here for a given, we'll try the canonical form.  If we get
-  ;; the known error from the buggy server, set the flag
-  ;; buffer-locally (to account for connections to multiple servers),
-  ;; then re-try with the alternative UIDS spec.
+  ;; The first time we get here for a given, we'll try the canonical
+  ;; form.  If we get the known error from the buggy server, set the
+  ;; flag buffer-locally (to account for connections to multiple
+  ;; servers), then re-try with the alternative UIDS spec.  We don't
+  ;; unconditionally use the alternative form, since the
+  ;; currently-used alternatives are seriously inefficient with some
+  ;; servers (although they are valid).
+  ;;
+  ;; FIXME:  Maybe it would be cleaner to have a flag to not signal
+  ;; the error (which otherwise gives a message), and test
+  ;; `imap-failed-tags'.  Also, Other IMAP clients use other forms of
+  ;; request which work with Exchange, e.g. Claws does "UID FETCH 1:*
+  ;; (UID)" rather than "FETCH UID 1,*".  Is there a good reason not
+  ;; to do the same?
   (condition-case data
-      (imap-fetch (if imap-enable-exchange-bug-workaround
-		      (cdr uids)
-		    (car uids))
-		  props receive nouidfetch buffer)
+      ;; Binding `debug-on-error' allows us to get the error from
+      ;; `imap-parse-response' -- it's normally caught by Emacs around
+      ;; execution of a process filter.
+      (let ((debug-on-error t))
+	(imap-fetch (if imap-enable-exchange-bug-workaround
+			(cdr uids)
+		      (car uids))
+		    props receive nouidfetch buffer))
     (error
      (if (and (not imap-enable-exchange-bug-workaround)
-	      (string-match
-	       "The specified message set is invalid"
-	       (cadr data)))
+	      ;; This is the Exchange 2007 response.  It may be more
+	      ;; robust just to check for a BAD response to the
+	      ;; attempted fetch.
+	      (string-match "The specified message set is invalid"
+			    (cadr data)))
 	 (with-current-buffer (or buffer (current-buffer))
-	   (set (make-local-variable
-		 'imap-enable-exchange-bug-workaround)
+	   (set (make-local-variable 'imap-enable-exchange-bug-workaround)
 		t)
 	   (imap-fetch (cdr uids) props receive nouidfetch))
        (signal (car data) (cdr data))))))
@@ -3023,6 +3038,7 @@
 	  imap-list-to-message-set
 	  imap-fetch-asynch
 	  imap-fetch
+	  imap-fetch-safe
 	  imap-message-put
 	  imap-message-get
 	  imap-message-map

  reply	other threads:[~2009-01-17 20:58 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <87iqphil5p.fsf@liv.ac.uk>
2008-12-22 22:38 ` imap.el workaround for Exchange 2007 Reiner Steib
2008-12-23 15:41   ` Dave Love
2009-01-01 18:34     ` Reiner Steib
2009-01-02 22:20       ` Ted Zlatanov
2009-01-02 22:38         ` Reiner Steib
2009-01-09 12:00       ` Simon Josefsson
2009-01-01 18:55     ` FIXMEs in imap.el and nnimap.el (was: imap.el workaround for Exchange 2007) Reiner Steib
2009-01-02 22:19       ` FIXMEs in imap.el and nnimap.el Ted Zlatanov
2009-01-02 22:57         ` Reiner Steib
2009-01-04 23:10           ` Dave Love
2009-01-07 21:07             ` Dave Love
2009-01-08 20:42               ` Reiner Steib
2009-01-07 19:25           ` Ted Zlatanov
2009-01-08 21:04             ` Reiner Steib
2009-01-13 10:40               ` Dave Love
2009-01-13 17:00                 ` IMAP and Exchange 2007 - imap-fetch-safe (was: FIXMEs in imap.el and nnimap.el) Reiner Steib
2009-01-13 17:20                   ` IMAP and Exchange 2007 - imap-fetch-safe Simon Josefsson
2009-01-17 20:58                     ` Dave Love [this message]
2009-01-28  1:18                       ` Dave Love
2009-01-31 15:27                       ` Reiner Steib
2009-02-01 15:43                         ` Bjorn Solberg
2009-02-02 14:54                           ` Dave Goldberg
2009-02-02 19:19                             ` Reiner Steib
2009-02-03 16:21                               ` Stephen J. Turnbull
2009-02-08 18:00                               ` Dave Love
2009-02-08 18:38                                 ` Dave Goldberg
2009-02-02 19:15                           ` Reiner Steib
2009-01-13 18:28                   ` Bjorn Solberg
2009-01-13 20:18                     ` Bjorn Solberg
2009-01-17 20:59                     ` Dave Love
2009-01-04 20:08       ` FIXMEs in imap.el and nnimap.el Dave Love
2009-01-05 16:13       ` Dave Love
2009-01-05 20:35         ` Conventions (was: FIXMEs in imap.el and nnimap.el) Reiner Steib
2009-01-06 11:33           ` Conventions Tassilo Horn

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=871vv1d50m.fsf@liv.ac.uk \
    --to=fx@gnu.org \
    --cc=bjorn_ding2@hekneby.org \
    --cc=ding@gnus.org \
    --cc=emacs-devel@gnu.org \
    /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).