*** empty log message ***
[bpt/emacs.git] / lisp / mail / rfc822.el
index f0662c2..178dd94 100644 (file)
@@ -1,12 +1,16 @@
-;; Hairy rfc822 parser for mail and news and suchlike
-;; Copyright (C) 1986, 1987 Free Software Foundation, Inc.
-;; Author Richard Mlynarik.
+;;; rfc822.el --- hairy rfc822 parser for mail and news and suchlike
+
+;; Copyright (C) 1986, 87, 1990 Free Software Foundation, Inc.
+
+;; Author: Richard Mlynarik <mly@eddie.mit.edu>
+;; Maintainer: FSF
+;; Keywords: mail
 
 ;; 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 1, or (at your option)
+;; 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,
 ;; 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, 675 Mass Ave, Cambridge, MA 02139, USA.
+;; 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.
 
-(provide 'rfc822)
+;;; Commentary:
+
+;; Support functions for parsing RFC-822 headers, used by mail and news
+;; modes.  
+
+;;; Code:
 
 ;; uses address-start free, throws to address
 (defun rfc822-bad-address (reason)
@@ -39,7 +49,7 @@
        (setq losers (cdr losers))))
     (goto-char (point-min)) (insert "(Unparsable address -- "
                                    reason
-                                   ":\n\t  \"")
+                                   ": \"")
     (goto-char (point-max)) (insert "\")"))
   (rfc822-nuke-whitespace)
   (throw 'address (buffer-substring address-start (point))))
               ;; an addr-spec, since many broken mailers output
               ;; "Hern K. Herklemeyer III
               ;;   <yank@megadeath.dod.gods-own-country>"
-              (or (= n 0)
-                  (= (preceding-char) ?\ )
-                  (insert ?\ ))
-              (rfc822-snarf-words)
-              (setq n (1+ n)))
+               (let ((again t))
+                 (while again
+                   (or (= n 0) (bobp) (= (preceding-char) ?\ )
+                       (insert ?\ ))
+                   (rfc822-snarf-words)
+                   (setq n (1+ n))
+                   (setq again (or (rfc822-looking-at ?.)
+                                   (looking-at "[^][\000-\037\177-\377 ()<>@,;:\\.]"))))))
              ((= n 0)
               (throw 'address nil))
              ((= n 1) ; allow "foo" (losing unix seems to do this)
               (throw 'address
                 (buffer-substring address-start (point))))
-             ((or (eobp) (looking-at ","))
+              ((> n 1)
+               (rfc822-bad-address "Missing comma between addresses or badly-formatted address"))
+             ((or (eobp) (= (following-char) ?,))
               (rfc822-bad-address "Missing comma or route-spec"))
              (t
               (rfc822-bad-address "Strange character or missing comma")))))))
                    (catch 'address ; this is for rfc822-bad-address
                      (cond ((rfc822-looking-at ?\,)
                             nil)
-                           ((looking-at "[][\000-\037\177-\377@;:\\.>]")
+                           ((looking-at "[][\000-\037\177-\377@;:\\.>)]")
                             (forward-char)
                             (rfc822-bad-address
                               (format "Strange character \\%c found"
            (nreverse list)))
       (and buf (kill-buffer buf))))))
 
+(provide 'rfc822)
+
+;;; rfc822.el ends here