From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/44355 Path: main.gmane.org!not-for-mail From: Ted Zlatanov Newsgroups: gmane.emacs.gnus.general Subject: Re: smtpmail-auth-credentials from authinfo Date: Tue, 23 Apr 2002 11:53:56 -0400 Organization: =?koi8-r?q?=F4=C5=CF=C4=CF=D2=20=FA=CC=C1=D4=C1=CE=CF=D7?= @ Cienfuegos Sender: owner-ding@hpc.uh.edu Message-ID: References: NNTP-Posting-Host: localhost.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: main.gmane.org 1019577421 21338 127.0.0.1 (23 Apr 2002 15:57:01 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Tue, 23 Apr 2002 15:57:01 +0000 (UTC) Cc: ding , Return-path: Original-Received: from malifon.math.uh.edu ([129.7.128.13]) by main.gmane.org with esmtp (Exim 3.33 #1 (Debian)) id 1702f6-0005Y3-00 for ; Tue, 23 Apr 2002 17:57:00 +0200 Original-Received: from sina.hpc.uh.edu ([129.7.128.10] ident=lists) by malifon.math.uh.edu with esmtp (Exim 3.20 #1) id 1702eJ-0007Ay-00; Tue, 23 Apr 2002 10:56:11 -0500 Original-Received: by sina.hpc.uh.edu (TLB v0.09a (1.20 tibbs 1996/10/09 22:03:07)); Tue, 23 Apr 2002 10:56:22 -0500 (CDT) Original-Received: from sclp3.sclp.com (qmailr@sclp3.sclp.com [209.196.61.66]) by sina.hpc.uh.edu (8.9.3/8.9.3) with SMTP id KAA23196 for ; Tue, 23 Apr 2002 10:56:03 -0500 (CDT) Original-Received: (qmail 2141 invoked by alias); 23 Apr 2002 15:54:24 -0000 Original-Received: (qmail 2136 invoked from network); 23 Apr 2002 15:54:24 -0000 Original-Received: from liilmtlssm01.mailtask.com (208.203.59.25) by gnus.org with SMTP; 23 Apr 2002 15:54:24 -0000 Original-Received: from LIILMTLSFE02.mailtask.com ([208.203.59.43]) by LIILMTLSSM01.mailtask.com with Microsoft SMTPSVC(5.0.2195.3779); Tue, 23 Apr 2002 10:53:57 -0500 Original-Received: from onyx.nimbus.northernlight.com ([10.128.22.65]) by LIILMTLSFE02.mailtask.com with Microsoft SMTPSVC(5.0.2195.4905); Tue, 23 Apr 2002 10:53:58 -0500 Original-To: Simon Josefsson X-Face: bd.DQ~'29fIs`T_%O%C\g%6jW)yi[zuz6;d4V0`@y-~$#3P_Ng{@m+e4o<4P'#(_GJQ%TT= D}[Ep*b!\e,fBZ'j_+#"Ps?s2!4H2-Y"sx" Mail-Followup-To: Simon Josefsson , ding , In-Reply-To: (Simon Josefsson's message of "Fri, 19 Apr 2002 17:55:43 +0200 (CEST)") Original-Lines: 57 User-Agent: Gnus/5.090006 (Oort Gnus v0.06) Emacs/21.2 (i386-redhat-linux-gnu) X-OriginalArrivalTime: 23 Apr 2002 15:53:58.0786 (UTC) FILETIME=[14A21E20:01C1EADF] Precedence: list X-Majordomo: 1.94.jlt7 Xref: main.gmane.org gmane.emacs.gnus.general:44355 X-Report-Spam: http://spam.gmane.org/gmane.emacs.gnus.general:44355 --=-=-= On Fri, 19 Apr 2002, jas@extundo.com wrote: > On Fri, 19 Apr 2002, Ted Zlatanov wrote: > >> Should I extract that to authinfo.el (or netrc.el?) so it can be >> integrated with smtpmail.el? > > I think that would be a good idea. nntp.el, imap.el and sieve.el > would also need to be changed, and maybe more stuff. I am attaching the netrc.el file, and the patch to gnus-util.el that will provide backward compatibility (via defalias calls) until the maintainers of the respective modules want to move to the netrc function names. I had to do (eval-and-compile (defalias 'netrc-point-at-eol (if (fboundp 'point-at-eol) 'point-at-eol 'line-end-position))) instead of (defalias 'netrc-point-at-eol (if (fboundp 'point-at-eol) 'point-at-eol 'line-end-position)) I'm not sure why the compilation was having problems with the function without the eval-and-compile... The rest was very easy though. >> Also smtpmail.el needs to be patched so it accepts the old-style >> flat lists and the gnus-parse-netrc style output. > > I think it would be better if smtpmail.el looked in .authinfo by > default, and not touch the `smtpmail-auth-credentials' stuff. When I know that the netrc.el functionality is accepted, I will try to modify smtpmail.el further to work with the netrc interface. smtpmail.el ships with Emacs, while netrc.el does not (yet?), so it doesn't make sense to modify smtpmail.el to rely on the netrc functionality only. It should look for netrc first, and failing that it should try the smtpmail-auth-credentials. I would appreciate comments from Stephen Cranefield, who's noted in the smtpmail.el credits as the AUTH support author. It would also be good to know the chances of having netrc.el included in the main Emacs distro. Thanks Ted --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=netrc.el ;;; netrc.el --- .netrc parsing functionality ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002 ;; Free Software Foundation, Inc. ;; Author: Lars Magne Ingebrigtsen ;; Modularizer: Ted Zlatanov ;; Keywords: news ;; This file is part of GNU Emacs. ;; 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 2, 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 ;; 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., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. ;;; Commentary: ;; Just the .netrc parsing functionality, abstracted so other packages ;; besides Gnus can use it. ;;; Code: ;;; ;;; .netrc and .authinforc parsing ;;; (eval-and-compile (defalias 'netrc-point-at-eol (if (fboundp 'point-at-eol) 'point-at-eol 'line-end-position))) (defun netrc-parse (file) "Parse FILE and return an list of all entries in the file." (when (file-exists-p file) (with-temp-buffer (let ((tokens '("machine" "default" "login" "password" "account" "macdef" "force" "port")) alist elem result pair) (insert-file-contents file) (goto-char (point-min)) ;; Go through the file, line by line. (while (not (eobp)) (narrow-to-region (point) (netrc-point-at-eol)) ;; For each line, get the tokens and values. (while (not (eobp)) (skip-chars-forward "\t ") ;; Skip lines that begin with a "#". (if (eq (char-after) ?#) (goto-char (point-max)) (unless (eobp) (setq elem (if (= (following-char) ?\") (read (current-buffer)) (buffer-substring (point) (progn (skip-chars-forward "^\t ") (point))))) (cond ((equal elem "macdef") ;; We skip past the macro definition. (widen) (while (and (zerop (forward-line 1)) (looking-at "$"))) (narrow-to-region (point) (point))) ((member elem tokens) ;; Tokens that don't have a following value are ignored, ;; except "default". (when (and pair (or (cdr pair) (equal (car pair) "default"))) (push pair alist)) (setq pair (list elem))) (t ;; Values that haven't got a preceding token are ignored. (when pair (setcdr pair elem) (push pair alist) (setq pair nil))))))) (when alist (push (nreverse alist) result)) (setq alist nil pair nil) (widen) (forward-line 1)) (nreverse result))))) (defun netrc-machine (list machine &optional port defaultport) "Return the netrc values from LIST for MACHINE or for the default entry. If PORT specified, only return entries with matching port tokens. Entries without port tokens default to DEFAULTPORT." (let ((rest list) result) (while list (when (equal (cdr (assoc "machine" (car list))) machine) (push (car list) result)) (pop list)) (unless result ;; No machine name matches, so we look for default entries. (while rest (when (assoc "default" (car rest)) (push (car rest) result)) (pop rest))) (when result (setq result (nreverse result)) (while (and result (not (equal (or port defaultport "nntp") (or (netrc-get (car result) "port") defaultport "nntp")))) (pop result)) (car result)))) (defun netrc-get (alist type) "Return the value of token TYPE from ALIST." (cdr (assoc type alist))) (provide 'netrc) ;;; netrc.el ends here --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=gnus-util-netrc.patch --- gnus-util.el Tue Apr 23 11:50:53 2002 +++ gnus-util.el.new Tue Apr 23 11:39:58 2002 @@ -38,6 +38,7 @@ (defvar nnmail-pathname-coding-system)) (require 'nnheader) (require 'time-date) +(require 'netrc) (eval-and-compile (autoload 'message-fetch-field "message") @@ -62,6 +63,11 @@ (setq start (- (length string) tail)))) string)))) +;;; bring in the netrc functions as aliases +(defalias 'gnus-netrc-get 'netrc-get) +(defalias 'gnus-netrc-machine 'netrc-machine) +(defalias 'gnus-parse-netrc 'netrc-parse) + (defun gnus-boundp (variable) "Return non-nil if VARIABLE is bound and non-nil." (and (boundp variable) @@ -899,93 +905,6 @@ (unwind-protect (apply 'run-hooks funcs) (set-buffer buf)))) - -;;; -;;; .netrc and .authinforc parsing -;;; - -(defun gnus-parse-netrc (file) - "Parse FILE and return an list of all entries in the file." - (when (file-exists-p file) - (with-temp-buffer - (let ((tokens '("machine" "default" "login" - "password" "account" "macdef" "force" - "port")) - alist elem result pair) - (insert-file-contents file) - (goto-char (point-min)) - ;; Go through the file, line by line. - (while (not (eobp)) - (narrow-to-region (point) (gnus-point-at-eol)) - ;; For each line, get the tokens and values. - (while (not (eobp)) - (skip-chars-forward "\t ") - ;; Skip lines that begin with a "#". - (if (eq (char-after) ?#) - (goto-char (point-max)) - (unless (eobp) - (setq elem - (if (= (following-char) ?\") - (read (current-buffer)) - (buffer-substring - (point) (progn (skip-chars-forward "^\t ") - (point))))) - (cond - ((equal elem "macdef") - ;; We skip past the macro definition. - (widen) - (while (and (zerop (forward-line 1)) - (looking-at "$"))) - (narrow-to-region (point) (point))) - ((member elem tokens) - ;; Tokens that don't have a following value are ignored, - ;; except "default". - (when (and pair (or (cdr pair) - (equal (car pair) "default"))) - (push pair alist)) - (setq pair (list elem))) - (t - ;; Values that haven't got a preceding token are ignored. - (when pair - (setcdr pair elem) - (push pair alist) - (setq pair nil))))))) - (when alist - (push (nreverse alist) result)) - (setq alist nil - pair nil) - (widen) - (forward-line 1)) - (nreverse result))))) - -(defun gnus-netrc-machine (list machine &optional port defaultport) - "Return the netrc values from LIST for MACHINE or for the default entry. -If PORT specified, only return entries with matching port tokens. -Entries without port tokens default to DEFAULTPORT." - (let ((rest list) - result) - (while list - (when (equal (cdr (assoc "machine" (car list))) machine) - (push (car list) result)) - (pop list)) - (unless result - ;; No machine name matches, so we look for default entries. - (while rest - (when (assoc "default" (car rest)) - (push (car rest) result)) - (pop rest))) - (when result - (setq result (nreverse result)) - (while (and result - (not (equal (or port defaultport "nntp") - (or (gnus-netrc-get (car result) "port") - defaultport "nntp")))) - (pop result)) - (car result)))) - -(defun gnus-netrc-get (alist type) - "Return the value of token TYPE from ALIST." - (cdr (assoc type alist))) ;;; Various --=-=-=--