Merge from emacs--devo--0
[gnus] / lisp / mail-source.el
index 65626b0..3ff8351 100644 (file)
@@ -8,10 +8,10 @@
 
 ;; 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
@@ -19,9 +19,7 @@
 ;; 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:
 
@@ -451,25 +449,7 @@ The variables bound and their default values are described by
 the `mail-source-keyword-map' variable."
   `(let* ,(mail-source-bind-1 (car type-source))
      (mail-source-set-1 ,(cadr type-source))
-     (let ((user 
-           (or
-            (auth-source-user-or-password
-             "login"
-             server          ; this is "host" in auth-sources
-             ',(car type-source))
-            (when (boundp 'user) (symbol-value 'user))))
-          (password 
-           (or
-            (auth-source-user-or-password 
-             "password"
-             server          ; this is "host" in auth-sources
-             ',(car type-source))
-            (when (boundp 'user) (symbol-value 'user)))))
-       (unless user
-        (unintern 'user))
-       (unless password
-        (unintern 'password))
-       ,@body)))
+     ,@body))
 
 (put 'mail-source-bind 'lisp-indent-function 1)
 (put 'mail-source-bind 'edebug-form-spec '(sexp body))
@@ -477,14 +457,37 @@ the `mail-source-keyword-map' variable."
 (defun mail-source-set-1 (source)
   (let* ((type (pop source))
         (defaults (cdr (assq type mail-source-keyword-map)))
-        default value keyword)
+        default value keyword user-auth pass-auth)
     (while (setq default (pop defaults))
       ;; for each default :SYMBOL, set SYMBOL to the plist value for :SYMBOL
       ;; using `mail-source-value' to evaluate the plist value
       (set (mail-source-strip-keyword (setq keyword (car default)))
-          (if (setq value (plist-get source keyword))
-              (mail-source-value value)
-            (mail-source-value (cadr default)))))))
+          ;; note the following reasons for this structure:
+          ;; 1) the auth-sources user and password override everything
+          ;; 2) it avoids macros, so it's cleaner
+          ;; 3) it falls through to the mail-sources and then default values
+          (cond 
+           ((and
+            (eq keyword :user)
+            (setq user-auth 
+                  (auth-source-user-or-password
+                   "login"
+                   ;; this is "host" in auth-sources
+                   (if (boundp 'server) (symbol-value 'server) "")
+                   type)))
+            user-auth)
+           ((and
+            (eq keyword :password)
+            (setq pass-auth 
+                  (auth-source-user-or-password
+                   "password"
+                   ;; this is "host" in auth-sources
+                   (if (boundp 'server) (symbol-value 'server) "")
+                   type)))
+            pass-auth)
+           (t (if (setq value (plist-get source keyword))
+                (mail-source-value value)
+              (mail-source-value (cadr default)))))))))
 
 (eval-and-compile
   (defun mail-source-bind-common-1 ()