1 ;;; std11.el --- STD 11 parser for GNU Emacs
3 ;; Copyright (C) 1995,1996 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Keywords: mail, news, RFC 822, STD 11
7 ;; Version: $Id: std11.el,v 0.6 1996-08-28 14:17:21 morioka Exp $
9 ;; This file is part of tl (Tiny Library).
11 ;; This program is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
16 ;; This program is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with This program; see the file COPYING. If not, write to
23 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
28 (autoload 'buffer-substring-no-properties "emu")
29 (autoload 'member "emu")
35 (defconst std11-field-name-regexp "[!-9;-~]+")
36 (defconst std11-field-head-regexp
37 (concat "^" std11-field-name-regexp ":"))
38 (defconst std11-next-field-head-regexp
39 (concat "\n" std11-field-name-regexp ":"))
41 (defun std11-field-body (name &optional boundary)
44 (std11-narrow-to-header boundary)
45 (goto-char (point-min))
46 (let ((case-fold-search t))
47 (if (re-search-forward (concat "^" name ":[ \t]*") nil t)
48 (buffer-substring-no-properties (match-end 0) (std11-field-end))
51 (defun std11-field-end ()
52 (if (re-search-forward std11-next-field-head-regexp nil t)
53 (goto-char (match-beginning 0))
54 (if (re-search-forward "^$" nil t)
55 (goto-char (1- (match-beginning 0)))
61 (defun std11-field-names (&optional boundary)
64 (std11-narrow-to-header boundary)
65 (goto-char (point-min))
67 (while (re-search-forward std11-field-head-regexp nil t)
68 (setq name (buffer-substring-no-properties
69 (match-beginning 0)(1- (match-end 0))))
70 (or (member name dest)
71 (setq dest (cons name dest))
76 (defun std11-field-bodies (field-names &optional default-value boundary)
79 (std11-narrow-to-header boundary)
80 (let* ((case-fold-search t)
81 (dest (make-list (length field-names) default-value))
85 (while (setq field-name (car s-rest))
86 (goto-char (point-min))
87 (if (re-search-forward (concat "^" field-name ":[ \t]*") nil t)
89 (buffer-substring-no-properties
90 (match-end 0) (std11-field-end)))
92 (setq s-rest (cdr s-rest)
101 (defun std11-narrow-to-header (&optional boundary)
103 (goto-char (point-min))
104 (if (re-search-forward
105 (concat "^\\(" (regexp-quote (or boundary "")) "\\)?$")
111 (defun std11-header-string (pat &optional boundary)
112 (let ((case-fold-search t))
115 (std11-narrow-to-header boundary)
116 (goto-char (point-min))
118 (while (re-search-forward std11-field-head-regexp nil t)
120 (buffer-substring (match-beginning 0) (std11-field-end)))
121 (if (string-match pat field)
122 (setq header (concat header field "\n"))
127 (defun std11-header-string-except (pat &optional boundary)
128 (let ((case-fold-search t))
131 (std11-narrow-to-header boundary)
132 (goto-char (point-min))
134 (while (re-search-forward std11-field-head-regexp nil t)
136 (buffer-substring (match-beginning 0) (std11-field-end)))
137 (if (not (string-match pat field))
138 (setq header (concat header field "\n"))
149 ;;; std11.el ends here