Mercurial > emacs
annotate lisp/mail/rmail.el @ 1314:4cbe6db1041e
* intervals.h: Declare `copy_intervals()'.
author | Joseph Arceneaux <jla@gnu.org> |
---|---|
date | Sat, 03 Oct 1992 00:04:59 +0000 |
parents | 1e1a54ebb29b |
children | 776d4c59f256 |
rev | line source |
---|---|
658
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
621
diff
changeset
|
1 ;;; rmail.el --- main code of "RMAIL" mail reader for Emacs. |
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
621
diff
changeset
|
2 |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
830
diff
changeset
|
3 ;; Copyright (C) 1985, 1986, 1987, 1988, 1991, 1992 Free Software Foundation, Inc. |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
830
diff
changeset
|
4 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
5 ;; Maintainer: FSF |
814
38b2499cb3e9
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
813
diff
changeset
|
6 ;; Keywords: mail |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
7 |
270 | 8 ;; This file is part of GNU Emacs. |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
12 ;; the Free Software Foundation; either version 2, or (at your option) |
270 | 13 ;; any later version. |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
23 | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
24 ;;; Code: |
270 | 25 |
26 ;; Souped up by shane@mit-ajax based on ideas of rlk@athena.mit.edu | |
27 ;; New features include attribute and keyword support, message | |
28 ;; selection by dispatch table, summary by attributes and keywords, | |
29 ;; expunging by dispatch table, sticky options for file commands. | |
30 | |
31 (require 'mail-utils) | |
32 ; These variables now declared paths.el | |
33 ;(defvar rmail-spool-directory "/usr/spool/mail/" | |
34 ; "This is the name of the directory used by the system mailer for\n\ | |
35 ;delivering new mail. It's name should end with a slash.") | |
36 ;(defvar rmail-file-name | |
37 ; (expand-file-name "~/RMAIL") | |
38 ; "") | |
39 | |
40 ;;;###autoload | |
41 (defvar rmail-dont-reply-to-names nil "\ | |
42 *A regexp specifying names to prune of reply to messages. | |
43 nil means dont reply to yourself.") | |
44 | |
45 ;;;###autoload | |
46 (defvar rmail-default-dont-reply-to-names "info-" "\ | |
47 A regular expression specifying part of the value of the default value of | |
48 the variable `rmail-dont-reply-to-names', for when the user does not set | |
49 `rmail-dont-reply-to-names' explicitly. (The other part of the default | |
50 value is the user's name.) | |
51 It is useful to set this variable in the site customisation file.") | |
52 | |
53 ;;;###autoload | |
54 (defvar rmail-ignored-headers "^via:\\|^mail-from:\\|^origin:\\|^status:\\|^received:\\|^message-id:\\|^summary-line:" "\ | |
55 *Gubbish headers one would rather not see.") | |
56 | |
57 ;;;###autoload | |
58 (defvar rmail-delete-after-output nil "\ | |
59 *Non-nil means automatically delete a message that is copied to a file.") | |
60 | |
61 ;;;###autoload | |
62 (defconst rmail-primary-inbox-list nil "\ | |
63 *List of files which are inboxes for user's primary mail file ~/RMAIL. | |
64 `nil' means the default, which is (\"/usr/spool/mail/$USER\" \"~/mbox\") | |
65 \(the first name varies depending on the operating system, | |
66 and the value of the environment variable MAIL overrides it).") | |
67 | |
68 ;; these may be altered by site-init.el to match the format of mmdf files | |
69 ;; delimitation used on a given host (delim1 and delim2 from the config | |
70 ;; files) | |
71 | |
72 (defvar mmdf-delim1 "^\001\001\001\001\n" | |
73 "Regexp marking the start of an mmdf message") | |
74 (defvar mmdf-delim2 "^\001\001\001\001\n" | |
75 "Regexp marking the end of an mmdf message") | |
76 | |
77 (defvar rmail-message-filter nil | |
78 "If non nil, is a filter function for new headers in RMAIL. | |
79 Called with region narrowed to unformatted header.") | |
80 | |
81 (defvar rmail-mode-map nil) | |
82 | |
83 (defvar rmail-inbox-list nil) | |
84 (defvar rmail-keywords nil) | |
85 | |
86 ;; Message counters and markers. Deleted flags. | |
87 | |
88 (defvar rmail-current-message nil) | |
89 (defvar rmail-total-messages nil) | |
90 (defvar rmail-message-vector nil) | |
91 (defvar rmail-deleted-vector nil) | |
92 | |
93 ;; These are used by autoloaded rmail-summary. | |
94 | |
95 (defvar rmail-summary-buffer nil) | |
96 (defvar rmail-summary-vector nil) | |
97 | |
98 ;; `Sticky' default variables. | |
99 | |
100 ;; Last individual label specified to a or k. | |
101 (defvar rmail-last-label nil) | |
102 ;; Last set of labels specified to C-M-n or C-M-p or C-M-l. | |
103 (defvar rmail-last-multi-labels nil) | |
104 (defvar rmail-last-file nil) | |
105 (defvar rmail-last-rmail-file nil) | |
617 | 106 |
621 | 107 ;;; Regexp matching the delimiter of messages in UNIX mail format |
108 ;;; (UNIX From lines), minus the initial ^. Note that if you change | |
109 ;;; this expression, you must change the code in rmail-nuke-pinhead-header | |
110 ;;; that knows the exact ordering of the \\( \\) subexpressions. | |
617 | 111 (defvar rmail-unix-mail-delimiter |
1112 | 112 (let ((time-zone-regexp |
113 (concat "\\([A-Z]?[A-Z][A-Z]T\\( DST\\)?" | |
114 "\\|[-+]?[0-9][0-9][0-9][0-9]" | |
115 "\\|" | |
116 "\\) *"))) | |
117 (concat | |
118 "From " | |
119 | |
120 ;; Username, perhaps with a quoted section that can contain spaces. | |
121 "\\(" | |
122 "[^ \n]*" | |
123 "\\(\\|\".*\"[^ \n]*\\)" | |
124 "\\) ?" | |
125 | |
126 ;; The time the message was sent. | |
127 "\\([^ \n]*\\) *" ; day of the week | |
128 "\\([^ ]*\\) *" ; month | |
129 "\\([0-9]*\\) *" ; day of month | |
130 "\\([0-9:]*\\) *" ; time of day | |
131 | |
132 ;; Perhaps a time zone, specified by an abbreviation, or by a | |
133 ;; numeric offset. | |
134 time-zone-regexp | |
135 | |
136 ;; The year. | |
137 " [0-9][0-9]\\([0-9]*\\) *" | |
138 | |
139 ;; On some systems the time zone can appear after the year, too. | |
140 time-zone-regexp | |
141 | |
142 ;; I'm not sure what this is. | |
143 "\\(remote from [^\n]*\\)?" | |
144 | |
145 "\n")) | |
146 nil) | |
147 | |
148 | |
270 | 149 |
150 ;;;; *** Rmail Mode *** | |
151 | |
152 ;;;###autoload | |
153 (defun rmail (&optional file-name-arg) | |
154 "Read and edit incoming mail. | |
155 Moves messages into file named by rmail-file-name (a babyl format file) | |
156 and edits that file in RMAIL Mode. | |
157 Type \\[describe-mode] once editing that file, for a list of RMAIL commands. | |
158 | |
159 May be called with filename as argument; then performs rmail editing on | |
160 that file, but does not copy any new mail into the file." | |
161 (interactive (if current-prefix-arg | |
162 (list (read-file-name "Run rmail on RMAIL file: " | |
163 nil nil t)))) | |
164 (or rmail-last-file | |
165 (setq rmail-last-file (expand-file-name "~/xmail"))) | |
166 (or rmail-last-rmail-file | |
167 (setq rmail-last-rmail-file (expand-file-name "~/XMAIL"))) | |
168 (let* ((file-name (expand-file-name (or file-name-arg rmail-file-name))) | |
169 (existed (get-file-buffer file-name))) | |
170 ;; Like find-file, but in the case where a buffer existed | |
171 ;; and the file was reverted, recompute the message-data. | |
172 (if (and existed (not (verify-visited-file-modtime existed))) | |
173 (progn | |
174 ;; Don't be confused by apparent local-variables spec | |
175 ;; in the last message in the RMAIL file. | |
1024
ceb4469d3cd7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
997
diff
changeset
|
176 (let ((enable-local-variables nil)) |
270 | 177 (find-file file-name)) |
178 (if (verify-visited-file-modtime existed) | |
179 (progn (rmail-forget-messages) | |
180 (rmail-set-message-counters)))) | |
1024
ceb4469d3cd7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
997
diff
changeset
|
181 (let ((enable-local-variables nil)) |
270 | 182 (find-file file-name))) |
183 (if (and existed (> (buffer-size) 0)) | |
184 ;; Buffer not new and not empty; ensure in proper mode, but that's all. | |
185 (or (eq major-mode 'rmail-mode) | |
186 (rmail-mode-2)) | |
187 (rmail-mode-2) | |
188 ;; Provide default set of inboxes for primary mail file ~/RMAIL. | |
189 (and (null rmail-inbox-list) | |
190 (null file-name-arg) | |
191 (setq rmail-inbox-list | |
192 (or rmail-primary-inbox-list | |
193 (list "~/mbox" | |
194 (or (getenv "MAIL") | |
195 (concat rmail-spool-directory | |
196 (user-original-login-name))))))) | |
197 ;; Convert all or part to Babyl file if possible. | |
198 (rmail-convert-file) | |
199 (goto-char (point-max)) | |
200 (if (null rmail-inbox-list) | |
201 (progn | |
202 (rmail-set-message-counters) | |
203 (rmail-show-message)))) | |
204 (rmail-get-new-mail) | |
205 ;; Show the first unseen message, which might be from a previous session | |
206 ;; or might have been just read in by rmail-get-new-mail. | |
207 (rmail-first-unseen-message))) | |
208 | |
209 ;; Given the value of MAILPATH, return a list of inbox file names. | |
210 ;; This is turned off because it is not clear that the user wants | |
211 ;; all these inboxes to feed into the primary rmail file. | |
212 ; (defun rmail-convert-mailpath (string) | |
213 ; (let (idx list) | |
214 ; (while (setq idx (string-match "[%:]" string)) | |
215 ; (let ((this (substring string 0 idx))) | |
216 ; (setq string (substring string (1+ idx))) | |
217 ; (setq list (cons (if (string-match "%" this) | |
218 ; (substring this 0 (string-match "%" this)) | |
219 ; this) | |
220 ; list)))) | |
221 ; list)) | |
222 | |
223 ; I have checked that adding "-*- rmail -*-" to the BABYL OPTIONS line | |
224 ; will not cause emacs 18.55 problems. | |
225 | |
226 (defun rmail-convert-file () | |
227 (let (convert) | |
228 (widen) | |
229 (goto-char (point-min)) | |
230 ;; If file doesn't start like a Babyl file, | |
231 ;; convert it to one, by adding a header and converting each message. | |
232 (cond ((looking-at "BABYL OPTIONS:")) | |
233 ((looking-at "Version: 5\n") | |
234 ;; Losing babyl file made by old version of Rmail. | |
235 ;; Just fix the babyl file header; don't make a new one, | |
236 ;; so we don't lose the Labels: file attribute, etc. | |
237 (let ((buffer-read-only nil)) | |
238 (insert "BABYL OPTIONS: -*- rmail -*-\n"))) | |
239 (t | |
240 (setq convert t) | |
241 (rmail-insert-rmail-file-header))) | |
242 ;; If file was not a Babyl file or if there are | |
243 ;; Unix format messages added at the end, | |
244 ;; convert file as necessary. | |
245 (if (or convert | |
246 (progn (goto-char (point-max)) | |
247 (search-backward "\^_") | |
248 (forward-char 1) | |
249 (looking-at "\n*From "))) | |
250 (let ((buffer-read-only nil)) | |
251 (message "Converting to Babyl format...") | |
252 (narrow-to-region (point) (point-max)) | |
253 (rmail-convert-to-babyl-format) | |
254 (message "Converting to Babyl format...done"))))) | |
255 | |
256 ; I have checked that adding "-*- rmail -*-" to the BABYL OPTIONS line | |
257 ; will not cause emacs 18.55 problems. | |
258 | |
259 (defun rmail-insert-rmail-file-header () | |
260 (let ((buffer-read-only nil)) | |
261 (insert "BABYL OPTIONS: -*- rmail -*- | |
262 Version: 5 | |
263 Labels: | |
264 Note: This is the header of an rmail file. | |
265 Note: If you are seeing it in rmail, | |
266 Note: it means the file has no messages in it.\n\^_"))) | |
267 | |
268 (if rmail-mode-map | |
269 nil | |
270 (setq rmail-mode-map (make-keymap)) | |
271 (suppress-keymap rmail-mode-map) | |
272 (define-key rmail-mode-map "." 'rmail-beginning-of-message) | |
273 (define-key rmail-mode-map " " 'scroll-up) | |
274 (define-key rmail-mode-map "\177" 'scroll-down) | |
275 (define-key rmail-mode-map "n" 'rmail-next-undeleted-message) | |
276 (define-key rmail-mode-map "p" 'rmail-previous-undeleted-message) | |
277 (define-key rmail-mode-map "\en" 'rmail-next-message) | |
278 (define-key rmail-mode-map "\ep" 'rmail-previous-message) | |
279 (define-key rmail-mode-map "\e\C-n" 'rmail-next-labeled-message) | |
280 (define-key rmail-mode-map "\e\C-p" 'rmail-previous-labeled-message) | |
281 (define-key rmail-mode-map "a" 'rmail-add-label) | |
282 (define-key rmail-mode-map "k" 'rmail-kill-label) | |
283 (define-key rmail-mode-map "d" 'rmail-delete-forward) | |
284 (define-key rmail-mode-map "u" 'rmail-undelete-previous-message) | |
285 (define-key rmail-mode-map "x" 'rmail-expunge) | |
286 (define-key rmail-mode-map "s" 'rmail-expunge-and-save) | |
287 (define-key rmail-mode-map "g" 'rmail-get-new-mail) | |
288 (define-key rmail-mode-map "h" 'rmail-summary) | |
289 (define-key rmail-mode-map "\e\C-h" 'rmail-summary) | |
290 (define-key rmail-mode-map "l" 'rmail-summary-by-labels) | |
291 (define-key rmail-mode-map "\e\C-l" 'rmail-summary-by-labels) | |
292 (define-key rmail-mode-map "\e\C-r" 'rmail-summary-by-recipients) | |
293 (define-key rmail-mode-map "\e\C-s" 'rmail-summary-by-regexp) | |
294 (define-key rmail-mode-map "t" 'rmail-toggle-header) | |
295 (define-key rmail-mode-map "m" 'rmail-mail) | |
296 (define-key rmail-mode-map "r" 'rmail-reply) | |
297 (define-key rmail-mode-map "\e\C-m" 'rmail-retry-failure) | |
298 (define-key rmail-mode-map "c" 'rmail-continue) | |
299 (define-key rmail-mode-map "f" 'rmail-forward) | |
874
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
300 (define-key rmail-mode-map "\er" 'rmail-search-backwards) |
270 | 301 (define-key rmail-mode-map "\es" 'rmail-search) |
302 (define-key rmail-mode-map "<" 'rmail-first-message) | |
303 (define-key rmail-mode-map ">" 'rmail-last-message) | |
304 (define-key rmail-mode-map "j" 'rmail-show-message) | |
305 (define-key rmail-mode-map "o" 'rmail-output-to-rmail-file) | |
306 (define-key rmail-mode-map "\C-o" 'rmail-output) | |
307 (define-key rmail-mode-map "i" 'rmail-input) | |
308 (define-key rmail-mode-map "q" 'rmail-quit) | |
309 (define-key rmail-mode-map "?" 'describe-mode) | |
310 (define-key rmail-mode-map "w" 'rmail-edit-current-message) | |
311 (define-key rmail-mode-map "e" 'rmail-edit-current-message) | |
312 (define-key rmail-mode-map "\C-d" 'rmail-delete-backward)) | |
313 | |
314 ;; Rmail mode is suitable only for specially formatted data. | |
315 (put 'rmail-mode 'mode-class 'special) | |
316 | |
317 (defun rmail-mode () | |
318 "Rmail Mode is used by \\<rmail-mode-map>\\[rmail] for editing Rmail files. | |
319 All normal editing commands are turned off. | |
320 Instead, these commands are available: | |
321 | |
322 \\[rmail-beginning-of-message] Move point to front of this message (same as \\[beginning-of-buffer]). | |
323 \\[scroll-up] Scroll to next screen of this message. | |
324 \\[scroll-down] Scroll to previous screen of this message. | |
325 \\[rmail-next-undeleted-message] Move to Next non-deleted message. | |
326 \\[rmail-previous-undeleted-message] Move to Previous non-deleted message. | |
327 \\[rmail-next-message] Move to Next message whether deleted or not. | |
328 \\[rmail-previous-message] Move to Previous message whether deleted or not. | |
329 \\[rmail-first-message] Move to the first message in Rmail file. | |
330 \\[rmail-last-message] Move to the last message in Rmail file. | |
331 \\[rmail-show-message] Jump to message specified by numeric position in file. | |
332 \\[rmail-search] Search for string and show message it is found in. | |
333 \\[rmail-delete-forward] Delete this message, move to next nondeleted. | |
334 \\[rmail-delete-backward] Delete this message, move to previous nondeleted. | |
335 \\[rmail-undelete-previous-message] Undelete message. Tries current message, then earlier messages | |
336 till a deleted message is found. | |
337 \\[rmail-expunge] Expunge deleted messages. | |
338 \\[rmail-expunge-and-save] Expunge and save the file. | |
339 \\[rmail-quit] Quit Rmail: expunge, save, then switch to another buffer. | |
340 \\[save-buffer] Save without expunging. | |
341 \\[rmail-get-new-mail] Move new mail from system spool directory or mbox into this file. | |
342 \\[rmail-mail] Mail a message (same as \\[mail-other-window]). | |
343 \\[rmail-continue] Continue composing outgoing message started before. | |
344 \\[rmail-reply] Reply to this message. Like m but initializes some fields. | |
345 \\[rmail-retry-failure] Send this message again. Used on a mailer failure message. | |
346 \\[rmail-forward] Forward this message to another user. | |
347 \\[rmail-output-to-rmail-file] Output this message to an Rmail file (append it). | |
348 \\[rmail-output] Output this message to a Unix-format mail file (append it). | |
349 \\[rmail-input] Input Rmail file. Run Rmail on that file. | |
350 \\[rmail-add-label] Add label to message. It will be displayed in the mode line. | |
351 \\[rmail-kill-label] Kill label. Remove a label from current message. | |
352 \\[rmail-next-labeled-message] Move to Next message with specified label | |
353 (label defaults to last one specified). | |
354 Standard labels: filed, unseen, answered, forwarded, deleted. | |
355 Any other label is present only if you add it with `a'. | |
356 \\[rmail-previous-labeled-message] Move to Previous message with specified label | |
357 \\[rmail-summary] Show headers buffer, with a one line summary of each message. | |
1078
15b4ed20e524
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1024
diff
changeset
|
358 \\[rmail-summary-by-labels] Like \\[rmail-summary] only just messages with particular label(s) are summarized. |
15b4ed20e524
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1024
diff
changeset
|
359 \\[rmail-summary-by-recipients] Like \\[rmail-summary] only just messages with particular recipient(s) are summarized. |
270 | 360 \\[rmail-toggle-header] Toggle header, show Rmail header if unformatted or vice versa. |
361 \\[rmail-edit-current-message] Edit the current message. \\[rmail-cease-edit] to return to Rmail." | |
362 (interactive) | |
363 (rmail-mode-2) | |
364 (rmail-set-message-counters) | |
365 (rmail-show-message)) | |
366 | |
367 (defun rmail-mode-2 () | |
368 (kill-all-local-variables) | |
369 (rmail-mode-1) | |
370 (rmail-variables) | |
371 (run-hooks 'rmail-mode-hook)) | |
372 | |
373 (defun rmail-mode-1 () | |
374 (setq major-mode 'rmail-mode) | |
375 (setq mode-name "RMAIL") | |
376 (setq buffer-read-only t) | |
377 ;; No need to auto save RMAIL files. | |
378 (setq buffer-auto-save-file-name nil) | |
379 (if (boundp 'mode-line-modified) | |
380 (setq mode-line-modified "--- ") | |
381 (setq mode-line-format | |
382 (cons "--- " (cdr (default-value 'mode-line-format))))) | |
383 (use-local-map rmail-mode-map) | |
384 (set-syntax-table text-mode-syntax-table) | |
385 (setq local-abbrev-table text-mode-abbrev-table)) | |
386 | |
387 (defun rmail-variables () | |
388 (make-local-variable 'revert-buffer-function) | |
389 (setq revert-buffer-function 'rmail-revert) | |
390 (make-local-variable 'rmail-last-label) | |
391 (make-local-variable 'rmail-deleted-vector) | |
392 (make-local-variable 'rmail-summary-buffer) | |
393 (make-local-variable 'rmail-summary-vector) | |
394 (make-local-variable 'rmail-current-message) | |
395 (make-local-variable 'rmail-total-messages) | |
396 (make-local-variable 'require-final-newline) | |
397 (setq require-final-newline nil) | |
398 (make-local-variable 'version-control) | |
399 (setq version-control 'never) | |
400 (make-local-variable 'file-precious-flag) | |
401 (setq file-precious-flag t) | |
402 (make-local-variable 'rmail-message-vector) | |
403 (make-local-variable 'rmail-last-file) | |
404 (make-local-variable 'rmail-inbox-list) | |
405 (setq rmail-inbox-list (rmail-parse-file-inboxes)) | |
406 (make-local-variable 'rmail-keywords) | |
407 ;; this gets generated as needed | |
280
e6f9ccb230ad
*** empty log message ***
Michael I. Bushnell <mib@gnu.org>
parents:
270
diff
changeset
|
408 (setq rmail-keywords nil)) |
270 | 409 |
410 ;; Handle M-x revert-buffer done in an rmail-mode buffer. | |
411 (defun rmail-revert (arg noconfirm) | |
412 (let (revert-buffer-function) | |
413 ;; Call our caller again, but this time it does the default thing. | |
414 (if (revert-buffer arg noconfirm) | |
415 ;; If the user said "yes", and we changed something, | |
416 ;; reparse the messages. | |
417 (progn | |
418 (rmail-convert-file) | |
419 (goto-char (point-max)) | |
420 (rmail-set-message-counters) | |
421 (rmail-show-message))))) | |
422 | |
423 ;; Return a list of files from this buffer's Mail: option. | |
424 ;; Does not assume that messages have been parsed. | |
425 ;; Just returns nil if buffer does not look like Babyl format. | |
426 (defun rmail-parse-file-inboxes () | |
427 (save-excursion | |
428 (save-restriction | |
429 (widen) | |
430 (goto-char 1) | |
431 (cond ((looking-at "BABYL OPTIONS:") | |
432 (search-forward "\n\^_" nil 'move) | |
433 (narrow-to-region 1 (point)) | |
434 (goto-char 1) | |
435 (if (search-forward "\nMail:" nil t) | |
436 (progn | |
437 (narrow-to-region (point) (progn (end-of-line) (point))) | |
438 (goto-char (point-min)) | |
439 (mail-parse-comma-list)))))))) | |
440 | |
441 (defun rmail-expunge-and-save () | |
442 "Expunge and save RMAIL file." | |
443 (interactive) | |
444 (rmail-expunge) | |
445 (save-buffer)) | |
446 | |
447 (defun rmail-quit () | |
448 "Quit out of RMAIL." | |
449 (interactive) | |
450 (rmail-expunge-and-save) | |
451 ;; Don't switch to the summary buffer even if it was recently visible. | |
452 (if rmail-summary-buffer | |
453 (bury-buffer rmail-summary-buffer)) | |
454 (let ((obuf (current-buffer))) | |
455 (switch-to-buffer (other-buffer)) | |
456 (bury-buffer obuf))) | |
457 | |
458 ;;;###autoload | |
459 (defun rmail-input (filename) | |
460 "Run RMAIL on file FILENAME." | |
461 (interactive "FRun rmail on RMAIL file: ") | |
462 (rmail filename)) | |
463 | |
464 | |
465 ;;;; *** Rmail input *** | |
466 | |
467 ;; RLK feature not added in this version: | |
468 ;; argument specifies inbox file or files in various ways. | |
469 | |
470 (defun rmail-get-new-mail (&optional file-name) | |
471 "Move any new mail from this RMAIL file's inbox files. | |
472 The inbox files can be specified with the file's Mail: option. The | |
473 variable `rmail-primary-inbox-list' specifies the inboxes for your | |
474 primary RMAIL file if it has no Mail: option. These are normally your | |
475 ~/mbox and your /usr/spool/mail/$USER. | |
476 | |
477 You can also specify the file to get new mail from. In this case, the | |
478 file of new mail is not changed or deleted. Noninteractively, you can | |
479 pass the inbox file name as an argument. Interactively, a prefix | |
480 argument causes us to read a file name and use that file as the inbox." | |
481 (interactive | |
482 (list (if current-prefix-arg | |
483 (read-file-name "Get new mail from file: ")))) | |
484 (or (verify-visited-file-modtime (current-buffer)) | |
485 (progn | |
486 (find-file (buffer-file-name)) | |
487 (if (verify-visited-file-modtime (current-buffer)) | |
488 (rmail-forget-messages)))) | |
489 (rmail-maybe-set-message-counters) | |
490 (widen) | |
491 ;; Get rid of all undo records for this buffer. | |
492 (or (eq buffer-undo-list t) | |
493 (setq buffer-undo-list nil)) | |
494 (unwind-protect | |
495 (let ((opoint (point)) | |
496 (new-messages 0) | |
497 (delete-files ()) | |
498 ;; If buffer has not changed yet, and has not been saved yet, | |
499 ;; don't replace the old backup file now. | |
500 (make-backup-files (and make-backup-files (buffer-modified-p))) | |
501 (buffer-read-only nil) | |
502 ;; Don't make undo records for what we do in getting mail. | |
503 (buffer-undo-list t)) | |
504 (goto-char (point-max)) | |
505 (skip-chars-backward " \t\n") ; just in case of brain damage | |
506 (delete-region (point) (point-max)) ; caused by require-final-newline | |
507 (save-excursion | |
508 (save-restriction | |
509 (narrow-to-region (point) (point)) | |
510 ;; Read in the contents of the inbox files, | |
511 ;; renaming them as necessary, | |
512 ;; and adding to the list of files to delete eventually. | |
513 (if file-name | |
514 (rmail-insert-inbox-text (list file-name) nil) | |
515 (setq delete-files (rmail-insert-inbox-text rmail-inbox-list t))) | |
516 ;; Scan the new text and convert each message to babyl format. | |
517 (goto-char (point-min)) | |
518 (save-excursion | |
519 (setq new-messages (rmail-convert-to-babyl-format))) | |
520 (or (zerop new-messages) | |
521 (let (success) | |
522 (widen) | |
523 (search-backward "\n\^_") | |
524 (narrow-to-region (point) (point-max)) | |
525 (goto-char (1+ (point-min))) | |
526 (rmail-count-new-messages) | |
527 (save-buffer))) | |
528 ;; Delete the old files, now that babyl file is saved. | |
529 (while delete-files | |
530 (condition-case () | |
1165 | 531 ;; First, try deleting. |
532 (condition-case () | |
533 (delete-file (car delete-files)) | |
534 (file-error | |
535 ;; If we can't delete it, truncate it. | |
536 (write-region (point) (point) (car delete-files)))) | |
270 | 537 (file-error nil)) |
538 (setq delete-files (cdr delete-files))))) | |
539 (if (= new-messages 0) | |
540 (progn (goto-char opoint) | |
541 (if (or file-name rmail-inbox-list) | |
542 (message "(No new mail has arrived)"))) | |
543 (message "%d new message%s read" | |
544 new-messages (if (= 1 new-messages) "" "s")) | |
545 (and (boundp 'display-time-string) | |
546 (string-match " Mail" display-time-string) | |
547 (setq display-time-string | |
548 (concat | |
549 (substring display-time-string 0 (match-beginning 0)) | |
550 (substring display-time-string (match-end 0)))) | |
551 (force-mode-line-update 'all)))) | |
552 ;; Don't leave the buffer screwed up if we get a disk-full error. | |
553 (rmail-show-message))) | |
554 | |
555 (defun rmail-insert-inbox-text (files renamep) | |
556 (let (file tofile delete-files movemail) | |
557 (while files | |
558 (setq file (expand-file-name (substitute-in-file-name (car files))) | |
559 ;;>> un*x specific << | |
813 | 560 ;; The "+" used to be "~", which is an extremely poor choice; |
561 ;; it might accidentally be deleted when space is low | |
562 ;; (as happened to me!). | |
563 tofile (concat file "+")) | |
270 | 564 ;; If getting from mail spool directory, |
565 ;; use movemail to move rather than just renaming, | |
566 ;; so as to interlock with the mailer. | |
567 (setq movemail (equal (file-name-directory file) rmail-spool-directory)) | |
568 (if movemail | |
569 (progn | |
570 (setq tofile (expand-file-name | |
571 ;; Generate name to move to from inbox name, | |
572 ;; in case of multiple inboxes that need moving. | |
573 (concat ".newmail-" (file-name-nondirectory file)) | |
574 (file-name-directory | |
575 (expand-file-name rmail-file-name)))) | |
576 ;; On some systems, /usr/spool/mail/foo is a directory | |
577 ;; and the actual inbox is /usr/spool/mail/foo/foo. | |
578 (if (file-directory-p file) | |
579 (setq file (expand-file-name (user-original-login-name) | |
580 file))))) | |
1161 | 581 (if (or (and (file-exists-p tofile) |
582 (/= 0 (nth 7 (file-attributes tofile)))) | |
583 (and (file-exists-p file) | |
584 (/= 0 (nth 7 (file-attributes file))))) | |
270 | 585 (message "Getting mail from %s..." file)) |
586 ;; Set TOFILE if have not already done so, and | |
587 ;; rename or copy the file FILE to TOFILE if and as appropriate. | |
588 (cond ((not renamep) | |
589 (setq tofile file)) | |
590 ((or (file-exists-p tofile) (not (file-exists-p file))) | |
591 nil) | |
592 ((not movemail) | |
1165 | 593 (rename-file file tofile nil) |
594 ;; Make the real inbox file empty. | |
595 ;; Leaving it deleted could cause lossage | |
596 ;; because mailers often won't create the file. | |
597 (condition-case () | |
598 (write-region (point) (point) file) | |
599 (file-error nil))) | |
270 | 600 (t |
601 (let ((errors nil)) | |
602 (unwind-protect | |
603 (save-excursion | |
604 (setq errors (generate-new-buffer " *rmail loss*")) | |
605 (buffer-disable-undo errors) | |
606 (call-process | |
607 (expand-file-name "movemail" exec-directory) | |
608 nil errors nil file tofile) | |
609 (if (not (buffer-modified-p errors)) | |
610 ;; No output => movemail won | |
611 nil | |
612 (set-buffer errors) | |
613 (subst-char-in-region (point-min) (point-max) | |
614 ?\n ?\ ) | |
615 (goto-char (point-max)) | |
616 (skip-chars-backward " \t") | |
617 (delete-region (point) (point-max)) | |
618 (goto-char (point-min)) | |
619 (if (looking-at "movemail: ") | |
620 (delete-region (point-min) (match-end 0))) | |
621 (beep t) | |
622 (message (concat "movemail: " | |
623 (buffer-substring (point-min) | |
624 (point-max)))) | |
625 (sit-for 3) | |
626 nil)) | |
627 (if errors (kill-buffer errors)))))) | |
628 ;; At this point, TOFILE contains the name to read: | |
629 ;; Either the alternate name (if we renamed) | |
630 ;; or the actual inbox (if not renaming). | |
631 (if (file-exists-p tofile) | |
632 (let (size) | |
633 (goto-char (point-max)) | |
634 (setq size (nth 1 (insert-file-contents tofile))) | |
635 (goto-char (point-max)) | |
636 (or (= (preceding-char) ?\n) | |
637 (zerop size) | |
638 (insert ?\n)) | |
639 (setq delete-files (cons tofile delete-files)))) | |
640 (message "") | |
641 (setq files (cdr files))) | |
642 delete-files)) | |
643 | |
644 ;; the rmail-break-forwarded-messages feature is not implemented | |
645 (defun rmail-convert-to-babyl-format () | |
646 (let ((count 0) start | |
402
14485c6a56aa
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
346
diff
changeset
|
647 (case-fold-search nil) |
14485c6a56aa
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
346
diff
changeset
|
648 (invalid-input-resync |
14485c6a56aa
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
346
diff
changeset
|
649 (function (lambda () |
14485c6a56aa
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
346
diff
changeset
|
650 (message "Invalid Babyl format in inbox!") |
14485c6a56aa
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
346
diff
changeset
|
651 (sit-for 1) |
14485c6a56aa
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
346
diff
changeset
|
652 ;; Try to get back in sync with a real message. |
14485c6a56aa
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
346
diff
changeset
|
653 (if (re-search-forward |
14485c6a56aa
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
346
diff
changeset
|
654 (concat mmdf-delim1 "\\|^From") nil t) |
14485c6a56aa
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
346
diff
changeset
|
655 (beginning-of-line) |
14485c6a56aa
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
346
diff
changeset
|
656 (goto-char (point-max))))))) |
270 | 657 (goto-char (point-min)) |
658 (save-restriction | |
659 (while (not (eobp)) | |
660 (cond ((looking-at "BABYL OPTIONS:");Babyl header | |
402
14485c6a56aa
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
346
diff
changeset
|
661 (if (search-forward "\n\^_" nil t) |
14485c6a56aa
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
346
diff
changeset
|
662 ;; If we find the proper terminator, delete through there. |
14485c6a56aa
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
346
diff
changeset
|
663 (delete-region (point-min) (point)) |
14485c6a56aa
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
346
diff
changeset
|
664 (funcall invalid-input-resync) |
405
698d5d6e8f8b
*** empty log message ***
Michael I. Bushnell <mib@gnu.org>
parents:
403
diff
changeset
|
665 (delete-region (point-min) (point)))) |
270 | 666 ;; Babyl format message |
667 ((looking-at "\^L") | |
668 (or (search-forward "\n\^_" nil t) | |
402
14485c6a56aa
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
346
diff
changeset
|
669 (funcall invalid-input-resync)) |
270 | 670 (setq count (1+ count)) |
671 ;; Make sure there is no extra white space after the ^_ | |
672 ;; at the end of the message. | |
673 ;; Narrowing will make sure that whatever follows the junk | |
674 ;; will be treated properly. | |
675 (delete-region (point) | |
676 (save-excursion | |
677 (skip-chars-forward " \t\n") | |
678 (point))) | |
679 (narrow-to-region (point) (point-max))) | |
680 ;;*** MMDF format | |
681 ((let ((case-fold-search t)) | |
682 (looking-at mmdf-delim1)) | |
683 (let ((case-fold-search t)) | |
684 (replace-match "\^L\n0, unseen,,\n*** EOOH ***\n") | |
685 (setq start (point)) | |
686 (re-search-forward mmdf-delim2 nil t) | |
687 (replace-match "\^_")) | |
688 (save-excursion | |
689 (save-restriction | |
690 (narrow-to-region start (1- (point))) | |
691 (goto-char (point-min)) | |
692 (while (search-forward "\n\^_" nil t); single char "\^_" | |
693 (replace-match "\n^_")))); 2 chars: "^" and "_" | |
694 (narrow-to-region (point) (point-max)) | |
695 (setq count (1+ count))) | |
696 ;;*** Mail format | |
697 ((looking-at "^From ") | |
698 (setq start (point)) | |
699 (insert "\^L\n0, unseen,,\n*** EOOH ***\n") | |
700 (rmail-nuke-pinhead-header) | |
701 (if (re-search-forward | |
702 (concat "^[\^_]?\\(" | |
617 | 703 rmail-unix-mail-delimiter |
704 "\\|" | |
270 | 705 mmdf-delim1 "\\|" |
706 "^BABYL OPTIONS:\\|" | |
707 "\^L\n[01],\\)") nil t) | |
708 (goto-char (match-beginning 1)) | |
709 (goto-char (point-max))) | |
710 (setq count (1+ count)) | |
711 (save-excursion | |
712 (save-restriction | |
713 (narrow-to-region start (point)) | |
714 (goto-char (point-min)) | |
715 (while (search-forward "\n\^_" nil t); single char | |
716 (replace-match "\n^_")))); 2 chars: "^" and "_" | |
717 (insert ?\^_) | |
718 (narrow-to-region (point) (point-max))) | |
719 ;; | |
720 ;;This is a kludge, in case we're wrong about mmdf not | |
721 ;;allowing anything in between. If it loses, we'll have | |
722 ;;to look for something else | |
405
698d5d6e8f8b
*** empty log message ***
Michael I. Bushnell <mib@gnu.org>
parents:
403
diff
changeset
|
723 (t (error "Cannot convert to babyl format"))))) |
270 | 724 count)) |
725 | |
726 ;; Delete the "From ..." line, creating various other headers with | |
727 ;; information from it if they don't already exist. Now puts the | |
728 ;; original line into a mail-from: header line for debugging. | |
729 (defun rmail-nuke-pinhead-header () | |
730 (save-excursion | |
731 (save-restriction | |
732 (let ((start (point)) | |
733 (end (progn | |
734 (condition-case () | |
735 (search-forward "\n\n") | |
736 (error | |
737 (goto-char (point-max)) | |
738 (insert "\n\n"))) | |
739 (point))) | |
740 has-from has-date) | |
741 (narrow-to-region start end) | |
742 (let ((case-fold-search t)) | |
743 (goto-char start) | |
744 (setq has-from (search-forward "\nFrom:" nil t)) | |
745 (goto-char start) | |
746 (setq has-date (and (search-forward "\nDate:" nil t) (point))) | |
747 (goto-char start)) | |
748 (let ((case-fold-search nil)) | |
617 | 749 (if (re-search-forward (concat "^" rmail-unix-mail-delimiter) nil t) |
270 | 750 (replace-match |
751 (concat | |
752 "Mail-from: \\&" | |
753 ;; Keep and reformat the date if we don't | |
754 ;; have a Date: field. | |
755 (if has-date | |
756 "" | |
1112 | 757 (concat |
758 "Date: \\3, \\5 \\4 \\9 \\6 " | |
759 | |
760 ;; The timezone could be matched by group 7 or group 10. | |
761 ;; If neither of them matched, assume EST, since only | |
762 ;; Easterners would be so sloppy. | |
763 ;; It's a shame the substitution can't use "\\10". | |
764 (cond | |
765 ((/= (match-beginning 7) (match-end 7)) "\\7") | |
766 ((/= (match-beginning 10) (match-end 10)) | |
767 (buffer-substring (match-beginning 10) | |
768 (match-end 10))) | |
769 (t "EST")) | |
770 "\n")) | |
270 | 771 ;; Keep and reformat the sender if we don't |
772 ;; have a From: field. | |
773 (if has-from | |
774 "" | |
775 "From: \\1\n"))))))))) | |
776 | |
777 ;;;; *** Rmail Message Formatting and Header Manipulation *** | |
778 | |
779 (defun rmail-reformat-message (beg end) | |
780 (goto-char beg) | |
781 (forward-line 1) | |
782 (if (/= (following-char) ?0) | |
783 (error "Bad format in RMAIL file.")) | |
784 (let ((buffer-read-only nil) | |
785 (delta (- (buffer-size) end))) | |
786 (delete-char 1) | |
787 (insert ?1) | |
788 (forward-line 1) | |
789 (if (looking-at "Summary-line: ") | |
790 (forward-line 1)) | |
791 (if (looking-at "\\*\\*\\* EOOH \\*\\*\\*\n") | |
792 (delete-region (point) | |
793 (progn (forward-line 1) (point)))) | |
794 (let ((str (buffer-substring (point) | |
795 (save-excursion (search-forward "\n\n" end 'move) | |
796 (point))))) | |
797 (insert str "*** EOOH ***\n") | |
798 (narrow-to-region (point) (- (buffer-size) delta))) | |
799 (goto-char (point-min)) | |
800 (if rmail-ignored-headers (rmail-clear-headers)) | |
801 (if rmail-message-filter (funcall rmail-message-filter)))) | |
802 | |
803 (defun rmail-clear-headers () | |
804 (if (search-forward "\n\n" nil t) | |
805 (save-restriction | |
806 (narrow-to-region (point-min) (point)) | |
807 (let ((buffer-read-only nil)) | |
808 (while (let ((case-fold-search t)) | |
809 (goto-char (point-min)) | |
810 (re-search-forward rmail-ignored-headers nil t)) | |
811 (beginning-of-line) | |
812 (delete-region (point) | |
813 (progn (re-search-forward "\n[^ \t]") | |
814 (forward-char -1) | |
815 (point)))))))) | |
816 | |
817 (defun rmail-toggle-header () | |
818 "Show original message header if pruned header currently shown, or vice versa." | |
819 (interactive) | |
820 (rmail-maybe-set-message-counters) | |
821 (narrow-to-region (rmail-msgbeg rmail-current-message) (point-max)) | |
822 (let ((buffer-read-only nil)) | |
823 (goto-char (point-min)) | |
824 (forward-line 1) | |
825 (if (= (following-char) ?1) | |
826 (progn (delete-char 1) | |
827 (insert ?0) | |
828 (forward-line 1) | |
829 (if (looking-at "Summary-Line:") | |
830 (forward-line 1)) | |
831 (insert "*** EOOH ***\n") | |
832 (forward-char -1) | |
833 (search-forward "\n*** EOOH ***\n") | |
834 (forward-line -1) | |
835 (let ((temp (point))) | |
836 (and (search-forward "\n\n" nil t) | |
837 (delete-region temp (point)))) | |
838 (goto-char (point-min)) | |
839 (search-forward "\n*** EOOH ***\n") | |
840 (narrow-to-region (point) (point-max))) | |
841 (rmail-reformat-message (point-min) (point-max))))) | |
842 | |
843 ;;;; *** Rmail Attributes and Keywords *** | |
844 | |
845 ;; Make a string describing current message's attributes and keywords | |
846 ;; and set it up as the name of a minor mode | |
847 ;; so it will appear in the mode line. | |
848 (defun rmail-display-labels () | |
849 (let ((blurb "") (beg (point-min-marker)) (end (point-max-marker))) | |
850 (save-excursion | |
851 (unwind-protect | |
852 (progn | |
853 (widen) | |
854 (goto-char (rmail-msgbeg rmail-current-message)) | |
855 (forward-line 1) | |
856 (if (looking-at "[01],") | |
857 (progn | |
858 (narrow-to-region (point) (progn (end-of-line) (point))) | |
859 ;; Truly valid BABYL format requires a space before each | |
860 ;; attribute or keyword name. Put them in if missing. | |
861 (let (buffer-read-only) | |
862 (goto-char (point-min)) | |
863 (while (search-forward "," nil t) | |
864 (or (looking-at "[ ,]") (eobp) | |
865 (insert " ")))) | |
866 (goto-char (point-max)) | |
867 (if (search-backward ",," nil 'move) | |
868 (progn | |
869 (if (> (point) (1+ (point-min))) | |
870 (setq blurb (buffer-substring (+ 1 (point-min)) (point)))) | |
871 (if (> (- (point-max) (point)) 2) | |
872 (setq blurb | |
873 (concat blurb | |
874 ";" | |
875 (buffer-substring (+ (point) 3) | |
876 (1- (point-max))))))))))) | |
877 ;; Note: we don't use save-restriction because that does not work right | |
878 ;; if changes are made outside the saved restriction | |
879 ;; before that restriction is restored. | |
880 (narrow-to-region beg end) | |
881 (set-marker beg nil) | |
882 (set-marker end nil))) | |
883 (while (string-match " +," blurb) | |
884 (setq blurb (concat (substring blurb 0 (match-beginning 0)) "," | |
885 (substring blurb (match-end 0))))) | |
886 (while (string-match ", +" blurb) | |
887 (setq blurb (concat (substring blurb 0 (match-beginning 0)) "," | |
888 (substring blurb (match-end 0))))) | |
889 (setq mode-line-process | |
890 (concat " " rmail-current-message "/" rmail-total-messages | |
891 blurb)))) | |
892 | |
893 ;; Turn an attribute of a message on or off according to STATE. | |
894 ;; ATTR is the name of the attribute, as a string. | |
895 ;; MSGNUM is message number to change; nil means current message. | |
896 (defun rmail-set-attribute (attr state &optional msgnum) | |
897 (let ((omax (point-max-marker)) | |
898 (omin (point-min-marker)) | |
899 (buffer-read-only nil)) | |
900 (or msgnum (setq msgnum rmail-current-message)) | |
901 (unwind-protect | |
902 (save-excursion | |
903 (widen) | |
904 (goto-char (+ 3 (rmail-msgbeg msgnum))) | |
905 (let ((curstate | |
906 (not | |
907 (null (search-backward (concat ", " attr ",") | |
908 (prog1 (point) (end-of-line)) t))))) | |
909 (or (eq curstate (not (not state))) | |
910 (if curstate | |
911 (delete-region (point) (1- (match-end 0))) | |
912 (beginning-of-line) | |
913 (forward-char 2) | |
914 (insert " " attr ",")))) | |
915 (if (string= attr "deleted") | |
916 (rmail-set-message-deleted-p msgnum state))) | |
917 ;; Note: we don't use save-restriction because that does not work right | |
918 ;; if changes are made outside the saved restriction | |
919 ;; before that restriction is restored. | |
920 (narrow-to-region omin omax) | |
921 (set-marker omin nil) | |
922 (set-marker omax nil) | |
923 (if (= msgnum rmail-current-message) | |
924 (rmail-display-labels))))) | |
925 | |
926 ;; Return t if the attributes/keywords line of msg number MSG | |
927 ;; contains a match for the regexp LABELS. | |
928 (defun rmail-message-labels-p (msg labels) | |
929 (save-excursion | |
930 (save-restriction | |
931 (widen) | |
932 (goto-char (rmail-msgbeg msg)) | |
933 (forward-char 3) | |
934 (re-search-backward labels (prog1 (point) (end-of-line)) t)))) | |
935 | |
936 ;;;; *** Rmail Message Selection And Support *** | |
937 | |
938 (defun rmail-msgend (n) | |
939 (marker-position (aref rmail-message-vector (1+ n)))) | |
940 | |
941 (defun rmail-msgbeg (n) | |
942 (marker-position (aref rmail-message-vector n))) | |
943 | |
944 (defun rmail-widen-to-current-msgbeg (function) | |
945 "Call FUNCTION with point at start of internal data of current message. | |
946 Assumes that bounds were previously narrowed to display the message in Rmail. | |
947 The bounds are widened enough to move point where desired, then narrowed | |
948 again afterward. | |
949 | |
950 FUNCTION may not change the visible text of the message, but it may | |
951 change the invisible header text." | |
952 (save-excursion | |
344 | 953 (let ((obeg (- (point-max) (point-min)))) |
270 | 954 (unwind-protect |
955 (progn | |
956 (narrow-to-region (rmail-msgbeg rmail-current-message) | |
957 (point-max)) | |
958 (goto-char (point-min)) | |
959 (funcall function)) | |
960 ;; Note: we don't use save-restriction because that does not work right | |
961 ;; if changes are made outside the saved restriction | |
962 ;; before that restriction is restored. | |
963 ;; Here we assume that changes made by FUNCTION | |
964 ;; occur before the visible region of the message. | |
344 | 965 (narrow-to-region (- (point-max) obeg) (point-max)))))) |
270 | 966 |
967 (defun rmail-forget-messages () | |
968 (unwind-protect | |
969 (if (vectorp rmail-message-vector) | |
970 (let* ((i 0) | |
971 (v rmail-message-vector) | |
972 (n (length v))) | |
973 (while (< i n) | |
974 (move-marker (aref v i) nil) | |
975 (setq i (1+ i))))) | |
976 (setq rmail-message-vector nil) | |
977 (setq rmail-deleted-vector nil))) | |
978 | |
979 (defun rmail-maybe-set-message-counters () | |
980 (if (not (and rmail-deleted-vector | |
981 rmail-message-vector | |
982 rmail-current-message | |
983 rmail-total-messages)) | |
984 (rmail-set-message-counters))) | |
985 | |
986 (defun rmail-count-new-messages (&optional nomsg) | |
987 (let* ((case-fold-search nil) | |
988 (total-messages 0) | |
989 (messages-head nil) | |
990 (deleted-head nil)) | |
991 (or nomsg (message "Counting new messages...")) | |
992 (goto-char (point-max)) | |
993 ;; Put at the end of messages-head | |
994 ;; the entry for message N+1, which marks | |
995 ;; the end of message N. (N = number of messages). | |
996 (search-backward "\n\^_") | |
997 (forward-char 1) | |
998 (setq messages-head (list (point-marker))) | |
999 (rmail-set-message-counters-counter (point-min)) | |
1000 (setq rmail-current-message (1+ rmail-total-messages)) | |
1001 (setq rmail-total-messages | |
1002 (+ rmail-total-messages total-messages)) | |
1003 (setq rmail-message-vector | |
1004 (vconcat rmail-message-vector (cdr messages-head))) | |
1005 (aset rmail-message-vector | |
1006 rmail-current-message (car messages-head)) | |
1007 (setq rmail-deleted-vector | |
1008 (concat rmail-deleted-vector deleted-head)) | |
1009 (setq rmail-summary-vector | |
1010 (vconcat rmail-summary-vector (make-vector total-messages nil))) | |
1011 (goto-char (point-min)) | |
1012 (or nomsg (message "Counting new messages...done (%d)" total-messages)))) | |
1013 | |
1014 (defun rmail-set-message-counters () | |
1015 (rmail-forget-messages) | |
1016 (save-excursion | |
1017 (save-restriction | |
1018 (widen) | |
1019 (let* ((point-save (point)) | |
1020 (total-messages 0) | |
1021 (messages-after-point) | |
1022 (case-fold-search nil) | |
1023 (messages-head nil) | |
1024 (deleted-head nil)) | |
1025 (message "Counting messages...") | |
1026 (goto-char (point-max)) | |
1027 ;; Put at the end of messages-head | |
1028 ;; the entry for message N+1, which marks | |
1029 ;; the end of message N. (N = number of messages). | |
1030 (search-backward "\n\^_") | |
1031 (forward-char 1) | |
1032 (setq messages-head (list (point-marker))) | |
1033 (rmail-set-message-counters-counter (min (point) point-save)) | |
1034 (setq messages-after-point total-messages) | |
1035 (rmail-set-message-counters-counter) | |
1036 (setq rmail-total-messages total-messages) | |
1037 (setq rmail-current-message | |
1038 (min total-messages | |
1039 (max 1 (- total-messages messages-after-point)))) | |
1040 (setq rmail-message-vector | |
1041 (apply 'vector (cons (point-min-marker) messages-head)) | |
1042 rmail-deleted-vector (concat "D" deleted-head) | |
1043 rmail-summary-vector (make-vector rmail-total-messages nil)) | |
1044 (message "Counting messages...done"))))) | |
1045 | |
1046 (defun rmail-set-message-counters-counter (&optional stop) | |
1047 (while (search-backward "\n\^_\^L\n" stop t) | |
1048 (forward-char 1) | |
1049 (setq messages-head (cons (point-marker) messages-head)) | |
1050 (save-excursion | |
1051 (setq deleted-head | |
1052 (cons (if (search-backward ", deleted," | |
1053 (prog1 (point) | |
1054 (forward-line 2)) | |
1055 t) | |
1056 ?D ?\ ) | |
1057 deleted-head))) | |
1058 (if (zerop (% (setq total-messages (1+ total-messages)) 20)) | |
1059 (message "Counting messages...%d" total-messages)))) | |
1060 | |
1061 (defun rmail-beginning-of-message () | |
1062 "Show current message starting from the beginning." | |
1063 (interactive) | |
1064 (rmail-show-message rmail-current-message)) | |
1065 | |
1066 (defun rmail-show-message (&optional n) | |
1067 "Show message number N (prefix argument), counting from start of file." | |
1068 (interactive "p") | |
1069 (rmail-maybe-set-message-counters) | |
1070 (widen) | |
1071 (if (zerop rmail-total-messages) | |
1072 (progn (narrow-to-region (point-min) (1- (point-max))) | |
1073 (goto-char (point-min)) | |
1074 (setq mode-line-process nil)) | |
1075 (let (blurb) | |
1076 (if (not n) | |
1077 (setq n rmail-current-message) | |
1078 (cond ((<= n 0) | |
1079 (setq n 1 | |
1080 rmail-current-message 1 | |
1081 blurb "No previous message")) | |
1082 ((> n rmail-total-messages) | |
1083 (setq n rmail-total-messages | |
1084 rmail-current-message rmail-total-messages | |
1085 blurb "No following message")) | |
1086 (t | |
1087 (setq rmail-current-message n)))) | |
1088 (let ((beg (rmail-msgbeg n)) | |
1089 (end (rmail-msgend n))) | |
1090 (goto-char beg) | |
1091 (forward-line 1) | |
1092 (if (= (following-char) ?0) | |
1093 (progn | |
1094 (rmail-reformat-message beg end) | |
1095 (rmail-set-attribute "unseen" nil)) | |
1096 (search-forward "\n*** EOOH ***\n" end t) | |
1097 (narrow-to-region (point) end)) | |
1098 (goto-char (point-min)) | |
1099 (rmail-display-labels) | |
1100 (run-hooks 'rmail-show-message-hook) | |
1101 (if blurb | |
1102 (message blurb)))))) | |
1103 | |
1104 (defun rmail-next-message (n) | |
1105 "Show following message whether deleted or not. | |
1106 With prefix arg N, moves forward N messages, or backward if N is negative." | |
1107 (interactive "p") | |
1108 (rmail-maybe-set-message-counters) | |
1109 (rmail-show-message (+ rmail-current-message n))) | |
1110 | |
1111 (defun rmail-previous-message (n) | |
1112 "Show previous message whether deleted or not. | |
1113 With prefix arg N, moves backward N messages, or forward if N is negative." | |
1114 (interactive "p") | |
1115 (rmail-next-message (- n))) | |
1116 | |
1117 (defun rmail-next-undeleted-message (n) | |
1118 "Show following non-deleted message. | |
1119 With prefix arg N, moves forward N non-deleted messages, | |
1120 or backward if N is negative." | |
1121 (interactive "p") | |
1122 (rmail-maybe-set-message-counters) | |
1123 (let ((lastwin rmail-current-message) | |
1124 (current rmail-current-message)) | |
1125 (while (and (> n 0) (< current rmail-total-messages)) | |
1126 (setq current (1+ current)) | |
1127 (if (not (rmail-message-deleted-p current)) | |
1128 (setq lastwin current n (1- n)))) | |
1129 (while (and (< n 0) (> current 1)) | |
1130 (setq current (1- current)) | |
1131 (if (not (rmail-message-deleted-p current)) | |
1132 (setq lastwin current n (1+ n)))) | |
1133 (if (/= lastwin rmail-current-message) | |
1134 (rmail-show-message lastwin)) | |
1135 (if (< n 0) | |
997
894201c58bb8
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
937
diff
changeset
|
1136 (message "No previous nondeleted message")) |
270 | 1137 (if (> n 0) |
997
894201c58bb8
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
937
diff
changeset
|
1138 (message "No following nondeleted message")))) |
270 | 1139 |
1140 (defun rmail-previous-undeleted-message (n) | |
1141 "Show previous non-deleted message. | |
1142 With prefix argument N, moves backward N non-deleted messages, | |
1143 or forward if N is negative." | |
1144 (interactive "p") | |
1145 (rmail-next-undeleted-message (- n))) | |
1146 | |
1147 (defun rmail-first-message () | |
1148 "Show first message in file." | |
1149 (interactive) | |
1150 (rmail-maybe-set-message-counters) | |
1151 (rmail-show-message 1)) | |
1152 | |
1153 (defun rmail-last-message () | |
1154 "Show last message in file." | |
1155 (interactive) | |
1156 (rmail-maybe-set-message-counters) | |
1157 (rmail-show-message rmail-total-messages)) | |
1158 | |
1159 (defun rmail-what-message () | |
1160 (let ((where (point)) | |
1161 (low 1) | |
1162 (high rmail-total-messages) | |
1163 (mid (/ rmail-total-messages 2))) | |
1164 (while (> (- high low) 1) | |
1165 (if (>= where (rmail-msgbeg mid)) | |
1166 (setq low mid) | |
1167 (setq high mid)) | |
1168 (setq mid (+ low (/ (- high low) 2)))) | |
1169 (if (>= where (rmail-msgbeg high)) high low))) | |
1170 | |
1171 (defvar rmail-search-last-regexp nil) | |
874
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1172 (defun rmail-search (regexp &optional n) |
270 | 1173 "Show message containing next match for REGEXP. |
874
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1174 Prefix argument gives repeat count; negative argument means search |
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1175 backwards (through earlier messages). |
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1176 Interactively, empty argument means use same regexp used last time." |
270 | 1177 (interactive |
1178 (let* ((reversep (< (prefix-numeric-value current-prefix-arg) 0)) | |
1179 (prompt | |
1180 (concat (if reversep "Reverse " "") "Rmail search (regexp): ")) | |
1181 regexp) | |
1182 (if rmail-search-last-regexp | |
1183 (setq prompt (concat prompt | |
1184 "(default " | |
1185 rmail-search-last-regexp | |
1186 ") "))) | |
1187 (setq regexp (read-string prompt)) | |
1188 (cond ((not (equal regexp "")) | |
1189 (setq rmail-search-last-regexp regexp)) | |
1190 ((not rmail-search-last-regexp) | |
1191 (error "No previous Rmail search string"))) | |
874
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1192 (list rmail-search-last-regexp |
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1193 (prefix-numeric-value current-prefix-arg)))) |
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1194 (or n (setq n 1)) |
270 | 1195 (message "%sRmail search for %s..." |
937
0f082d63bfd6
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
874
diff
changeset
|
1196 (if (< n 0) "Reverse " "") |
270 | 1197 regexp) |
1198 (rmail-maybe-set-message-counters) | |
1199 (let ((omin (point-min)) | |
1200 (omax (point-max)) | |
1201 (opoint (point)) | |
1202 win | |
874
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1203 (reversep (< n 0)) |
270 | 1204 (msg rmail-current-message)) |
1205 (unwind-protect | |
1206 (progn | |
1207 (widen) | |
874
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1208 (while (/= n 0) |
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1209 ;; Check messages one by one, advancing message number up or down |
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1210 ;; but searching forward through each message. |
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1211 (if reversep |
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1212 (while (and (null win) (> msg 1)) |
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1213 (goto-char (rmail-msgbeg (setq msg (1- msg)))) |
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1214 (setq win (re-search-forward |
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1215 regexp (rmail-msgend msg) t))) |
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1216 (while (and (null win) (< msg rmail-total-messages)) |
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1217 (goto-char (rmail-msgbeg (setq msg (1+ msg)))) |
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1218 (setq win (re-search-forward regexp (rmail-msgend msg) t)))) |
937
0f082d63bfd6
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
874
diff
changeset
|
1219 (setq n (+ n (if reversep 1 -1))))) |
270 | 1220 (if win |
1221 (progn | |
1222 ;; If this is a reverse search and we found a message, | |
1223 ;; search backward thru this message to position point. | |
1224 (if reversep | |
1225 (progn | |
1226 (goto-char (rmail-msgend msg)) | |
1227 (re-search-backward | |
1228 regexp (rmail-msgbeg msg) t))) | |
1229 (setq win (point)) | |
1230 (rmail-show-message msg) | |
1231 (message "%sRmail search for %s...done" | |
1232 (if reversep "Reverse " "") | |
1233 regexp) | |
1234 (goto-char win)) | |
1235 (goto-char opoint) | |
1236 (narrow-to-region omin omax) | |
1237 (ding) | |
1238 (message "Search failed: %s" regexp))))) | |
1239 | |
874
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1240 (defun rmail-search-backwards (regexp &optional n) |
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1241 "Show message containing previous match for REGEXP. |
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1242 Prefix argument gives repeat count; negative argument means search |
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1243 forward (through later messages). |
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1244 Interactively, empty argument means use same regexp used last time." |
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1245 (interactive |
937
0f082d63bfd6
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
874
diff
changeset
|
1246 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg) 0)) |
874
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1247 (prompt |
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1248 (concat (if reversep "Reverse " "") "Rmail search (regexp): ")) |
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1249 regexp) |
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1250 (if rmail-search-last-regexp |
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1251 (setq prompt (concat prompt |
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1252 "(default " |
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1253 rmail-search-last-regexp |
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1254 ") "))) |
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1255 (setq regexp (read-string prompt)) |
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1256 (cond ((not (equal regexp "")) |
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1257 (setq rmail-search-last-regexp regexp)) |
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1258 ((not rmail-search-last-regexp) |
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1259 (error "No previous Rmail search string"))) |
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1260 (list rmail-search-last-regexp |
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1261 (prefix-numeric-value current-prefix-arg)))) |
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1262 (rmail-search regexp (- (or n -1)))) |
b945f592b94d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1263 |
270 | 1264 ;; Show the first message which has the `unseen' attribute. |
1265 (defun rmail-first-unseen-message () | |
1266 (let ((current 1) | |
1267 found) | |
1268 (save-restriction | |
1269 (widen) | |
1270 (while (and (not found) (< current rmail-total-messages)) | |
1271 (if (rmail-message-labels-p current ", ?\\(unseen\\),") | |
346 | 1272 (setq found current)) |
1273 (setq current (1+ current)))) | |
270 | 1274 (if found |
1275 (rmail-show-message found)))) | |
1276 | |
1277 ;;;; *** Rmail Message Deletion Commands *** | |
1278 | |
1279 (defun rmail-message-deleted-p (n) | |
1280 (= (aref rmail-deleted-vector n) ?D)) | |
1281 | |
1282 (defun rmail-set-message-deleted-p (n state) | |
1283 (aset rmail-deleted-vector n (if state ?D ?\ ))) | |
1284 | |
1285 (defun rmail-delete-message () | |
1286 "Delete this message and stay on it." | |
1287 (interactive) | |
1288 (rmail-set-attribute "deleted" t)) | |
1289 | |
1290 (defun rmail-undelete-previous-message () | |
1291 "Back up to deleted message, select it, and undelete it." | |
1292 (interactive) | |
1293 (let ((msg rmail-current-message)) | |
1294 (while (and (> msg 0) | |
1295 (not (rmail-message-deleted-p msg))) | |
1296 (setq msg (1- msg))) | |
1297 (if (= msg 0) | |
1298 (error "No previous deleted message") | |
1299 (if (/= msg rmail-current-message) | |
1300 (rmail-show-message msg)) | |
1301 (rmail-set-attribute "deleted" nil)))) | |
1302 | |
1303 (defun rmail-delete-forward (&optional backward) | |
1304 "Delete this message and move to next nondeleted one. | |
1305 Deleted messages stay in the file until the \\[rmail-expunge] command is given. | |
819
5bbabfcef929
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
814
diff
changeset
|
1306 With prefix argument, delete and move backward." |
270 | 1307 (interactive "P") |
1308 (rmail-set-attribute "deleted" t) | |
830
d7f1e2db9faf
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
819
diff
changeset
|
1309 (rmail-next-undeleted-message (if backward -1 1))) |
270 | 1310 |
1311 (defun rmail-delete-backward () | |
1312 "Delete this message and move to previous nondeleted one. | |
1313 Deleted messages stay in the file until the \\[rmail-expunge] command is given." | |
1314 (interactive) | |
1315 (rmail-delete-forward t)) | |
1316 | |
1317 (defun rmail-expunge () | |
1318 "Actually erase all deleted messages in the file." | |
1319 (interactive) | |
1320 (message "Expunging deleted messages...") | |
1321 ;; Discard all undo records for this buffer. | |
1322 (or (eq buffer-undo-list t) | |
1323 (setq buffer-undo-list nil)) | |
1324 (rmail-maybe-set-message-counters) | |
1325 (let* ((omax (- (buffer-size) (point-max))) | |
1326 (omin (- (buffer-size) (point-min))) | |
1327 (opoint (if (and (> rmail-current-message 0) | |
1328 (= ?D (aref rmail-deleted-vector rmail-current-message))) | |
1329 0 (- (point) (point-min)))) | |
1330 (messages-head (cons (aref rmail-message-vector 0) nil)) | |
1331 (messages-tail messages-head) | |
1332 ;; Don't make any undo records for the expunging. | |
1333 (buffer-undo-list t) | |
1334 (win)) | |
1335 (unwind-protect | |
1336 (save-excursion | |
1337 (widen) | |
1338 (goto-char (point-min)) | |
1339 (let ((counter 0) | |
1340 (number 1) | |
1341 (total rmail-total-messages) | |
1342 (new-message-number rmail-current-message) | |
1343 (new-summary nil) | |
1344 (buffer-read-only nil) | |
1345 (messages rmail-message-vector) | |
1346 (deleted rmail-deleted-vector) | |
1347 (summary rmail-summary-vector)) | |
1348 (setq rmail-total-messages nil | |
1349 rmail-current-message nil | |
1350 rmail-message-vector nil | |
1351 rmail-deleted-vector nil | |
1352 rmail-summary-vector nil) | |
1353 (while (<= number total) | |
1354 (if (= (aref deleted number) ?D) | |
1355 (progn | |
1356 (delete-region | |
1357 (marker-position (aref messages number)) | |
1358 (marker-position (aref messages (1+ number)))) | |
1359 (move-marker (aref messages number) nil) | |
1360 (if (> new-message-number counter) | |
1361 (setq new-message-number (1- new-message-number)))) | |
1362 (setq counter (1+ counter)) | |
1363 (setq messages-tail | |
1364 (setcdr messages-tail | |
1365 (cons (aref messages number) nil))) | |
1366 (setq new-summary | |
1367 (cons (if (= counter number) (aref summary (1- number))) | |
1368 new-summary))) | |
1369 (if (zerop (% (setq number (1+ number)) 20)) | |
1370 (message "Expunging deleted messages...%d" number))) | |
1371 (setq messages-tail | |
1372 (setcdr messages-tail | |
1373 (cons (aref messages number) nil))) | |
1374 (setq rmail-current-message new-message-number | |
1375 rmail-total-messages counter | |
1376 rmail-message-vector (apply 'vector messages-head) | |
1377 rmail-deleted-vector (make-string (1+ counter) ?\ ) | |
1378 rmail-summary-vector (vconcat (nreverse new-summary)) | |
1379 win t))) | |
1380 (message "Expunging deleted messages...done") | |
1381 (if (not win) | |
1382 (narrow-to-region (- (buffer-size) omin) (- (buffer-size) omax))) | |
1383 (rmail-show-message | |
1384 (if (zerop rmail-current-message) 1 nil)) | |
1385 (forward-char opoint)))) | |
1386 | |
1387 ;;;; *** Rmail Mailing Commands *** | |
1388 | |
1389 (defun rmail-mail () | |
1390 "Send mail in another window. While composing the message, use | |
1391 \\[mail-yank-original] to yank the original message into it." | |
1392 (interactive) | |
1393 (mail-other-window nil nil nil nil nil (current-buffer))) | |
1394 | |
1395 (defun rmail-continue () | |
1396 "Continue composing outgoing message previously being composed." | |
1397 (interactive) | |
1398 (mail-other-window t)) | |
1399 | |
1400 (defun rmail-reply (just-sender) | |
1401 "Reply to the current message. | |
1402 Normally include CC: to all other recipients of original message; | |
1403 prefix argument means ignore them. While composing the reply, | |
1404 use \\[mail-yank-original] to yank the original message into it." | |
1405 (interactive "P") | |
1406 (let (from reply-to cc subject date to message-id resent-reply-to) | |
1407 (save-excursion | |
1408 (save-restriction | |
1409 (widen) | |
1410 (goto-char (rmail-msgbeg rmail-current-message)) | |
1411 (forward-line 1) | |
1412 (if (= (following-char) ?0) | |
1413 (narrow-to-region | |
1414 (progn (forward-line 2) | |
1415 (point)) | |
1416 (progn (search-forward "\n\n" (rmail-msgend rmail-current-message) | |
1417 'move) | |
1418 (point))) | |
1419 (narrow-to-region (point) | |
1420 (progn (search-forward "\n*** EOOH ***\n") | |
1421 (beginning-of-line) (point)))) | |
1422 (setq resent-reply-to (mail-fetch-field "resent-reply-to" t) | |
1423 from (mail-fetch-field "from") | |
1424 reply-to (or resent-reply-to | |
1425 (mail-fetch-field "reply-to" nil t) | |
1426 from) | |
1427 cc (cond (just-sender nil) | |
1428 (resent-reply-to (mail-fetch-field "resent-cc" t)) | |
1429 (t (mail-fetch-field "cc" nil t))) | |
1430 subject (or (and resent-reply-to | |
1431 (mail-fetch-field "resent-subject" t)) | |
1432 (mail-fetch-field "subject")) | |
1433 date (cond (resent-reply-to | |
1434 (mail-fetch-field "resent-date" t)) | |
1435 ((mail-fetch-field "date"))) | |
1436 to (cond (resent-reply-to | |
1437 (mail-fetch-field "resent-to" t)) | |
1438 ((mail-fetch-field "to" nil t)) | |
1439 ;((mail-fetch-field "apparently-to")) ack gag barf | |
1440 (t "")) | |
1441 message-id (cond (resent-reply-to | |
1442 (mail-fetch-field "resent-message-id" t)) | |
1443 ((mail-fetch-field "message-id")))))) | |
1444 (and subject | |
1445 (string-match "\\`Re: " subject) | |
1446 (setq subject (substring subject 4))) | |
1447 (mail-other-window nil | |
1448 (mail-strip-quoted-names reply-to) | |
1449 subject | |
1450 (rmail-make-in-reply-to-field from date message-id) | |
1451 (if just-sender | |
1452 nil | |
1453 (let* ((cc-list (rmail-dont-reply-to | |
1454 (mail-strip-quoted-names | |
1455 (if (null cc) to (concat to ", " cc)))))) | |
1456 (if (string= cc-list "") nil cc-list))) | |
1457 (current-buffer) | |
1458 (list (list '(lambda (buf msgnum) | |
1459 (save-excursion | |
1460 (set-buffer buf) | |
1461 (rmail-set-attribute "answered" t msgnum))) | |
1462 (current-buffer) rmail-current-message))))) | |
1463 | |
1464 (defun rmail-make-in-reply-to-field (from date message-id) | |
1465 (cond ((not from) | |
1466 (if message-id | |
1467 message-id | |
1468 nil)) | |
1469 (mail-use-rfc822 | |
1470 (require 'rfc822) | |
1471 (let ((tem (car (rfc822-addresses from)))) | |
1472 (if message-id | |
1473 (if (string-match | |
1474 (regexp-quote (if (string-match "@[^@]*\\'" tem) | |
1475 (substring tem 0 (match-beginning 0)) | |
1476 tem)) | |
1477 message-id) | |
1478 ;; Message-ID is sufficiently informative | |
1479 message-id | |
1480 (concat message-id " (" tem ")")) | |
1481 ;; Use prin1 to fake RFC822 quoting | |
1482 (let ((field (prin1-to-string tem))) | |
1483 (if date | |
1484 (concat field "'s message of " date) | |
1485 field))))) | |
1486 ((let* ((foo "[^][\000-\037\177-\377()<>@,;:\\\" ]+") | |
1487 (bar "[^][\000-\037\177-\377()<>@,;:\\\"]+")) | |
1488 ;; Can't use format because format loses on \000 (unix *^&%*^&%$!!) | |
1489 (or (string-match (concat "\\`[ \t]*\\(" bar | |
1490 "\\)\\(<" foo "@" foo ">\\)?[ \t]*\\'") | |
1491 ;; "Unix Loser <Foo@bar.edu>" => "Unix Loser" | |
1492 from) | |
1493 (string-match (concat "\\`[ \t]*<" foo "@" foo ">[ \t]*(\\(" | |
1494 bar "\\))[ \t]*\\'") | |
1495 ;; "<Bugs@bar.edu>" (Losing Unix) => "Losing Unix" | |
1496 from))) | |
1497 (let ((start (match-beginning 1)) | |
1498 (end (match-end 1))) | |
1499 ;; Trim whitespace which above regexp match allows | |
1500 (while (and (< start end) | |
1501 (memq (aref from start) '(?\t ?\ ))) | |
1502 (setq start (1+ start))) | |
1503 (while (and (< start end) | |
1504 (memq (aref from (1- end)) '(?\t ?\ ))) | |
1505 (setq end (1- end))) | |
1506 (let ((field (substring from start end))) | |
1507 (if date (setq field (concat "message from " field " on " date))) | |
1508 (if message-id | |
1509 ;; "<AA259@bar.edu> (message from Unix Loser on 1-Apr-89)" | |
1510 (concat message-id " (" field ")") | |
1511 field)))) | |
1512 (t | |
1513 ;; If we can't kludge it simply, do it correctly | |
1514 (let ((mail-use-rfc822 t)) | |
1515 (rmail-make-in-reply-to-field from date message-id))))) | |
1516 | |
1517 (defun rmail-forward () | |
1518 "Forward the current message to another user." | |
1519 (interactive) | |
1520 (let ((forward-buffer (current-buffer)) | |
1521 (subject (concat "[" | |
1522 (mail-strip-quoted-names (mail-fetch-field "From")) | |
1523 ": " (or (mail-fetch-field "Subject") "") "]"))) | |
1137
6f2689fa1c37
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1135
diff
changeset
|
1524 ;; Turn off the usual actions for initializing the message body |
6f2689fa1c37
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1135
diff
changeset
|
1525 ;; because we want to get only the text from the failure message. |
6f2689fa1c37
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1135
diff
changeset
|
1526 (let (mail-signature mail-setup-hook) |
6f2689fa1c37
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1135
diff
changeset
|
1527 ;; If only one window, use it for the mail buffer. |
6f2689fa1c37
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1135
diff
changeset
|
1528 ;; Otherwise, use another window for the mail buffer |
6f2689fa1c37
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1135
diff
changeset
|
1529 ;; so that the Rmail buffer remains visible |
6f2689fa1c37
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1135
diff
changeset
|
1530 ;; and sending the mail will get back to it. |
6f2689fa1c37
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1135
diff
changeset
|
1531 (if (funcall (if (one-window-p t) |
6f2689fa1c37
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1135
diff
changeset
|
1532 (function mail) |
6f2689fa1c37
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1135
diff
changeset
|
1533 (function mail-other-window)) |
6f2689fa1c37
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1135
diff
changeset
|
1534 nil nil subject nil nil nil |
6f2689fa1c37
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1135
diff
changeset
|
1535 (list (list (function (lambda (buf msgnum) |
6f2689fa1c37
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1135
diff
changeset
|
1536 (save-excursion |
6f2689fa1c37
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1135
diff
changeset
|
1537 (set-buffer buf) |
6f2689fa1c37
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1135
diff
changeset
|
1538 (rmail-set-attribute "forwarded" t msgnum)))) |
6f2689fa1c37
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1135
diff
changeset
|
1539 (current-buffer) |
6f2689fa1c37
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1135
diff
changeset
|
1540 rmail-current-message))) |
6f2689fa1c37
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1135
diff
changeset
|
1541 (save-excursion |
6f2689fa1c37
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1135
diff
changeset
|
1542 (goto-char (point-max)) |
6f2689fa1c37
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1135
diff
changeset
|
1543 (forward-line 1) |
6f2689fa1c37
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1135
diff
changeset
|
1544 (insert-buffer forward-buffer)))))) |
270 | 1545 |
1546 (defun rmail-resend (address &optional from comment mail-alias-file) | |
1547 "Resend current message to ADDRESSES. | |
1548 ADDRESSES should be a single address, a a string consisting of several | |
1549 addresses separated by commas, or a list of addresses. | |
1550 | |
1551 Optional FROM is the address to resend the message from, and | |
1552 defaults to the username of the person redistributing the message. | |
1553 Optional COMMENT is a string that will be inserted as a comment in the | |
1554 resent message. | |
1555 Optional ALIAS-FILE is alternate aliases file to be used by sendmail, | |
1556 typically for purposes of moderating a list." | |
1557 (interactive "sResend to: ") | |
1558 (if (not from) (setq from (user-login-name))) | |
1559 (let ((tembuf (generate-new-buffer " sendmail temp")) | |
1560 (mail-header-separator "") | |
1561 (case-fold-search nil) | |
1562 (mailbuf (current-buffer))) | |
1563 (unwind-protect | |
1564 (save-excursion | |
1565 ;;>> Copy message into temp buffer | |
1566 (set-buffer tembuf) | |
1567 (insert-buffer-substring mailbuf) | |
1568 (goto-char (point-min)) | |
1569 ;;>> Insert resent-from: | |
1570 (insert "Resent-From: " from "\n") | |
1571 (insert "Resent-Date: " (current-time-string) "\n") | |
1572 ;;>> Insert resent-to: and bcc if need be. | |
1573 (let ((before (point))) | |
1574 (insert "Resent-To: " (if (stringp address) | |
1575 address | |
1576 (mapconcat 'identity address ",\n\t")) | |
1577 "\n") | |
1578 (expand-mail-aliases before (point))) | |
1579 ;;>> Set up comment, if any. | |
1580 (if (and (sequencep comment) (not (zerop (length comment)))) | |
1581 (let ((before (point)) | |
1582 after) | |
1583 (insert comment) | |
1584 (or (eolp) (insert "\n")) | |
1585 (setq after (point)) | |
1586 (goto-char before) | |
1587 (while (< (point) after) | |
1588 (insert "Resent-Comment: ") | |
1589 (forward-line 1)))) | |
1590 ;; Don't expand aliases in the destination fields | |
1591 ;; of the original message. | |
1592 (let (mail-aliases) | |
1593 (sendmail-send-it))) | |
1594 (kill-buffer tembuf)))) | |
1595 | |
1267
1e1a54ebb29b
(mail-unsent-separator): Add another alternative.
Richard M. Stallman <rms@gnu.org>
parents:
1165
diff
changeset
|
1596 (defvar mail-unsent-separator |
1e1a54ebb29b
(mail-unsent-separator): Add another alternative.
Richard M. Stallman <rms@gnu.org>
parents:
1165
diff
changeset
|
1597 "^ *----- Unsent message follows ----- *$\\|^ *--- Returned message --- *$") |
270 | 1598 |
1599 (defun rmail-retry-failure () | |
1600 "Edit a mail message which is based on the contents of the current message. | |
1601 For a message rejected by the mail system, extract the interesting headers and | |
1602 the body of the original message; otherwise copy the current message." | |
1603 (interactive) | |
1604 (require 'mail-utils) | |
1605 (let (to subj irp2 cc orig-message) | |
1606 (save-excursion | |
1607 ;; Narrow down to just the quoted original message | |
1608 (rmail-beginning-of-message) | |
1609 (or (re-search-forward mail-unsent-separator nil t) | |
1610 (error "Cannot parse this as a failure message")) | |
1611 (save-restriction | |
1612 (narrow-to-region (point) (point-max)) | |
1613 ;; Now mail-fetch-field will get from headers of the original message, | |
1614 ;; not from the headers of the rejection. | |
1615 (setq to (mail-fetch-field "To") | |
1616 subj (mail-fetch-field "Subject") | |
1617 irp2 (mail-fetch-field "In-reply-to") | |
1618 cc (mail-fetch-field "Cc")) | |
1619 ;; Get the entire text (not headers) of the original message. | |
1620 (setq orig-message | |
1621 (buffer-substring | |
1622 (progn (search-forward "\n\n") (point)) | |
1623 (point-max))))) | |
1624 ;; Start sending a new message; default header fields from the original. | |
1135
e33f6475229a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1112
diff
changeset
|
1625 ;; Turn off the usual actions for initializing the message body |
e33f6475229a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1112
diff
changeset
|
1626 ;; because we want to get only the text from the failure message. |
e33f6475229a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1112
diff
changeset
|
1627 (let (mail-signature mail-setup-hook) |
e33f6475229a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1112
diff
changeset
|
1628 (if (mail-other-window nil to subj irp2 cc (current-buffer)) |
e33f6475229a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1112
diff
changeset
|
1629 ;; Insert original text as initial text of new draft message. |
e33f6475229a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1112
diff
changeset
|
1630 (progn |
e33f6475229a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1112
diff
changeset
|
1631 (goto-char (point-max)) |
e33f6475229a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1112
diff
changeset
|
1632 (insert orig-message) |
e33f6475229a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1112
diff
changeset
|
1633 (goto-char (point-min)) |
e33f6475229a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1112
diff
changeset
|
1634 (end-of-line)))))) |
270 | 1635 |
1636 ;;;; *** Rmail Specify Inbox Files *** | |
1637 | |
1638 (autoload 'set-rmail-inbox-list "rmailmsc" | |
1639 "Set the inbox list of the current RMAIL file to FILE-NAME. | |
1640 This may be a list of file names separated by commas. | |
1641 If FILE-NAME is empty, remove any inbox list." | |
1642 t) | |
1643 | |
1644 ;;;; *** Rmail Commands for Labels *** | |
1645 | |
1646 (autoload 'rmail-add-label "rmailkwd" | |
1647 "Add LABEL to labels associated with current RMAIL message. | |
1648 Completion is performed over known labels when reading." | |
1649 t) | |
1650 | |
1651 (autoload 'rmail-kill-label "rmailkwd" | |
1652 "Remove LABEL from labels associated with current RMAIL message. | |
1653 Completion is performed over known labels when reading." | |
1654 t) | |
1655 | |
1656 (autoload 'rmail-next-labeled-message "rmailkwd" | |
1657 "Show next message with LABEL. Defaults to last label used. | |
1658 With prefix argument N moves forward N messages with this label." | |
1659 t) | |
1660 | |
1661 (autoload 'rmail-previous-labeled-message "rmailkwd" | |
1662 "Show previous message with LABEL. Defaults to last label used. | |
1663 With prefix argument N moves backward N messages with this label." | |
1664 t) | |
1665 | |
1666 ;;;; *** Rmail Edit Mode *** | |
1667 | |
1668 (autoload 'rmail-edit-current-message "rmailedit" | |
1669 "Edit the contents of the current message" | |
1670 t) | |
1671 | |
1672 ;;;; *** Rmail Summary Mode *** | |
1673 | |
1674 (autoload 'rmail-summary "rmailsum" | |
1675 "Display a summary of all messages, one line per message." | |
1676 t) | |
1677 | |
1678 (autoload 'rmail-summary-by-labels "rmailsum" | |
1679 "Display a summary of all messages with one or more LABELS. | |
1680 LABELS should be a string containing the desired labels, separated by commas." | |
1681 t) | |
1682 | |
1683 (autoload 'rmail-summary-by-recipients "rmailsum" | |
1684 "Display a summary of all messages with the given RECIPIENTS. | |
1685 Normally checks the To, From and Cc fields of headers; but if PRIMARY-ONLY | |
1686 is non-nil (prefix arg given), only look in the To and From fields. | |
1687 RECIPIENTS is a string of names separated by commas." | |
1688 t) | |
1689 | |
1690 ;;;; *** Rmail output messages to files *** | |
1691 | |
1692 (autoload 'rmail-output-to-rmail-file "rmailout" | |
1693 "Append the current message to an Rmail file named FILE-NAME. | |
1694 If the file does not exist, ask if it should be created. | |
1695 If file is being visited, the message is appended to the Emacs | |
1696 buffer visiting that file." | |
1697 t) | |
1698 | |
1699 (autoload 'rmail-output "rmailout" | |
1700 "Append this message to Unix mail file named FILE-NAME." | |
1701 t) | |
1702 | |
1703 ;;;; *** Rmail undigestification *** | |
1704 | |
1705 (autoload 'undigestify-rmail-message "undigest" | |
1706 "Break up a digest message into its constituent messages. | |
1707 Leaves original message, deleted, before the undigestified messages." | |
1708 t) | |
584 | 1709 |
1710 (provide 'rmail) | |
1711 | |
658
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
621
diff
changeset
|
1712 ;;; rmail.el ends here |