annotate lisp/mail/rmailhdr.el @ 88218:6860ecbf3db6

*** empty log message ***
author Alex Schroeder <alex@gnu.org>
date Wed, 18 Jan 2006 22:33:59 +0000
parents 83e39e1cce60
children 18b22fde84db
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 ;; 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
30
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
31 (eval-when-compile
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
32 (require 'mail-utils))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
33
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
34 (defconst rmail-header-attribute-header "X-BABYL-V6-ATTRIBUTES"
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
35 "The header that persists the Rmail attribute data.")
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
36
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
37 (defconst rmail-header-keyword-header "X-BABYL-V6-KEYWORDS"
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
38 "The header that persists the Rmail keyword data.")
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
39
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
40 (defvar rmail-header-overlay-list nil
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
41 "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
42
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
43 (defvar rmail-header-display-mode nil
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
44 "Records the current header display mode.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
45 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
46
88215
83e39e1cce60 (rmail-header-get-limit): Rewrote macro as simple
Alex Schroeder <alex@gnu.org>
parents: 88124
diff changeset
47 (defun rmail-header-get-limit ()
83e39e1cce60 (rmail-header-get-limit): Rewrote macro as simple
Alex Schroeder <alex@gnu.org>
parents: 88124
diff changeset
48 "Return the end of the headers."
83e39e1cce60 (rmail-header-get-limit): Rewrote macro as simple
Alex Schroeder <alex@gnu.org>
parents: 88124
diff changeset
49 (goto-char (point-min))
83e39e1cce60 (rmail-header-get-limit): Rewrote macro as simple
Alex Schroeder <alex@gnu.org>
parents: 88124
diff changeset
50 (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
51 (1- (point))
83e39e1cce60 (rmail-header-get-limit): Rewrote macro as simple
Alex Schroeder <alex@gnu.org>
parents: 88124
diff changeset
52 (error "Invalid message format.")))
88124
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
53
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
54 ;;; The following functions are presented alphabetically ordered by
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
55 ;;; name.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
56
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
57 (defun rmail-header-add-header (header value)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
58 "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
59 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
60 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
61 instead."
88124
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
62 (save-excursion
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
63 (let* ((inhibit-read-only t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
64 (case-fold-search t)
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
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
85 ;; Some keywords exist. Now search for the specific keyword.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
86 (let ((start (point))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
87 (end (progn (end-of-line) (point))))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
88 (if (re-search-forward (concat "\\(" keyword ",\\|" keyword "$\\)"))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
89 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 (defun rmail-header-get-header (header)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
92 "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
93 The current buffer, possibly narrowed, contains a single message."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
94 (save-excursion
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
95 (let ((case-fold-search t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
96 (inhibit-point-motion-hooks t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
97 (limit (rmail-header-get-limit))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
98 result start end)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
99 ;; Search for the given header. If found return it, otherwise
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
100 ;; nil.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
101 (goto-char (point-min))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
102 (if (re-search-forward (format "^%s: " header) limit t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
103
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
104 ;; Get the value, including extension parts.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
105 (progn
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
106 (setq start (point))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
107 (end-of-line)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
108 (setq result (buffer-substring start (point)))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
109 (while (progn
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
110 (forward-line 1)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
111 (looking-at "[ \t]+"))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
112 (setq start (match-end 0))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
113 (end-of-line)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
114 (setq result (format "%s %s" result
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
115 (buffer-substring start (point)))))))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
116 result)))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
117
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
118 (defun rmail-header-get-keywords ()
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
119 "Return the keywords in the current message.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
120 The current buffer, possibly narrowed, contains a single message."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
121
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
122 ;; Search for a keyword header and return the comma separated
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
123 ;; strings as a list.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
124 (let ((limit (rmail-header-get-limit)) result)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
125 (goto-char (point-min))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
126 (if (re-search-forward
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
127 (format "^%s: " rmail-header-keyword-header) limit t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
128 (save-excursion
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
129 (save-restriction
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
130 (narrow-to-region (point) (progn (end-of-line) (point)))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
131 (goto-char (point-min))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
132 (mail-parse-comma-list))))))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
133
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
134
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
135 (defun rmail-header-hide-headers ()
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
136 "Hide ignored headers. All others will be visible.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
137 The current buffer, possibly narrowed, contains a single message."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
138 (save-excursion
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
139 (let ((case-fold-search t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
140 (limit (rmail-header-get-limit))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
141 (inhibit-point-motion-hooks t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
142 start end visibility-p overlay overlay-list)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
143
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
144 ;; Record the display state as having headers hidden.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
145 (setq rmail-header-display-mode t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
146
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
147 ;; Clear the pool of overlays for reuse.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
148 (mapcar 'delete-overlay rmail-header-overlay-list)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
149 (setq overlay-list rmail-header-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 ;; Determine whether to use the displayed headers or the ignored
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
152 ;; headers.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
153 (if rmail-displayed-headers
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
154
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
155 ;; Set the visibility predicate function to ignore headers
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
156 ;; marked for display.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
157 (setq visibility-p 'rmail-header-show-displayed-p)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
158
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
159 ;; Set the visibility predicate function to hide ignored
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
160 ;; headers.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
161 (setq visibility-p 'rmail-header-hide-ignored-p))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
162
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
163 ;; Walk through all the headers marking the non-displayed
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
164 ;; headers as invisible.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
165 (goto-char (point-min))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
166 (while (re-search-forward "^[^ \t:]+[ :]" limit t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
167
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
168 ;; Determine if the current header needs to be hidden.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
169 (beginning-of-line)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
170 (if (funcall visibility-p)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
171
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
172 ;; It does. Make this header hidden by setting an overlay
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
173 ;; with both the invisible and intangible properties set.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
174 (progn
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
175 (setq start (point))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
176 (forward-line 1)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
177 (while (looking-at "[ \t]+")
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
178 (forward-line 1))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
179 (setq end (point))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
180
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
181 ;; Use one of the cleared, cached overlays until they
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
182 ;; run out.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
183 (if (car overlay-list)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
184
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
185 ;; Use a cached overlay.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
186 (progn
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
187 (setq overlay (car overlay-list)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
188 overlay-list (cdr overlay-list))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
189 (move-overlay overlay start end))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
190
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
191 ;; No overlay exists for this header. Create one and
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
192 ;; add it to the cache.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
193 (setq overlay (make-overlay start end)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
194 rmail-header-overlay-list
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
195 (append (list overlay)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
196 rmail-header-overlay-list))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
197 (overlay-put overlay 'invisible t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
198 (overlay-put overlay 'intangible t)))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
199
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
200 ;; It does not. Move point away from this header.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
201 (forward-line 1))))))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
202
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
203 (defun rmail-header-persist-attributes (attributes)
88215
83e39e1cce60 (rmail-header-get-limit): Rewrote macro as simple
Alex Schroeder <alex@gnu.org>
parents: 88124
diff changeset
204 "Save ATTRIBUTES in the Rmail BABYL header."
88124
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
205 (rmail-header-set-header rmail-header-attribute-header attributes))
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 (defun rmail-header-set-header (header value)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
208 "Set the current value of HEADER to VALUE.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
209 The current buffer, possibly narrowed, contains a single message."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
210 (save-excursion
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
211
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
212 ;; 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
213 ;; insensitively, ignore intangibility and do not record these
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
214 ;; changes in the undo list.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
215 (let ((inhibit-read-only t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
216 (case-fold-search t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
217 (inhibit-point-motion-hooks t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
218 (buffer-undo-list t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
219 (limit (rmail-header-get-limit))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
220 start end)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
221
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
222 ;; 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
223 ;; If not generate an error.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
224 (goto-char (point-min))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
225 (if (re-search-forward (format "^%s: " header) limit t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
226
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
227 ;; Kill the current value and replace it with the new.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
228 (progn
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
229 (setq start (point))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
230 (while (progn
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
231 (forward-line 1)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
232 (looking-at "[ \t]+")))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
233 (setq end (point-marker))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
234 (goto-char start)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
235 (insert-and-inherit value)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
236 (kill-region (point) (1- (marker-position end))))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
237 ;; Generate an error since the header does not exist.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
238 (error "Header %s not found." header)))))
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 (defun rmail-header-show-headers ()
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
241 "Show all headers.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
242 The current buffer, possibly narrowed, contains a single message."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
243 ;; Remove all the overlays used to control hiding headers.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
244 (mapcar 'delete-overlay rmail-header-overlay-list)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
245 (setq rmail-header-display-mode nil))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
246
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
247 (defun rmail-header-toggle-visibility (&optional arg)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
248 "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
249 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
250 ignored headers. The current buffer, possibly narrowed, contains a
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
251 single message."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
252 (cond ((eq arg nil)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
253 (if rmail-header-display-mode
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
254 (rmail-header-show-headers)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
255 (rmail-header-hide-headers)))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
256 ((or (eq arg t) (> arg 0))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
257 (rmail-header-hide-headers))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
258 (t (rmail-header-show-headers))))
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-hide-ignored-p ()
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
261 "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
262 (looking-at rmail-ignored-headers))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
263
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
264 (defun rmail-header-show-displayed-p ()
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
265 "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
266 (not (looking-at rmail-displayed-headers)))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
267
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
268 (provide 'rmailhdr)