1 ;;; drums.el --- Functions for parsing RFC822bis headers
2 ;; Copyright (C) 1998 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; This file is part of GNU Emacs.
7 ;; GNU Emacs is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; GNU Emacs is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs; see the file COPYING. If not, write to the
19 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 ;; Boston, MA 02111-1307, USA.
24 ;; DRUMS is an IETF Working Group that works (or worked) on the
25 ;; successor to RFC822, "Standard For The Format Of Arpa Internet Text
26 ;; Messages". This library is based on
27 ;; draft-ietf-drums-msg-fmt-05.txt, released on 1998-08-05.
33 (defvar drums-no-ws-ctl-token "\001-\010\013\014\016-\037\177"
34 "US-ASCII control characters excluding CR, LF and white space.")
35 (defvar drums-text-token "\001-\011\013\014\016-\177"
36 "US-ASCII characters exlcuding CR and LF.")
37 (defvar drums-specials-token "()<>[]:;@\\,.\""
38 "Special characters.")
39 (defvar drums-quote-token "\\"
41 (defvar drums-wsp-token " \t"
43 (defvar drums-fws-regexp
44 (concat "[" drums-wsp-token "]*\n[" drums-wsp-token "]+")
45 "Folding white space.")
46 (defvar drums-atext-token "-^a-zA-Z0-9!#$%&'*+/=?_`{|}~"
48 (defvar drums-dot-atext-token "-^a-zA-Z0-9!#$%&'*+/=?_`{|}~."
49 "Textual token including full stop.")
50 (defvar drums-qtext-token
51 (concat drums-no-ws-ctl-token "\041\043-\133\135-\177")
52 "Non-white-space control characaters, plus the rest of ASCII excluding backslash and doublequote.")
54 (defvar drums-syntax-table
55 (let ((table (copy-syntax-table emacs-lisp-mode-syntax-table)))
56 (modify-syntax-entry ?\\ "/" table)
57 (modify-syntax-entry ?< "(" table)
58 (modify-syntax-entry ?> ")" table)
61 (defsubst drums-init (string)
62 (set-syntax-table drums-syntax-table)
65 (goto-char (point-min)))
67 (defun drums-remove-comments (string)
68 "Remove comments from STRING."
73 (setq c (following-char))
78 (delete-region (point) (progn (forward-sexp 1) (point))))
83 (defun drums-remove-whitespace (string)
84 "Remove comments from STRING."
89 (setq c (following-char))
99 (defun drums-get-comment (string)
100 "Return the first comment in STRING."
105 (setq c (following-char))
113 (progn (forward-sexp 1) (1- (point)))))
114 (goto-char (point-max)))
119 (defun drums-parse-address (string)
120 "Parse STRING and return a MAILBOX / DISPLAY-NAME pair."
122 (let (display-name mailbox c)
125 (setq c (following-char))
133 (push (buffer-substring
134 (1+ (point)) (progn (forward-sexp 1) (1- (point))))
136 ((looking-at (concat "[" drums-atext-token "]"))
137 (push (buffer-substring (point) (progn (forward-word 1) (point)))
141 (drums-remove-whitespace
142 (drums-remove-comments
145 (progn (forward-sexp 1) (1- (point))))))))
146 (t (error "Unknown symbol: %c" c))))
147 ;; If we found no display-name, then we look for comments.
149 (setq display-name (mapconcat 'identity (nreverse display-name) " "))
150 (setq display-name (drums-get-comment string)))
152 (cons mailbox display-name)))))
154 (defun drums-parse-addresses (string)
155 "Parse STRING and return a list of MAILBOX / DISPLAY-NAME pairs."
161 (setq c (following-char))
163 ((memq c '(?\" ?< ?\())
166 (push (drums-parse-address (buffer-substring beg (1- (point))))
173 (defun drums-unfold-fws ()
174 "Unfold folding white space in the current buffer."
175 (goto-char (point-min))
176 (while (re-search-forward drums-fws-regexp nil t)
177 (replace-match " " t t))
178 (goto-char (point-min)))
180 (defun drums-parse-date (string)
181 "Return an Emacs time spec from STRING."
182 (encode-time (parse-time-string string)))
186 ;;; drums.el ends here