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.10 1996-08-28 15:25:16 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-find-field-body (name &optional boundary)
42 "Return body of field NAME.
43 If BOUNDARY is not nil, it is used as message header separator.
47 (std11-narrow-to-header boundary)
48 (goto-char (point-min))
49 (let ((case-fold-search t))
50 (if (re-search-forward (concat "^" name ":[ \t]*") nil t)
51 (buffer-substring-no-properties (match-end 0) (std11-field-end))
54 (defun std11-field-end ()
55 "Move to end of field and return this point. [std11.el]"
56 (if (re-search-forward std11-next-field-head-regexp nil t)
57 (goto-char (match-beginning 0))
58 (if (re-search-forward "^$" nil t)
59 (goto-char (1- (match-beginning 0)))
65 (defun std11-field-names (&optional boundary)
66 "Return list of all field-names of the message header in current buffer.
67 If BOUNDARY is not nil, it is used as message header separator.
71 (std11-narrow-to-header boundary)
72 (goto-char (point-min))
74 (while (re-search-forward std11-field-head-regexp nil t)
75 (setq name (buffer-substring-no-properties
76 (match-beginning 0)(1- (match-end 0))))
77 (or (member name dest)
78 (setq dest (cons name dest))
83 (defun std11-find-field-bodies (field-names &optional default-value boundary)
84 "Return list of each field-bodies of FIELD-NAMES of the message header
85 in current buffer. If BOUNDARY is not nil, it is used as message
86 header separator. [std11.el]"
89 (std11-narrow-to-header boundary)
90 (let* ((case-fold-search t)
91 (dest (make-list (length field-names) default-value))
95 (while (setq field-name (car s-rest))
96 (goto-char (point-min))
97 (if (re-search-forward (concat "^" field-name ":[ \t]*") nil t)
99 (buffer-substring-no-properties
100 (match-end 0) (std11-field-end)))
102 (setq s-rest (cdr s-rest)
111 (defun std11-unfold-string (string)
112 "Unfold STRING as message header field. [std11.el]"
114 (while (string-match "\n\\s +" string)
115 (setq dest (concat dest (substring string 0 (match-beginning 0)) " "))
116 (setq string (substring string (match-end 0)))
125 (defun std11-narrow-to-header (&optional boundary)
126 "Narrow to the message header.
127 If BOUNDARY is not nil, it is used as message header separator.
130 (goto-char (point-min))
131 (if (re-search-forward
132 (concat "^\\(" (regexp-quote (or boundary "")) "\\)?$")
138 (defun std11-header-string (regexp &optional boundary)
139 "Return string of message header fields matched by REGEXP.
140 If BOUNDARY is not nil, it is used as message header separator.
142 (let ((case-fold-search t))
145 (std11-narrow-to-header boundary)
146 (goto-char (point-min))
148 (while (re-search-forward std11-field-head-regexp nil t)
150 (buffer-substring (match-beginning 0) (std11-field-end)))
151 (if (string-match regexp field)
152 (setq header (concat header field "\n"))
157 (defun std11-header-string-except (regexp &optional boundary)
158 "Return string of message header fields not matched by REGEXP.
159 If BOUNDARY is not nil, it is used as message header separator.
161 (let ((case-fold-search t))
164 (std11-narrow-to-header boundary)
165 (goto-char (point-min))
167 (while (re-search-forward std11-field-head-regexp nil t)
169 (buffer-substring (match-beginning 0) (std11-field-end)))
170 (if (not (string-match regexp field))
171 (setq header (concat header field "\n"))
182 ;;; std11.el ends here