*** empty log message ***
[elisp/apel.git] / std11.el
1 ;;; std11.el --- STD 11 parser for GNU Emacs
2
3 ;; Copyright (C) 1995,1996 Free Software Foundation, Inc.
4
5 ;; Author:   MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Keywords: mail, news, RFC 822, STD 11
7 ;; Version: $Id: std11.el,v 0.1 1996-08-28 12:29:00 morioka Exp $
8
9 ;; This file is part of tl (Tiny Library).
10
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.
15
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.
20
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.
25
26 ;;; Code:
27
28 ;;; @ field
29 ;;;
30
31 (defconst std11-field-name-regexp "[!-9;-~]+")
32 (defconst std11-field-head-regexp
33   (concat "\\(" std11-field-name-regexp "\\):"))
34
35 (defun std11-field-end ()
36   (if (re-search-forward rfc822::next-field-top-regexp nil t)
37       (goto-char (match-beginning 0))
38     (if (re-search-forward "^$" nil t)
39         (goto-char (1- (match-beginning 0)))
40       (end-of-line)
41       ))
42   (point)
43   )
44
45
46 ;;; @ header
47 ;;;
48
49 (defun std11-header-string (pat &optional boundary)
50   (let ((case-fold-search t))
51     (save-excursion
52       (save-restriction
53         (std11-narrow-to-header boundary)
54         (goto-char (point-min))
55         (let (field header)
56           (while (re-search-forward std11-field-head-regexp nil t)
57             (setq field (buffer-substring (match-beginning 0)
58                                           (rfc822/field-end)
59                                           ))
60             (if (string-match pat field)
61                 (setq header (concat header field "\n"))
62               ))
63           header)
64         ))))
65
66 (defun std11-header-string-except (pat &optional boundary)
67   (let ((case-fold-search t))
68     (save-excursion
69       (save-restriction
70         (std11-narrow-to-header boundary)
71         (goto-char (point-min))
72         (let (field header)
73           (while (re-search-forward std11-field-head-regexp nil t)
74             (setq field (buffer-substring (match-beginning 0)
75                                           (rfc822/field-end)
76                                           ))
77             (if (not (string-match pat field))
78                 (setq header (concat header field "\n"))
79               ))
80           header)
81         ))))
82
83 (defun std11-narrow-to-header (&optional boundary)
84   (narrow-to-region
85    (goto-char (point-min))
86    (if (re-search-forward
87         (concat "^\\(" (regexp-quote (or boundary "")) "\\)?$")
88         nil t)
89        (match-beginning 0)
90      (point-max)
91      )))
92
93
94 ;;; @ end
95 ;;;
96
97 (provide 'std11)
98
99 ;;; std11.el ends here