unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* make smtpmail.el use the new netrc.el file
@ 2002-04-24 19:28 Simon Josefsson
  2002-05-07 19:45 ` Fidel Salas
  0 siblings, 1 reply; 2+ messages in thread
From: Simon Josefsson @ 2002-04-24 19:28 UTC (permalink / raw)
  Cc: Ted Zlatanov

This patch makes smtpmail.el take advantage of the new netrc.el stuff.

I bumped :version on the variable to "21.3".  Is this correct?  I
wasn't sure about that.

I am sending this message with SMTP authentication using ~/.authinfo,
but I also tested the old `smtpmail-auth-credentials' as well.  Not
tested by anyone but me though.  Ted, if you can/want, please test
it. (Ted, netrc.el has been added to Emacs, XEmacs and Oort Gnus now.)

2002-04-24  Simon Josefsson  <jas@extundo.com>

	* mail/smtpmail.el (smtpmail-auth-credentials): Support netrc
	files as well.
	(smtpmail-try-auth-methods): Support netrc data.
	(netrc-parse): Autoload netrc.

--- smtpmail.el.~1.38.~	Wed Apr 24 21:13:38 2002
+++ smtpmail.el	Wed Apr 24 21:26:11 2002
@@ -40,7 +40,7 @@
 ;;(setq smtpmail-local-domain "YOUR DOMAIN NAME")
 ;;(setq smtpmail-sendto-domain "YOUR DOMAIN NAME")
 ;;(setq smtpmail-debug-info t) ; only to debug problems
-;;(setq smtpmail-auth-credentials
+;;(setq smtpmail-auth-credentials  ; or use ~/.authinfo
 ;;      '(("YOUR SMTP HOST" 25 "username" "password")))
 ;;(setq smtpmail-starttls-credentials
 ;;      '(("YOUR SMTP HOST" 25 "~/.my_smtp_tls.key" "~/.my_smtp_tls.cert")))
@@ -73,6 +73,7 @@
 (autoload 'message-make-date "message")
 (autoload 'message-make-message-id "message")
 (autoload 'rfc2104-hash "rfc2104")
+(autoload 'netrc-parse "netrc")
 
 ;;;
 (defgroup smtpmail nil
@@ -150,19 +151,21 @@
   :type 'directory
   :group 'smtpmail)
 
-(defcustom smtpmail-auth-credentials '(("" 25 "" nil))
-  "Specify username and password for servers.
-It is a list of four-element lists that contain, in order,
+(defcustom smtpmail-auth-credentials "~/.authinfo"
+  "Specify username and password for servers, directly or via .netrc file.
+This variable can either be a filename pointing to a file in netrc(5)
+format, or list of four-element lists that contain, in order,
 `servername' (a string), `port' (an integer), `user' (a string) and
-`password' (a string, or nil to query the user when needed).
-If you need to enter a `realm' too, add it to the user string, so that
-it looks like `user@realm'."
-  :type '(repeat (list (string  :tag "Server")
+`password' (a string, or nil to query the user when needed).  If you
+need to enter a `realm' too, add it to the user string, so that it
+looks like `user@realm'."
+  :type '(choice file
+		 (repeat (list (string  :tag "Server")
 		       (integer :tag "Port")
 		       (string  :tag "Username")
 		       (choice (const :tag "Query when needed" nil)
-			       (string  :tag "Password"))))
-  :version "21.1"
+				       (string  :tag "Password")))))
+  :version "21.3"
   :group 'smtpmail)
 
 (defcustom smtpmail-starttls-credentials '(("" 25 "" ""))
@@ -460,7 +467,16 @@
 (defun smtpmail-try-auth-methods (process supported-extensions host port)
   (let* ((mechs (cdr-safe (assoc 'auth supported-extensions)))
 	 (mech (car (smtpmail-intersection smtpmail-auth-supported mechs)))
-	 (cred (smtpmail-find-credentials smtpmail-auth-credentials host port))
+	 (cred (if (stringp smtpmail-auth-credentials)
+		   (let* ((netrc (netrc-parse smtpmail-auth-credentials))
+			  (hostentry (netrc-machine 
+				      netrc host (format "%s" (or port "smtp"))
+				      "smtp")))
+		     (list host port
+			   (netrc-get hostentry "login")
+			   (netrc-get hostentry "password")))
+		 (smtpmail-find-credentials
+		  smtpmail-auth-credentials host port)))
 	 (passwd (when cred
 		   (or (smtpmail-cred-passwd cred)
 		       (read-passwd
@@ -507,7 +523,8 @@
        (t
 	(error "Mechanism %s not implemented" mech)))
       ;; Remember the password.
-      (unless (smtpmail-cred-passwd cred)
+      (when (and (not (stringp smtpmail-auth-credentials))
+		 (null (smtpmail-cred-passwd cred)))
 	(setcar (cdr (cdr (cdr cred))) passwd)))))
 
 (defun smtpmail-via-smtp (recipient smtpmail-text-buffer)

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-05-07 19:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-04-24 19:28 make smtpmail.el use the new netrc.el file Simon Josefsson
2002-05-07 19:45 ` Fidel Salas

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).