annotate lisp/mail/rmailhdr.el @ 88286:32c6e924fc14

*** empty log message ***
author Alex Schroeder <alex@gnu.org>
date Mon, 23 Jan 2006 16:54:26 +0000
parents b6d2078cce14
children e664e2e2ae90
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
88215
83e39e1cce60 (rmail-header-get-limit): Rewrote macro as simple
Alex Schroeder <alex@gnu.org>
parents: 88124
diff changeset
3 ;; Copyright (C) 2002, 2006 Free Software Foundation, Inc.
88124
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
4
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
5 ;; Maintainer: FSF
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
6 ;; Keywords: mail
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
7
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
9
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
10 ;; 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
11 ;; 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
12 ;; 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
13 ;; any later version.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
14
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
15 ;; 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
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
18 ;; GNU General Public License for more details.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
19
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
20 ;; 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
21 ;; 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
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
23 ;; Boston, MA 02111-1307, USA.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
24
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
25 ;;; Commentary:
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
26
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
27 ;;; Code:
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
28
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
29 (eval-when-compile
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
30 (require 'mail-utils))
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 (defconst rmail-header-attribute-header "X-BABYL-V6-ATTRIBUTES"
88257
b6d2078cce14 (rmail-header-attribute-header)
Alex Schroeder <alex@gnu.org>
parents: 88224
diff changeset
33 "The header that stores the Rmail attribute data.")
88124
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-keyword-header "X-BABYL-V6-KEYWORDS"
88257
b6d2078cce14 (rmail-header-attribute-header)
Alex Schroeder <alex@gnu.org>
parents: 88224
diff changeset
36 "The header that stores the Rmail keyword data.")
88124
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 (defvar rmail-header-overlay-list nil
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
39 "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
40
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
41 (defvar rmail-header-display-mode nil
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
42 "Records the current header display mode.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
43 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
44
88215
83e39e1cce60 (rmail-header-get-limit): Rewrote macro as simple
Alex Schroeder <alex@gnu.org>
parents: 88124
diff changeset
45 (defun rmail-header-get-limit ()
88257
b6d2078cce14 (rmail-header-attribute-header)
Alex Schroeder <alex@gnu.org>
parents: 88224
diff changeset
46 "Return the end of the headers.
b6d2078cce14 (rmail-header-attribute-header)
Alex Schroeder <alex@gnu.org>
parents: 88224
diff changeset
47 The current buffer must show one message. If you want to narrow
b6d2078cce14 (rmail-header-attribute-header)
Alex Schroeder <alex@gnu.org>
parents: 88224
diff changeset
48 to the headers of a mail by number, use `rmail-narrow-to-header'
b6d2078cce14 (rmail-header-attribute-header)
Alex Schroeder <alex@gnu.org>
parents: 88224
diff changeset
49 instead."
88215
83e39e1cce60 (rmail-header-get-limit): Rewrote macro as simple
Alex Schroeder <alex@gnu.org>
parents: 88124
diff changeset
50 (goto-char (point-min))
83e39e1cce60 (rmail-header-get-limit): Rewrote macro as simple
Alex Schroeder <alex@gnu.org>
parents: 88124
diff changeset
51 (if (search-forward "\n\n" nil t)
83e39e1cce60 (rmail-header-get-limit): Rewrote macro as simple
Alex Schroeder <alex@gnu.org>
parents: 88124
diff changeset
52 (1- (point))
83e39e1cce60 (rmail-header-get-limit): Rewrote macro as simple
Alex Schroeder <alex@gnu.org>
parents: 88124
diff changeset
53 (error "Invalid message format.")))
88124
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 (defun rmail-header-add-header (header value)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
56 "Add HEADER to the list of headers and associate VALUE with it.
88215
83e39e1cce60 (rmail-header-get-limit): Rewrote macro as simple
Alex Schroeder <alex@gnu.org>
parents: 88124
diff changeset
57 The current buffer, possibly narrowed, contains a single message.
83e39e1cce60 (rmail-header-get-limit): Rewrote macro as simple
Alex Schroeder <alex@gnu.org>
parents: 88124
diff changeset
58 If VALUE is nil or the empty string, the header is removed
83e39e1cce60 (rmail-header-get-limit): Rewrote macro as simple
Alex Schroeder <alex@gnu.org>
parents: 88124
diff changeset
59 instead."
88124
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
60 (save-excursion
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
61 (let* ((inhibit-read-only t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
62 (case-fold-search t)
88257
b6d2078cce14 (rmail-header-attribute-header)
Alex Schroeder <alex@gnu.org>
parents: 88224
diff changeset
63 (inhibit-point-motion-hooks t)
b6d2078cce14 (rmail-header-attribute-header)
Alex Schroeder <alex@gnu.org>
parents: 88224
diff changeset
64 (buffer-undo-list t)
88124
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
65 (limit (rmail-header-get-limit))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
66 start end)
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)
88215
83e39e1cce60 (rmail-header-get-limit): Rewrote macro as simple
Alex Schroeder <alex@gnu.org>
parents: 88124
diff changeset
71 (let ((start (match-beginning 0)))
83e39e1cce60 (rmail-header-get-limit): Rewrote macro as simple
Alex Schroeder <alex@gnu.org>
parents: 88124
diff changeset
72 (re-search-forward "\n[^ \t]")
83e39e1cce60 (rmail-header-get-limit): Rewrote macro as simple
Alex Schroeder <alex@gnu.org>
parents: 88124
diff changeset
73 (goto-char limit)
83e39e1cce60 (rmail-header-get-limit): Rewrote macro as simple
Alex Schroeder <alex@gnu.org>
parents: 88124
diff changeset
74 (kill-region start (1+ (match-beginning 0))))
88124
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
75 (goto-char limit))
88215
83e39e1cce60 (rmail-header-get-limit): Rewrote macro as simple
Alex Schroeder <alex@gnu.org>
parents: 88124
diff changeset
76 (when (> (length value) 0)
83e39e1cce60 (rmail-header-get-limit): Rewrote macro as simple
Alex Schroeder <alex@gnu.org>
parents: 88124
diff changeset
77 (insert header ": " value "\n")))))
88124
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
78
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
79 (defun rmail-header-contains-keyword-p (keyword)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
80 "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
81 (let ((limit (rmail-header-get-limit)))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
82 (goto-char (point-min))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
83 (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
84 ;; Some keywords exist. Now search for the specific keyword.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
85 (let ((start (point))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
86 (end (progn (end-of-line) (point))))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
87 (if (re-search-forward (concat "\\(" keyword ",\\|" keyword "$\\)"))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
88 t)))))
88221
18b22fde84db (rmail-header-get-header): Rewrite to be a
Henrik Enberg <henrik.enberg@telia.com>
parents: 88215
diff changeset
89
88124
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
90 (defun rmail-header-get-header (header)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
91 "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
92 The current buffer, possibly narrowed, contains a single message."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
93 (save-excursion
88221
18b22fde84db (rmail-header-get-header): Rewrite to be a
Henrik Enberg <henrik.enberg@telia.com>
parents: 88215
diff changeset
94 (save-restriction
18b22fde84db (rmail-header-get-header): Rewrite to be a
Henrik Enberg <henrik.enberg@telia.com>
parents: 88215
diff changeset
95 (let ((limit (rmail-header-get-limit)))
18b22fde84db (rmail-header-get-header): Rewrite to be a
Henrik Enberg <henrik.enberg@telia.com>
parents: 88215
diff changeset
96 (narrow-to-region (point-min) limit)
18b22fde84db (rmail-header-get-header): Rewrite to be a
Henrik Enberg <henrik.enberg@telia.com>
parents: 88215
diff changeset
97 (mail-fetch-field header)))))
88124
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
98
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
99 (defun rmail-header-get-keywords ()
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
100 "Return the keywords in the current message.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
101 The current buffer, possibly narrowed, contains a single message."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
102 ;; Search for a keyword header and return the comma separated
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
103 ;; strings as a list.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
104 (let ((limit (rmail-header-get-limit)) result)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
105 (goto-char (point-min))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
106 (if (re-search-forward
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
107 (format "^%s: " rmail-header-keyword-header) limit t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
108 (save-excursion
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
109 (save-restriction
88221
18b22fde84db (rmail-header-get-header): Rewrite to be a
Henrik Enberg <henrik.enberg@telia.com>
parents: 88215
diff changeset
110 (narrow-to-region (point) (line-end-position))
88124
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
111 (goto-char (point-min))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
112 (mail-parse-comma-list))))))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
113
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
114 (defun rmail-header-hide-headers ()
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
115 "Hide ignored headers. All others will be visible.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
116 The current buffer, possibly narrowed, contains a single message."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
117 (save-excursion
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
118 (let ((case-fold-search t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
119 (limit (rmail-header-get-limit))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
120 (inhibit-point-motion-hooks t)
88224
7c074ae71bd8 (rmail-header-hide-headers): Simplify.
Henrik Enberg <henrik.enberg@telia.com>
parents: 88221
diff changeset
121 ;; start end
7c074ae71bd8 (rmail-header-hide-headers): Simplify.
Henrik Enberg <henrik.enberg@telia.com>
parents: 88221
diff changeset
122 visibility-p
7c074ae71bd8 (rmail-header-hide-headers): Simplify.
Henrik Enberg <henrik.enberg@telia.com>
parents: 88221
diff changeset
123 ;;overlay
7c074ae71bd8 (rmail-header-hide-headers): Simplify.
Henrik Enberg <henrik.enberg@telia.com>
parents: 88221
diff changeset
124 overlay-list)
88124
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
125 ;; Record the display state as having headers hidden.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
126 (setq rmail-header-display-mode t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
127 ;; Clear the pool of overlays for reuse.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
128 (mapcar 'delete-overlay rmail-header-overlay-list)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
129 (setq overlay-list rmail-header-overlay-list)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
130 ;; Determine whether to use the displayed headers or the ignored
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
131 ;; headers.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
132 (if rmail-displayed-headers
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
133 ;; Set the visibility predicate function to ignore headers
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
134 ;; marked for display.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
135 (setq visibility-p 'rmail-header-show-displayed-p)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
136 ;; Set the visibility predicate function to hide ignored
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
137 ;; headers.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
138 (setq visibility-p 'rmail-header-hide-ignored-p))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
139 ;; Walk through all the headers marking the non-displayed
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
140 ;; headers as invisible.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
141 (goto-char (point-min))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
142 (while (re-search-forward "^[^ \t:]+[ :]" limit t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
143 ;; Determine if the current header needs to be hidden.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
144 (beginning-of-line)
88224
7c074ae71bd8 (rmail-header-hide-headers): Simplify.
Henrik Enberg <henrik.enberg@telia.com>
parents: 88221
diff changeset
145 (if (not (funcall visibility-p))
7c074ae71bd8 (rmail-header-hide-headers): Simplify.
Henrik Enberg <henrik.enberg@telia.com>
parents: 88221
diff changeset
146 ;; It does not. Move point away from this header.
7c074ae71bd8 (rmail-header-hide-headers): Simplify.
Henrik Enberg <henrik.enberg@telia.com>
parents: 88221
diff changeset
147 (forward-line 1)
7c074ae71bd8 (rmail-header-hide-headers): Simplify.
Henrik Enberg <henrik.enberg@telia.com>
parents: 88221
diff changeset
148 ;; It does. Make this header hidden by setting an overlay
7c074ae71bd8 (rmail-header-hide-headers): Simplify.
Henrik Enberg <henrik.enberg@telia.com>
parents: 88221
diff changeset
149 ;; with both the invisible and intangible properties set.
7c074ae71bd8 (rmail-header-hide-headers): Simplify.
Henrik Enberg <henrik.enberg@telia.com>
parents: 88221
diff changeset
150 (let ((start (point))
7c074ae71bd8 (rmail-header-hide-headers): Simplify.
Henrik Enberg <henrik.enberg@telia.com>
parents: 88221
diff changeset
151 overlay)
7c074ae71bd8 (rmail-header-hide-headers): Simplify.
Henrik Enberg <henrik.enberg@telia.com>
parents: 88221
diff changeset
152 ;; Move to end and pick upp any continuation lines on folded
7c074ae71bd8 (rmail-header-hide-headers): Simplify.
Henrik Enberg <henrik.enberg@telia.com>
parents: 88221
diff changeset
153 ;; headers.
7c074ae71bd8 (rmail-header-hide-headers): Simplify.
Henrik Enberg <henrik.enberg@telia.com>
parents: 88221
diff changeset
154 (forward-line 1)
7c074ae71bd8 (rmail-header-hide-headers): Simplify.
Henrik Enberg <henrik.enberg@telia.com>
parents: 88221
diff changeset
155 (while (looking-at "[ \t]+")
7c074ae71bd8 (rmail-header-hide-headers): Simplify.
Henrik Enberg <henrik.enberg@telia.com>
parents: 88221
diff changeset
156 (forward-line 1))
7c074ae71bd8 (rmail-header-hide-headers): Simplify.
Henrik Enberg <henrik.enberg@telia.com>
parents: 88221
diff changeset
157 ;; (setq end (point))
7c074ae71bd8 (rmail-header-hide-headers): Simplify.
Henrik Enberg <henrik.enberg@telia.com>
parents: 88221
diff changeset
158 ;; Use one of the cleared, cached overlays until they
7c074ae71bd8 (rmail-header-hide-headers): Simplify.
Henrik Enberg <henrik.enberg@telia.com>
parents: 88221
diff changeset
159 ;; run out.
7c074ae71bd8 (rmail-header-hide-headers): Simplify.
Henrik Enberg <henrik.enberg@telia.com>
parents: 88221
diff changeset
160 (if (car overlay-list)
7c074ae71bd8 (rmail-header-hide-headers): Simplify.
Henrik Enberg <henrik.enberg@telia.com>
parents: 88221
diff changeset
161 ;; Use a cached overlay.
7c074ae71bd8 (rmail-header-hide-headers): Simplify.
Henrik Enberg <henrik.enberg@telia.com>
parents: 88221
diff changeset
162 (progn
7c074ae71bd8 (rmail-header-hide-headers): Simplify.
Henrik Enberg <henrik.enberg@telia.com>
parents: 88221
diff changeset
163 (setq overlay (car overlay-list)
7c074ae71bd8 (rmail-header-hide-headers): Simplify.
Henrik Enberg <henrik.enberg@telia.com>
parents: 88221
diff changeset
164 overlay-list (cdr overlay-list))
7c074ae71bd8 (rmail-header-hide-headers): Simplify.
Henrik Enberg <henrik.enberg@telia.com>
parents: 88221
diff changeset
165 (move-overlay overlay start (point)))
7c074ae71bd8 (rmail-header-hide-headers): Simplify.
Henrik Enberg <henrik.enberg@telia.com>
parents: 88221
diff changeset
166 ;; No overlay exists for this header. Create one and
7c074ae71bd8 (rmail-header-hide-headers): Simplify.
Henrik Enberg <henrik.enberg@telia.com>
parents: 88221
diff changeset
167 ;; add it to the cache.
7c074ae71bd8 (rmail-header-hide-headers): Simplify.
Henrik Enberg <henrik.enberg@telia.com>
parents: 88221
diff changeset
168 (setq overlay (make-overlay start (point)))
7c074ae71bd8 (rmail-header-hide-headers): Simplify.
Henrik Enberg <henrik.enberg@telia.com>
parents: 88221
diff changeset
169 (overlay-put overlay 'invisible t)
7c074ae71bd8 (rmail-header-hide-headers): Simplify.
Henrik Enberg <henrik.enberg@telia.com>
parents: 88221
diff changeset
170 (overlay-put overlay 'intangible t)
7c074ae71bd8 (rmail-header-hide-headers): Simplify.
Henrik Enberg <henrik.enberg@telia.com>
parents: 88221
diff changeset
171 (push overlay rmail-header-overlay-list))))))))
88124
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
172
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
173 (defun rmail-header-show-headers ()
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
174 "Show all headers.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
175 The current buffer, possibly narrowed, contains a single message."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
176 ;; Remove all the overlays used to control hiding headers.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
177 (mapcar 'delete-overlay rmail-header-overlay-list)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
178 (setq rmail-header-display-mode nil))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
179
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
180 (defun rmail-header-toggle-visibility (&optional arg)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
181 "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
182 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
183 ignored headers. The current buffer, possibly narrowed, contains a
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
184 single message."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
185 (cond ((eq arg nil)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
186 (if rmail-header-display-mode
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
187 (rmail-header-show-headers)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
188 (rmail-header-hide-headers)))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
189 ((or (eq arg t) (> arg 0))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
190 (rmail-header-hide-headers))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
191 (t (rmail-header-show-headers))))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
192
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
193 (defun rmail-header-hide-ignored-p ()
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
194 "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
195 (looking-at rmail-ignored-headers))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
196
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
197 (defun rmail-header-show-displayed-p ()
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
198 "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
199 (not (looking-at rmail-displayed-headers)))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
200
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
201 (provide 'rmailhdr)
88224
7c074ae71bd8 (rmail-header-hide-headers): Simplify.
Henrik Enberg <henrik.enberg@telia.com>
parents: 88221
diff changeset
202
7c074ae71bd8 (rmail-header-hide-headers): Simplify.
Henrik Enberg <henrik.enberg@telia.com>
parents: 88221
diff changeset
203 ;;; rmailhdr.el ends here