annotate lisp/mail/rmailhdr.el @ 88138:824f9f6f0df3

(rmail-get-new-mail): Integrate the rmail spam filter into rmail.
author Paul Reilly <pmr@pajato.com>
date Fri, 21 Feb 2003 18:44:45 +0000
parents 30235d819e60
children 83e39e1cce60
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
88124
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
1 ;;; rmail-header.el --- Header handling code of "RMAIL" mail reader for Emacs
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
2
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
3 ;; Copyright (C) 2002
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
4 ;; Free Software Foundation, Inc.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
5
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
6 ;; Maintainer: FSF
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
7 ;; Keywords: mail
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
8
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
10
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
14 ;; any later version.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
15
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
19 ;; GNU General Public License for more details.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
20
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
24 ;; Boston, MA 02111-1307, USA.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
25
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
26 ;;; Commentary:
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
27
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
28 ;;; Code:
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
29
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
30 ;; Written by Paul Reilly as part of moving BABYL to inbox/mbox format.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
31
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
32 (eval-when-compile
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
33 (require 'mail-utils))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
34
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
35 (defconst rmail-header-attribute-header "X-BABYL-V6-ATTRIBUTES"
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
36 "The header that persists the Rmail attribute data.")
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
37
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
38 (defconst rmail-header-keyword-header "X-BABYL-V6-KEYWORDS"
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
39 "The header that persists the Rmail keyword data.")
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
40
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
41 (defvar rmail-header-overlay-list nil
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
42 "A list of cached overlays used to make headers hidden or visible.")
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
43
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
44 (defvar rmail-header-display-mode nil
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
45 "Records the current header display mode.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
46 nil means headers are displayed, t indicates headers are not displayed.")
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
47
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
48 (defmacro rmail-header-get-limit ()
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
49 '(progn
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
50 (goto-char (point-min))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
51 (if (search-forward "\n\n" nil t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
52 (1- (point))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
53 (error "Invalid message format."))))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
54
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
55 ;;; The following functions are presented alphabetically ordered by
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
56 ;;; name.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
57
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
58 (defun rmail-header-add-header (header value)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
59 "Add HEADER to the list of headers and associate VALUE with it.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
60 The current buffer, possibly narrowed, contains a single message."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
61 (save-excursion
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
62 (let* ((inhibit-read-only t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
63 (case-fold-search t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
64 (limit (rmail-header-get-limit))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
65 start end)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
66
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
67 ;; Search for the given header. If found, then set it's value.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
68 ;; If not then add the header to the end of the header section.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
69 (goto-char (point-min))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
70 (if (re-search-forward (format "^%s: " header) limit t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
71
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
72 ;; Kill the current value and replace it with the new.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
73 (progn
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
74 (beginning-of-line)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
75 (setq start (point))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
76 (while (progn
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
77 (forward-line 1)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
78 (looking-at "[ \t]+")))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
79 (kill-region start (point)))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
80
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
81 ;; Add a new header at the end of the headers.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
82 (goto-char limit))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
83 (insert header ": " value "\n"))))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
84
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
85 (defun rmail-header-contains-keyword-p (keyword)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
86 "Return t if KEYWORD exists in the current buffer, nil otherwise."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
87 (let ((limit (rmail-header-get-limit)))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
88 (goto-char (point-min))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
89 (if (re-search-forward (format "^%s: " rmail-header-keyword-header) limit t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
90
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
91 ;; Some keywords exist. Now search for the specific keyword.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
92 (let ((start (point))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
93 (end (progn (end-of-line) (point))))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
94 (if (re-search-forward (concat "\\(" keyword ",\\|" keyword "$\\)"))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
95 t)))))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
96
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
97 (defun rmail-header-get-header (header)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
98 "Return the text value for HEADER, nil if no such header exists.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
99 The current buffer, possibly narrowed, contains a single message."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
100 (save-excursion
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
101 (let ((case-fold-search t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
102 (inhibit-point-motion-hooks t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
103 (limit (rmail-header-get-limit))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
104 result start end)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
105
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
106 ;; Search for the given header. If found return it, otherwise
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
107 ;; nil.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
108 (goto-char (point-min))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
109 (if (re-search-forward (format "^%s: " header) limit t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
110
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
111 ;; Get the value, including extension parts.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
112 (progn
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
113 (setq start (point))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
114 (end-of-line)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
115 (setq result (buffer-substring start (point)))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
116 (while (progn
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
117 (forward-line 1)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
118 (looking-at "[ \t]+"))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
119 (setq start (match-end 0))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
120 (end-of-line)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
121 (setq result (format "%s %s" result
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
122 (buffer-substring start (point)))))))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
123 result)))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
124
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
125 (defun rmail-header-get-keywords ()
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
126 "Return the keywords in the current message.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
127 The current buffer, possibly narrowed, contains a single message."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
128
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
129 ;; Search for a keyword header and return the comma separated
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
130 ;; strings as a list.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
131 (let ((limit (rmail-header-get-limit)) result)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
132 (goto-char (point-min))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
133 (if (re-search-forward
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
134 (format "^%s: " rmail-header-keyword-header) limit t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
135 (save-excursion
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
136 (save-restriction
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
137 (narrow-to-region (point) (progn (end-of-line) (point)))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
138 (goto-char (point-min))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
139 (mail-parse-comma-list))))))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
140
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
141
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
142 (defun rmail-header-hide-headers ()
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
143 "Hide ignored headers. All others will be visible.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
144 The current buffer, possibly narrowed, contains a single message."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
145 (save-excursion
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
146 (let ((case-fold-search t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
147 (limit (rmail-header-get-limit))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
148 (inhibit-point-motion-hooks t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
149 start end visibility-p overlay overlay-list)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
150
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
151 ;; Record the display state as having headers hidden.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
152 (setq rmail-header-display-mode t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
153
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
154 ;; Clear the pool of overlays for reuse.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
155 (mapcar 'delete-overlay rmail-header-overlay-list)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
156 (setq overlay-list rmail-header-overlay-list)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
157
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
158 ;; Determine whether to use the displayed headers or the ignored
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
159 ;; headers.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
160 (if rmail-displayed-headers
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
161
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
162 ;; Set the visibility predicate function to ignore headers
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
163 ;; marked for display.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
164 (setq visibility-p 'rmail-header-show-displayed-p)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
165
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
166 ;; Set the visibility predicate function to hide ignored
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
167 ;; headers.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
168 (setq visibility-p 'rmail-header-hide-ignored-p))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
169
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
170 ;; Walk through all the headers marking the non-displayed
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
171 ;; headers as invisible.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
172 (goto-char (point-min))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
173 (while (re-search-forward "^[^ \t:]+[ :]" limit t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
174
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
175 ;; Determine if the current header needs to be hidden.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
176 (beginning-of-line)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
177 (if (funcall visibility-p)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
178
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
179 ;; It does. Make this header hidden by setting an overlay
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
180 ;; with both the invisible and intangible properties set.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
181 (progn
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
182 (setq start (point))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
183 (forward-line 1)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
184 (while (looking-at "[ \t]+")
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
185 (forward-line 1))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
186 (setq end (point))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
187
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
188 ;; Use one of the cleared, cached overlays until they
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
189 ;; run out.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
190 (if (car overlay-list)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
191
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
192 ;; Use a cached overlay.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
193 (progn
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
194 (setq overlay (car overlay-list)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
195 overlay-list (cdr overlay-list))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
196 (move-overlay overlay start end))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
197
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
198 ;; No overlay exists for this header. Create one and
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
199 ;; add it to the cache.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
200 (setq overlay (make-overlay start end)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
201 rmail-header-overlay-list
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
202 (append (list overlay)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
203 rmail-header-overlay-list))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
204 (overlay-put overlay 'invisible t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
205 (overlay-put overlay 'intangible t)))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
206
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
207 ;; It does not. Move point away from this header.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
208 (forward-line 1))))))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
209
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
210 (defun rmail-header-persist-attributes (attributes)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
211 "Save ATTRIBUTES in the Rmail BABYL header.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
212 The current buffer, possibly narrowed, contains a single message."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
213 (rmail-header-set-header rmail-header-attribute-header attributes))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
214
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
215 (defun rmail-header-remove-keyword (keyword)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
216 "..."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
217 ;; tbd
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
218 )
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
219
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
220 (defun rmail-header-set-header (header value)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
221 "Set the current value of HEADER to VALUE.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
222 The current buffer, possibly narrowed, contains a single message."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
223 (save-excursion
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
224
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
225 ;; Enable the buffer to be written, search for the header case
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
226 ;; insensitively, ignore intangibility and do not record these
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
227 ;; changes in the undo list.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
228 (let ((inhibit-read-only t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
229 (case-fold-search t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
230 (inhibit-point-motion-hooks t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
231 (buffer-undo-list t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
232 (limit (rmail-header-get-limit))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
233 start end)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
234
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
235 ;; Search for the given header. If found, then set it's value.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
236 ;; If not generate an error.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
237 (goto-char (point-min))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
238 (if (re-search-forward (format "^%s: " header) limit t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
239
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
240 ;; Kill the current value and replace it with the new.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
241 (progn
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
242 (setq start (point))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
243 (while (progn
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
244 (forward-line 1)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
245 (looking-at "[ \t]+")))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
246 (setq end (point-marker))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
247 (goto-char start)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
248 (insert-and-inherit value)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
249 (kill-region (point) (1- (marker-position end))))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
250 ;; Generate an error since the header does not exist.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
251 (error "Header %s not found." header)))))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
252
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
253 (defun rmail-header-show-headers ()
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
254 "Show all headers.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
255 The current buffer, possibly narrowed, contains a single message."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
256 ;; Remove all the overlays used to control hiding headers.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
257 (mapcar 'delete-overlay rmail-header-overlay-list)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
258 (setq rmail-header-display-mode nil))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
259
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
260 (defun rmail-header-toggle-visibility (&optional arg)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
261 "Toggle the visibility of the ignored headers if ARG is nil.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
262 Hide the ignored headers if ARG is greater than 0, otherwise show the
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
263 ignored headers. The current buffer, possibly narrowed, contains a
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
264 single message."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
265 (cond ((eq arg nil)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
266 (if rmail-header-display-mode
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
267 (rmail-header-show-headers)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
268 (rmail-header-hide-headers)))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
269 ((or (eq arg t) (> arg 0))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
270 (rmail-header-hide-headers))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
271 (t (rmail-header-show-headers))))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
272
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
273 (defun rmail-header-hide-ignored-p ()
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
274 "Test that the header is one of the headers marked to be ignored."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
275 (looking-at rmail-ignored-headers))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
276
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
277 (defun rmail-header-show-displayed-p ()
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
278 "Test that the header is not one of the headers marked for display."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
279 (not (looking-at rmail-displayed-headers)))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
280
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
281 (provide 'rmailhdr)