1 ;;; std11.el --- STD 11 functions 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.17 1996-08-28 20:42:42 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-end ()
42 "Move to end of field and return this point. [std11.el]"
43 (if (re-search-forward std11-next-field-head-regexp nil t)
44 (goto-char (match-beginning 0))
45 (if (re-search-forward "^$" nil t)
46 (goto-char (1- (match-beginning 0)))
52 (defun std11-find-field-body (name &optional boundary)
53 "Return body of field NAME.
54 If BOUNDARY is not nil, it is used as message header separator.
58 (std11-narrow-to-header boundary)
59 (goto-char (point-min))
60 (let ((case-fold-search t))
61 (if (re-search-forward (concat "^" name ":[ \t]*") nil t)
62 (buffer-substring-no-properties (match-end 0) (std11-field-end))
65 (defun std11-find-field-bodies (field-names &optional default-value boundary)
66 "Return list of each field-bodies of FIELD-NAMES of the message header
67 in current buffer. If BOUNDARY is not nil, it is used as message
68 header separator. [std11.el]"
71 (std11-narrow-to-header boundary)
72 (let* ((case-fold-search t)
73 (dest (make-list (length field-names) default-value))
77 (while (setq field-name (car s-rest))
78 (goto-char (point-min))
79 (if (re-search-forward (concat "^" field-name ":[ \t]*") nil t)
81 (buffer-substring-no-properties
82 (match-end 0) (std11-field-end)))
84 (setq s-rest (cdr s-rest)
93 (defun std11-unfold-string (string)
94 "Unfold STRING as message header field. [std11.el]"
96 (while (string-match "\n\\s +" string)
97 (setq dest (concat dest (substring string 0 (match-beginning 0)) " "))
98 (setq string (substring string (match-end 0)))
107 (defun std11-narrow-to-header (&optional boundary)
108 "Narrow to the message header.
109 If BOUNDARY is not nil, it is used as message header separator.
112 (goto-char (point-min))
113 (if (re-search-forward
114 (concat "^\\(" (regexp-quote (or boundary "")) "\\)?$")
120 (defun std11-header-string (regexp &optional boundary)
121 "Return string of message header fields matched by REGEXP.
122 If BOUNDARY is not nil, it is used as message header separator.
124 (let ((case-fold-search t))
127 (std11-narrow-to-header boundary)
128 (goto-char (point-min))
130 (while (re-search-forward std11-field-head-regexp nil t)
132 (buffer-substring (match-beginning 0) (std11-field-end)))
133 (if (string-match regexp field)
134 (setq header (concat header field "\n"))
139 (defun std11-header-string-except (regexp &optional boundary)
140 "Return string of message header fields not matched by REGEXP.
141 If BOUNDARY is not nil, it is used as message header separator.
143 (let ((case-fold-search t))
146 (std11-narrow-to-header boundary)
147 (goto-char (point-min))
149 (while (re-search-forward std11-field-head-regexp nil t)
151 (buffer-substring (match-beginning 0) (std11-field-end)))
152 (if (not (string-match regexp field))
153 (setq header (concat header field "\n"))
158 (defun std11-collect-field-names (&optional boundary)
159 "Return list of all field-names of the message header in current buffer.
160 If BOUNDARY is not nil, it is used as message header separator.
164 (std11-narrow-to-header boundary)
165 (goto-char (point-min))
167 (while (re-search-forward std11-field-head-regexp nil t)
168 (setq name (buffer-substring-no-properties
169 (match-beginning 0)(1- (match-end 0))))
170 (or (member name dest)
171 (setq dest (cons name dest))
184 (autoload func "std11-parse")
186 '(std11-lexical-analyze
187 std11-parse-address std11-parse-addresses
188 std11-parse-address-string))
190 ;;; std11.el ends here