annotate lisp/mail/rmaildesc.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 1cb8cab175ad
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 ;;; rmaildesc.el --- Low level message descriptor library for Rmail.
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 ;;; This package provides low level functions for tracking messages in Rmail.
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 ;;; Code:
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 ;; Written by Paul Reilly as part of moving BABYL to mbox format.
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 (eval-when-compile
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
35 (require 'rmailhdr)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
36 (require 'mail-utils))
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-desc-attributes nil
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
39 "A private variable providing temporary access to message attributes.")
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-desc-delete-callback nil
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
42 "A function pointer called after a message has been deleted.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
43 It expects one argument --- the message number.")
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
44
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
45 (defvar rmail-desc-vector nil
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
46 "A vector of message descriptors.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
47 A message descriptor contains data formatted as follows:
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
48
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
49 (START ATTRIBUTES KEYWORDS DATE LINE-COUNT SENDER SUBJECT)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
50
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
51 where
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
52
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
53 START is a marker at the beginning of the header
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 ATTRIBUTES is a string where each character encodes an
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
56 attribute. A hyphen (-) indicates that the attribute is not
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
57 set:
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
58
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
59 ANSWERED The message has been replied to (A).
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
60 DELETED The message has been marked for deletion (D).
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
61 EDITED The message has been edited (E).
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
62 FILED The message has been filed (F).
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
63 RESENT The message has been resent (R).
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
64 STORED The message has been saved to a file (S).
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
65 UNSEEN The message has not been read (-).
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 KEYWORDS is a list of User defined label strings.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
68
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
69 DATE is a list of strings describing the message date:
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
70
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
71 DAY-OF-WEEK Mon, Sun, etc.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
72 DAY-NUMBER 9, 13, 15, etc.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
73 MONTH Feb, Jun, etc.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
74 YEAR 2001, 2002, etc.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
75 TIME 12:03:25, etc.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
76
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
77 LINE-COUNT is the number of lines in the message.
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 SENDER is the name of the User sending the message.
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 SUBJECT is the subject header, cached to support fast summary line generation.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
82 ")
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
83 (put 'rmail-desc-vector 'permanent-local 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 ;;;; Constants supporting message vector processing.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
86
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
87 ;;; Message component indexes.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
88
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
89 (defconst rmail-desc-beg-index 0
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
90 "The message descriptor element index for the start of the message text.")
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
91
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
92 (defconst rmail-desc-attrs-index 1
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
93 "The message descriptor element index for the attributes string.")
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
94
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
95 (defconst rmail-desc-keywords-index 2
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
96 "The message descriptor element index for the User defined labels.")
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
97
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
98 (defconst rmail-desc-date-index 3
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
99 "The message descriptor element index for the message date information.")
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
100
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
101 (defconst rmail-desc-line-count-index 4
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
102 "The message descriptor element index for the message line count.")
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 (defconst rmail-desc-sender-index 5
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
105 "The message descriptor element index for the message line count.")
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
106
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
107 (defconst rmail-desc-subject-index 6
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
108 "The message descriptor element index for the message line count.")
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
109
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
110 ;;; Attribute indexes
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
111
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
112 (defconst rmail-desc-answered-index 0
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
113 "The index for the `answered' attribute.")
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
114
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
115 (defconst rmail-desc-deleted-index 1
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
116 "The index for the `deleted' attribute.")
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 (defconst rmail-desc-edited-index 2
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
119 "The index for the `edited' attirute.")
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
120
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
121 (defconst rmail-desc-filed-index 3
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
122 "The index for the `filed' attribute.")
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
123
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
124 (defconst rmail-desc-resent-index 4
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
125 "The index for the `resent' attribute.")
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
126
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
127 (defconst rmail-desc-stored-index 5
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
128 "The index for the `stored' attribute.")
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
129
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
130 (defconst rmail-desc-unseen-index 6
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
131 "The index for the `unseen' attribute.")
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
132
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
133 (defconst rmail-desc-attr-code-index 0
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
134 "The index for the attibute code.")
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
135
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
136 (defconst rmail-desc-attr-keyword-index 1
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
137 "The index for the attribute keyword.")
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
138
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
139 (defconst rmail-desc-attr-summary-offset-index 2
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
140 "The index for the attribute offset in a summary buffer.")
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 (defconst rmail-desc-attr-alist
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
143 (list (cons rmail-desc-answered-index (list ?A "answered" 1))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
144 (cons rmail-desc-deleted-index (list ?D "deleted" 0))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
145 (cons rmail-desc-edited-index (list ?E "edited" 3))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
146 (cons rmail-desc-filed-index (list ?F "filed" 2))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
147 (cons rmail-desc-resent-index (list ?R "resent" nil))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
148 (cons rmail-desc-stored-index (list ?S "stored" 4))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
149 (cons rmail-desc-unseen-index (list ? "unseen" 0)))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
150 "An alist mapping an attribute to a keycode, keyword and summary offset.")
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
151
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
152 (defconst rmail-desc-attr-index-map
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
153 (list (cons "answered" rmail-desc-answered-index)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
154 (cons "deleted" rmail-desc-deleted-index)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
155 (cons "edited" rmail-desc-edited-index)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
156 (cons "filed" rmail-desc-filed-index)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
157 (cons "resent" rmail-desc-resent-index)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
158 (cons "stored" rmail-desc-stored-index)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
159 (cons "unseen" rmail-desc-unseen-index)))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
160
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
161 ;;; Date indexes
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 (defconst rmail-desc-date-day-of-week-index 0
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
164 "The DAY-OF-WEEK index into the list of date information.")
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 (defconst rmail-desc-date-day-number-index 1
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
167 "The DAY-NUMBER index into the list of date information.")
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
168
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
169 (defconst rmail-desc-date-month-index 2
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
170 "The MONTH index into the list of date information.")
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 (defconst rmail-desc-date-year-index 3
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
173 "The YEAR index into the list of date information.")
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 (defconst rmail-desc-date-time-index 4
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
176 "The TIME index into the list of date information.")
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
177
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
178 (defsubst rmail-desc-get-descriptor (n)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
179 "Return a descriptor for message N.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
180 N is 1 based, i.e. the first message number is 1."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
181 (aref rmail-desc-vector (1- n)))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
182
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
183 (defsubst rmail-desc-get-start (n)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
184 "Return the position of the start of message N."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
185 (marker-position
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
186 (nth rmail-desc-beg-index (rmail-desc-get-descriptor n))))
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 (defun rmail-desc-get-end (n)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
189 "Return the position of the end of message N."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
190 (if (= n (length rmail-desc-vector))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
191 (save-restriction
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
192 (widen)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
193 (point-max))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
194 (rmail-desc-get-start (1+ n))))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
195
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
196 (defun rmail-desc-add-descriptors (descriptor-list)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
197 "Append DESCRIPTOR-LIST to the Rmail message descriptor vector."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
198 (setq rmail-desc-vector
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
199 (vconcat rmail-desc-vector descriptor-list)))
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 (defun rmail-desc-add-keyword (keyword n)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
202 "Add KEYWORD to the list of keywords for message N.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
203 The current buffer, likely narrowed, contains message N."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
204
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
205 ;; Append KEYWORD to the descriptor for message N.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
206 (save-excursion
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
207 (save-restriction
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
208 (let ((keyword-list (rmail-desc-get-keyword-list n))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
209 (display-state (rmail-desc-get-header-display-state n)))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
210 (rmail-header-show-headers)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
211 (if keyword-list
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
212
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
213 ;; ??? Don't use setcdr for this.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
214 ;; Just add it to the front of the list
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
215 ;; and store the updated list back in its proper place.
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 ;; Append the string to the list unless it already is there.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
218 (unless (member-ignore-case keyword keyword-list)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
219 (setcdr keyword-list (append (cdr keyword-list) (list keyword)))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
220
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
221 ;; Persist the label for this message.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
222 (rmail-header-add-header
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
223 rmail-header-keyword-header
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
224 (concat (rmail-header-get-header rmail-header-keyword-header)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
225 "," keyword)))
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 ;; Create the initial keyword list as well as the keyword header
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
228 ;; and persist the header.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
229 (setq keyword-list
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
230 (nthcdr rmail-desc-keywords-index (rmail-desc-get-descriptor n)))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
231 (setcar keyword-list (list keyword))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
232 (rmail-header-add-header rmail-header-keyword-header keyword))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
233 (rmail-header-toggle-visibility display-state)))))
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 (defun rmail-desc-remove-keyword (keyword n)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
236 "Remove KEYWORD from the list of keywords for message N.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
237 The current buffer, likely narrowed, contains message N."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
238
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
239 ;; Remove KEYWORD from the descriptor for message N.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
240 (save-excursion
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
241 (save-restriction
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
242 (let ((desc-list (nthcdr rmail-desc-keywords-index
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
243 (rmail-desc-get-descriptor n)))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
244 (display-state (rmail-desc-get-header-display-state n)))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
245
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
246 ;; Remove the keyword from the descriptor.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
247 (setcar desc-list (delete keyword (car desc-list)))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
248
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
249 ;; Persist the change by removing the keyword for the keywords
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
250 ;; header and restore the display state.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
251 (rmail-header-show-headers)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
252 (rmail-header-delete-keyword keyword)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
253 (rmail-header-toggle-visibility display-state)))))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
254
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
255 (defun rmail-desc-attr-p (attr-index n)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
256 "Return the state of the the attribute denoted by ATTR-INDEX in
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
257 message N."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
258 (let ((attrs (nth rmail-desc-attrs-index
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
259 (rmail-desc-get-descriptor n))))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
260 (not (equal "-" (substring attrs attr-index (1+ attr-index))))))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
261
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
262 (defun rmail-desc-clear-descriptors ()
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
263 "Clear the Rmail message vector of all messages."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
264 (setq rmail-desc-vector nil))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
265
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
266 (defun rmail-desc-deleted-p (n)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
267 "Return non-nil if message N is marked for deletion."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
268 (rmail-desc-attr-p rmail-desc-deleted-index n))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
269
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
270 (defun rmail-desc-delete-maybe (n)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
271 "Determine if message N is marked for deletion. If so then delete it.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
272 Return t if the message is deleted, nil if not."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
273 (if (rmail-desc-deleted-p n)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
274 (progn
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
275 (rmail-desc-delete n)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
276 t)))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
277
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
278 (defun rmail-desc-delete (n)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
279 "Remove message N from the Rmail buffer and from the descriptor vector."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
280 (save-excursion
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
281 (save-restriction
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
282 ;; Enable the buffer to be written, ignore intangibility and do
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
283 ;; not record these changes in the undo list.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
284 (let ((inhibit-read-only t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
285 (inhibit-point-motion-hooks t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
286 (buffer-undo-list t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
287 start end)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
288 (widen)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
289
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
290 ;; Remove the message from the buffer and neutralize the
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
291 ;; marker pointing to the start of the message.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
292 (delete-region (rmail-desc-get-start n) (rmail-desc-get-end n))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
293 (move-marker (nth rmail-desc-beg-index (rmail-desc-get-descriptor n)) nil)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
294
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
295 ;; Remove the message descriptor from the Rmail message vector
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
296 ;; and execute the callback indicating the message has been
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
297 ;; deleted.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
298 (aset rmail-desc-vector (1- n) t)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
299 (funcall rmail-desc-delete-callback n)))))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
300
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
301 (defun rmail-desc-get-attr-code (attr-index n)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
302 "Return the attribute code for ATTR-INDEX in message N.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
303 If the attribute is not set, return nil."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
304 (if (rmail-desc-attr-p attr-index n)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
305 (string (nth rmail-desc-attr-code-index
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
306 (cdr (assoc attr-index rmail-desc-attr-alist))))))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
307
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
308 (defun rmail-desc-get-attr-index (attr)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
309 "Return the attribute index associated with attribute ATTR, a string."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
310 (cdr (assoc attr rmail-desc-attr-index-map)))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
311
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
312 (defun rmail-desc-get-attributes (n)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
313 "Return the attribute vector for message N."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
314 (nth rmail-desc-attrs-index (rmail-desc-get-descriptor n)))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
315
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
316 (defsubst rmail-desc-get-count ()
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
317 "Return the number of messages described in the Rmail descriptor vector."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
318 (length rmail-desc-vector))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
319
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
320 (defun rmail-desc-get-date (n)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
321 "Return the date list generated when the messages were read in."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
322 (nth rmail-desc-date-index (rmail-desc-get-descriptor n)))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
323
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
324 (defun rmail-desc-get-day-number (n)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
325 "Return the day number (1..31) from the date associated with message N."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
326 (nth rmail-desc-date-day-number-index
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
327 (nth rmail-desc-date-index (rmail-desc-get-descriptor n))))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
328
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
329 (defun rmail-desc-get-day-of-week (n)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
330 "Return the day of week (Sun .. Sat) from the date associated with message N."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
331 (nth rmail-desc-date-day-of-week-index
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
332 (nth rmail-desc-date-index (rmail-desc-get-descriptor n))))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
333
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
334 (defun rmail-desc-get-default-attrs ()
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
335 "Return the default attributes for a new message."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
336 (format "%s" "------U"))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
337
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
338 (defun rmail-desc-get-header-display-state (n)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
339 "Return t if ignorable headers are being displayed, nil otherwise."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
340 (null (overlays-at (rmail-desc-get-start n))))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
341
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
342 (defun rmail-desc-get-keyword (attr-index)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
343 "Return the keyword string associated with ATTR-INDEX."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
344 (nth rmail-desc-attr-keyword-index
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
345 (cdr (assoc attr-index rmail-desc-attr-alist))))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
346
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
347 (defun rmail-desc-get-keyword-list (n)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
348 "Return the list of User defined keywords for message N."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
349 (nth rmail-desc-keywords-index (rmail-desc-get-descriptor n)))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
350
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
351 (defun rmail-desc-get-keyword-maybe (attribute)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
352 "Return the keyword associated with ATTRIBUTE if it is set, nil otherwise.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
353 ATTRIBUTE is a cons cell associating an attribute index with a keyword string."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
354 (let ((index (car attribute)))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
355 (if (not (equal "-" (substring rmail-desc-attributes index (1+ index))))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
356 (nth rmail-desc-attr-keyword-index (cdr attribute)))))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
357
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
358 (defun rmail-desc-get-keywords (n)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
359 "Return a list of keywords for message N."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
360 ;; Combine the attribute keywords with the User defined keywords.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
361 (setq rmail-desc-attributes (rmail-desc-get-attributes n))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
362 (append (delq nil (mapcar
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
363 'rmail-desc-get-keyword-maybe
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
364 rmail-desc-attr-alist))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
365 (rmail-desc-get-keyword-list n)))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
366
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
367 (defun rmail-desc-get-line-count (n)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
368 "Return the message body line count."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
369 (nth rmail-desc-line-count-index (rmail-desc-get-descriptor n)))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
370
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
371 (defun rmail-desc-get-month (n)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
372 "Return the month (Jan .. Dec) from the date associated with message N."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
373 (nth rmail-desc-date-month-index
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
374 (nth rmail-desc-date-index (rmail-desc-get-descriptor n))))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
375
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
376 (defun rmail-desc-get-sender (n)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
377 "Return the User registered as the mail sender."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
378 (nth rmail-desc-sender-index (rmail-desc-get-descriptor n)))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
379
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
380 (defun rmail-desc-get-subject (n)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
381 "Return the cached subject header."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
382 (nth rmail-desc-subject-index (rmail-desc-get-descriptor n)))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
383
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
384 (defun rmail-desc-get-summary-offset (attr-index)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
385 "Return the summary buffer offset associated with ATTR-INDEX.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
386 This is the relative position where the attribute code letter is
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
387 displayed in the Rmail summary buffer."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
388 (nth rmail-desc-attr-summary-offset-index
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
389 (cdr (assoc attr-index rmail-desc-attr-alist))))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
390
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
391 (defun rmail-desc-get-time (n)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
392 "Return the time (hh:mm:ss) from the date associated with message N."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
393 (nth rmail-desc-date-time-index
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
394 (nth rmail-desc-date-index (rmail-desc-get-descriptor n))))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
395
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
396 (defun rmail-desc-get-year (n)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
397 "Return the year (1969 ... 2###) from the date associated with message N."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
398 (nth rmail-desc-date-year-index
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
399 (nth rmail-desc-date-index (rmail-desc-get-descriptor n))))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
400
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
401 ;; This is a strange thing to use.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
402 ;; Why not write a simple loop instead?
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
403 (defun rmail-desc-make-index-list ()
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
404 "Return a list of integers from 1 to the total number of messages."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
405 (let ((result (make-vector (length rmail-desc-vector) nil))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
406 (index 0))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
407 (while (< index (length result))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
408 (aset result index (1+ index))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
409 (setq index (1+ index)))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
410 (append result nil)))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
411
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
412 (defun rmail-desc-prune-deleted-messages (callback)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
413 "Remove all messages marked for marked for deletion.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
414 Return the number of messages removed. Invoke CALLBACK immediately
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
415 after a message has been deleted.."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
416
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
417 ;; Set the callback.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
418 (setq rmail-desc-delete-callback callback)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
419
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
420 ;; Remove all messages marked for deletion from the Rmail buffer and
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
421 ;; their descriptors from the Rmail message vector.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
422 (let ((result (length (delq t (mapcar 'rmail-desc-delete-maybe
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
423 (rmail-desc-make-index-list))))))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
424 (setq rmail-desc-vector
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
425 (vconcat (delq t (append rmail-desc-vector nil))))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
426 result))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
427
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
428 (defun rmail-desc-set-attribute (attr-index state n)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
429 "Set the attribute denoted by ATTR-INDEX in message N according to STATE.
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
430 If STATE is non-nil the attribute will be set to the single character code
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
431 associated with ATTR-INDEX in rmail-desc-attr-alist, otherwise the attribute is
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
432 set to the hyphen character (-)."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
433 (let ((attributes (nth rmail-desc-attrs-index (rmail-desc-get-descriptor n)))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
434 code)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
435 (setq code (if state
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
436 (car (cdr (assoc attr-index rmail-desc-attr-alist)))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
437 ?-))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
438 (aset attributes attr-index code)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
439 (rmail-header-persist-attributes attributes)))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
440
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
441 (defun rmail-desc-set-start (n pos)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
442 "Set the start position for message N to POS."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
443 (set-marker (nth rmail-desc-beg-index (rmail-desc-get-descriptor n)) pos))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
444
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
445 (defun rmail-desc-showing-message-p (n)
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
446 "Return t if the current buffer is displaying message N, nil otherwise."
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
447 (let ((beg (rmail-desc-get-start n))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
448 (end (rmail-desc-get-end n))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
449 (curpos (point)))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
450 (and (>= curpos beg) (< curpos end))))
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
451
30235d819e60 Mbox format support. Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
452 (provide 'rmaildesc)