;;; nnimap.el --- imap backend for Gnus
-;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
+;; 2007, 2008 Free Software Foundation, Inc.
;; Author: Simon Josefsson <jas@pdc.kth.se>
;; Jim Radford <radford@robby.caltech.edu>
;; This file is part of GNU Emacs.
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 3, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
(eval-when-compile (require 'cl))
+(autoload 'auth-source-user-or-password "auth-source")
+
(nnoo-declare nnimap)
(defconst nnimap-version "nnimap 1.0")
;; Performance / bug workaround variables
-(defcustom nnimap-enable-minmax-bug-workaround nil
- "Send UID FETCH UID commands as 1:* instead of 1,*.
-Enabling this appears to be required for some servers (e.g.,
-Exchange) which otherwise would trigger a response 'BAD The
-specified message set is invalid.'.
-Note that enabling this work around may cause significant
-performance penalties if you have large mailboxes. It makes the
-code transfer one line of data for each message in a
-mailbox (i.e., O(n)) compared to transfering only two
-lines (i.e., O(1))."
- :type 'boolean
- :group 'nnimap)
-
(defcustom nnimap-close-asynchronous t
"Close mailboxes asynchronously in `nnimap-close-group'.
This means that errors caught by nnimap when closing the mailbox will
(defcustom nnimap-id nil
"Plist with client identity to send to server upon login.
-Nil means no information is sent, symbol `no' to disable ID query
-alltogheter, or plist with identifier-value pairs to send to
+A nil value means no information is sent, symbol `no' to disable ID query
+altogether, or plist with identifier-value pairs to send to
server. RFC 2971 describes the list as follows:
Any string may be sent as a field, but the following are defined to
(imap-mailbox-select group examine))
(let (minuid maxuid)
(when (> (imap-mailbox-get 'exists) 0)
- (imap-fetch (if nnimap-enable-minmax-bug-workaround "1:*" "1,*")
+ (imap-fetch (if imap-enable-exchange-bug-workaround "1,*:*" "1,*")
"UID" nil 'nouidfetch)
(imap-message-map (lambda (uid Uid)
(setq minuid (if minuid (min minuid uid) uid)
lines (imap-body-lines (imap-message-body imap-current-message))
chars (imap-message-get imap-current-message 'RFC822.SIZE)))
(nnheader-insert-nov
- (with-temp-buffer
+ ;; At this stage, we only have bytes, so let's use unibyte buffers
+ ;; to make it more clear.
+ (mm-with-unibyte-buffer
(buffer-disable-undo)
(insert headers)
(let ((head (nnheader-parse-naked-head uid)))
(port (if nnimap-server-port
(int-to-string nnimap-server-port)
"imap"))
- (user (netrc-machine-user-or-password
- "login"
- list
- (list server
- (or nnimap-server-address
- nnimap-address))
- (list port)
- (list "imap" "imaps" "143" "993")))
- (passwd (netrc-machine-user-or-password
- "password"
- list
- (list server
- (or nnimap-server-address
- nnimap-address))
- (list port)
- (list "imap" "imaps" "143" "993"))))
+ (user (or
+ (auth-source-user-or-password "login" server port) ; this is preferred to netrc-*
+ (netrc-machine-user-or-password
+ "login"
+ list
+ (list server
+ (or nnimap-server-address
+ nnimap-address))
+ (list port)
+ (list "imap" "imaps" "143" "993"))))
+ (passwd (or
+ (auth-source-user-or-password "password" server port) ; this is preferred to netrc-*
+ (netrc-machine-user-or-password
+ "password"
+ list
+ (list server
+ (or nnimap-server-address
+ nnimap-address))
+ (list port)
+ (list "imap" "imaps" "143" "993")))))
(if (imap-authenticate user passwd nnimap-server-buffer)
(prog2
(setq nnimap-server-buffer-alist
;; request the article only when the move is NOT internal
(and (or move-is-internal
(nnimap-request-article article group server))
- (save-excursion
- (set-buffer buf)
+ (with-current-buffer buf
(buffer-disable-undo (current-buffer))
(insert-buffer-substring nntp-server-buffer)
(setq result (eval accept-form))
(deffoo nnimap-request-delete-group (group force &optional server)
(when (nnimap-possibly-change-server server)
+ (when (string= group (imap-current-mailbox nnimap-server-buffer))
+ (imap-mailbox-unselect nnimap-server-buffer))
(with-current-buffer nnimap-server-buffer
(if force
(or (null (imap-mailbox-status group 'uidvalidity))