]> code.delx.au - gnu-emacs/blob - lisp/mail/rmail.el
(rmail-summary-goto-msg): Get rmail-total-messages from the rmail buffer.
[gnu-emacs] / lisp / mail / rmail.el
1 ;;; rmail.el --- main code of "RMAIL" mail reader for Emacs.
2
3 ;; Copyright (C) 1985,86,87,88,93,94 Free Software Foundation, Inc.
4
5 ;; Maintainer: FSF
6 ;; Keywords: mail
7
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
12 ;; the Free Software Foundation; either version 2, or (at your option)
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
24 ;;; Code:
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 ;; Extended by Bob Weiner of Motorola
32 ;; New features include: rmail and rmail-summary buffers remain
33 ;; synchronized and key bindings basically operate the same way in both
34 ;; buffers, summary by topic or by regular expression, rmail-reply-prefix
35 ;; variable, and a bury rmail buffer (wipe) command.
36 ;;
37
38 (require 'mail-utils)
39
40 ;; For Emacs V18 compatibility
41 (and (not (fboundp 'buffer-disable-undo))
42 (fboundp 'buffer-flush-undo)
43 (defalias 'buffer-disable-undo 'buffer-flush-undo))
44
45 ; These variables now declared in paths.el.
46 ;(defvar rmail-spool-directory "/usr/spool/mail/"
47 ; "This is the name of the directory used by the system mailer for\n\
48 ;delivering new mail. It's name should end with a slash.")
49 ;(defvar rmail-file-name
50 ; (expand-file-name "~/RMAIL")
51 ; "")
52
53 (defvar rmail-movemail-program nil
54 "If non-nil, name of program for fetching new mail.")
55
56 ;;;###autoload
57 (defvar rmail-dont-reply-to-names nil "\
58 *A regexp specifying names to prune of reply to messages.
59 A value of nil means exclude your own name only.")
60
61 ;;;###autoload
62 (defvar rmail-default-dont-reply-to-names "info-" "\
63 A regular expression specifying part of the value of the default value of
64 the variable `rmail-dont-reply-to-names', for when the user does not set
65 `rmail-dont-reply-to-names' explicitly. (The other part of the default
66 value is the user's name.)
67 It is useful to set this variable in the site customization file.")
68
69 ;;;###autoload
70 (defvar rmail-ignored-headers "^via:\\|^mail-from:\\|^origin:\\|^status:\\|^received:\\|^x400-originator:\\|^x400-recipients:\\|^x400-received:\\|^x400-mts-identifier:\\|^x400-content-type:\\|^\\(resent-\\|\\)message-id:\\|^summary-line:" "\
71 ^received:\\|^x400-originator:\\|^x400-recipients:\\|^x400-received:\\|\
72 ^x400-mts-identifier:\\|^x400-content-type:\\|^message-id:\\|^summary-line:"
73 "*Regexp to match Header fields that Rmail should normally hide.")
74
75 ;;;###autoload
76 (defvar rmail-retry-ignored-headers nil "\
77 *Headers that should be stripped when retrying a failed message.")
78
79 ;;;###autoload
80 (defvar rmail-highlighted-headers "^From:\\|^Subject:" "\
81 *Regexp to match Header fields that Rmail should normally highlight.
82 A value of nil means don't highlight.
83 See also `rmail-highlight-face'.")
84
85 ;;;###autoload
86 (defvar rmail-highlight-face nil "\
87 *Face used by Rmail for highlighting headers.")
88
89 ;;;###autoload
90 (defvar rmail-delete-after-output nil "\
91 *Non-nil means automatically delete a message that is copied to a file.")
92
93 ;;;###autoload
94 (defvar rmail-primary-inbox-list nil "\
95 *List of files which are inboxes for user's primary mail file `~/RMAIL'.
96 `nil' means the default, which is (\"/usr/spool/mail/$USER\")
97 \(the name varies depending on the operating system,
98 and the value of the environment variable MAIL overrides it).")
99
100 ;;;###autoload
101 (defvar rmail-mail-new-frame nil
102 "*Non-nil means Rmail makes a new frame for composing outgoing mail.")
103
104 ;;;###autoload
105 (defvar rmail-secondary-file-directory "~/"
106 "*Directory for additional secondary Rmail files.")
107 ;;;###autoload
108 (defvar rmail-secondary-file-regexp "\\.xmail$"
109 "*Regexp for which files are secondary Rmail files.")
110
111 ;; These may be altered by site-init.el to match the format of mmdf files
112 ;; delimiting used on a given host (delim1 and delim2 from the config
113 ;; files).
114
115 (defvar mmdf-delim1 "^\001\001\001\001\n"
116 "Regexp marking the start of an mmdf message")
117 (defvar mmdf-delim2 "^\001\001\001\001\n"
118 "Regexp marking the end of an mmdf message")
119
120 (defvar rmail-message-filter nil
121 "If non nil, a filter function for new messages in RMAIL.
122 Called with region narrowed to the message, including headers.")
123
124 (defvar rmail-reply-prefix "Re: "
125 "String to prepend to Subject line when replying to a message.")
126
127 (defvar rmail-display-summary nil
128 "If non nil, the summary buffer is always displayed.")
129
130 (defvar rmail-mode-map nil)
131
132 (defvar rmail-inbox-list nil)
133 (defvar rmail-keywords nil)
134
135 ;; Message counters and markers. Deleted flags.
136
137 (defvar rmail-current-message nil)
138 (defvar rmail-total-messages nil)
139 (defvar rmail-message-vector nil)
140 (defvar rmail-deleted-vector nil)
141
142 (defvar rmail-overlay-list nil)
143
144 ;; These are used by autoloaded rmail-summary.
145
146 (defvar rmail-summary-buffer nil)
147 (defvar rmail-summary-vector nil)
148
149 ;; `Sticky' default variables.
150
151 ;; Last individual label specified to a or k.
152 (defvar rmail-last-label nil)
153 ;; Last set of values specified to C-M-n, C-M-p, C-M-s or C-M-l.
154 (defvar rmail-last-multi-labels nil)
155 (defvar rmail-last-regexp nil)
156 (defvar rmail-default-file nil
157 "*Default file name for \\[rmail-output].")
158 (defvar rmail-default-rmail-file (expand-file-name "~/XMAIL")
159 "*Default file name for \\[rmail-output-to-rmail-file].")
160
161 ;;; Regexp matching the delimiter of messages in UNIX mail format
162 ;;; (UNIX From lines), minus the initial ^. Note that if you change
163 ;;; this expression, you must change the code in rmail-nuke-pinhead-header
164 ;;; that knows the exact ordering of the \\( \\) subexpressions.
165 (defvar rmail-unix-mail-delimiter
166 (let ((time-zone-regexp
167 (concat "\\([A-Z]?[A-Z][A-Z][A-Z]\\( DST\\)?"
168 "\\|[-+]?[0-9][0-9][0-9][0-9]"
169 "\\|"
170 "\\) *")))
171 (concat
172 "From "
173
174 ;; Username, perhaps with a quoted section that can contain spaces.
175 "\\("
176 "[^ \n]*"
177 "\\(\\|\".*\"[^ \n]*\\)"
178 "\\) ?"
179
180 ;; The time the message was sent.
181 "\\([^ \n]*\\) *" ; day of the week
182 "\\([^ ]*\\) *" ; month
183 "\\([0-9]*\\) *" ; day of month
184 "\\([0-9:]*\\) *" ; time of day
185
186 ;; Perhaps a time zone, specified by an abbreviation, or by a
187 ;; numeric offset.
188 time-zone-regexp
189
190 ;; The year.
191 " [0-9][0-9]\\([0-9]*\\) *"
192
193 ;; On some systems the time zone can appear after the year, too.
194 time-zone-regexp
195
196 ;; Old uucp cruft.
197 "\\(remote from .*\\)?"
198
199 "\n"))
200 nil)
201
202 ;; Perform BODY in the summary buffer
203 ;; in such a way that its cursor is properly updated in its own window.
204 (defmacro rmail-select-summary (&rest body)
205 (` (let ((total rmail-total-messages))
206 (if (rmail-summary-displayed)
207 (let ((window (selected-window)))
208 (save-excursion
209 (unwind-protect
210 (progn
211 (pop-to-buffer rmail-summary-buffer)
212 ;; rmail-total-messages is a buffer-local var
213 ;; in the rmail buffer.
214 ;; This way we make it available for the body
215 ;; even tho the rmail buffer is not current.
216 (let ((rmail-total-messages total))
217 (,@ body)))
218 (select-window window))))
219 (save-excursion
220 (set-buffer rmail-summary-buffer)
221 (let ((rmail-total-messages total))
222 (,@ body))))
223 (rmail-maybe-display-summary))))
224 \f
225 ;;;; *** Rmail Mode ***
226
227 ;;;###autoload
228 (defun rmail (&optional file-name-arg)
229 "Read and edit incoming mail.
230 Moves messages into file named by `rmail-file-name' (a babyl format file)
231 and edits that file in RMAIL Mode.
232 Type \\[describe-mode] once editing that file, for a list of RMAIL commands.
233
234 May be called with file name as argument; then performs rmail editing on
235 that file, but does not copy any new mail into the file.
236 Interactively, if you supply a prefix argument, then you
237 have a chance to specify a file name with the minibuffer.
238
239 If `rmail-display-summary' is non-nil, make a summary for this RMAIL file."
240 (interactive (if current-prefix-arg
241 (list (read-file-name "Run rmail on RMAIL file: "
242 nil nil t))))
243 (or rmail-default-file
244 (setq rmail-default-file (expand-file-name "~/xmail")))
245 (let* ((file-name (expand-file-name (or file-name-arg rmail-file-name)))
246 (existed (get-file-buffer file-name)))
247 ;; Like find-file, but in the case where a buffer existed
248 ;; and the file was reverted, recompute the message-data.
249 (if (and existed (not (verify-visited-file-modtime existed)))
250 (progn
251 ;; Don't be confused by apparent local-variables spec
252 ;; in the last message in the RMAIL file.
253 (let ((enable-local-variables nil))
254 (find-file file-name))
255 (if (and (verify-visited-file-modtime existed)
256 (eq major-mode 'rmail-mode))
257 (progn (rmail-forget-messages)
258 (rmail-set-message-counters))))
259 (let ((enable-local-variables nil))
260 (find-file file-name)))
261 (if (eq major-mode 'rmail-edit-mode)
262 (error "Exit Rmail Edit mode before getting new mail."))
263 (if (and existed (> (buffer-size) 0))
264 ;; Buffer not new and not empty; ensure in proper mode, but that's all.
265 (or (eq major-mode 'rmail-mode)
266 (rmail-mode-2))
267 (rmail-mode-2)
268 ;; Convert all or part to Babyl file if possible.
269 (rmail-convert-file)
270 (goto-char (point-max))
271 (if (null rmail-inbox-list)
272 (progn
273 (rmail-set-message-counters)
274 (rmail-show-message))))
275 (let ((existing-unseen (rmail-first-unseen-message)))
276 (or file-name-arg
277 (rmail-get-new-mail))
278 ;; Show the first unseen message, which might be from a previous session
279 ;; or might have been just read in by rmail-get-new-mail. Must
280 ;; determine already unseen messages first, as rmail-get-new-mail
281 ;; positions on the first new message, thus marking it as seen.
282 (rmail-show-message existing-unseen))
283 (if rmail-display-summary (rmail-summary))
284 (rmail-construct-io-menu)))
285
286 ;; Given the value of MAILPATH, return a list of inbox file names.
287 ;; This is turned off because it is not clear that the user wants
288 ;; all these inboxes to feed into the primary rmail file.
289 ; (defun rmail-convert-mailpath (string)
290 ; (let (idx list)
291 ; (while (setq idx (string-match "[%:]" string))
292 ; (let ((this (substring string 0 idx)))
293 ; (setq string (substring string (1+ idx)))
294 ; (setq list (cons (if (string-match "%" this)
295 ; (substring this 0 (string-match "%" this))
296 ; this)
297 ; list))))
298 ; list))
299
300 ; I have checked that adding "-*- rmail -*-" to the BABYL OPTIONS line
301 ; will not cause emacs 18.55 problems.
302
303 (defun rmail-convert-file ()
304 (let (convert)
305 (widen)
306 (goto-char (point-min))
307 ;; If file doesn't start like a Babyl file,
308 ;; convert it to one, by adding a header and converting each message.
309 (cond ((looking-at "BABYL OPTIONS:"))
310 ((looking-at "Version: 5\n")
311 ;; Losing babyl file made by old version of Rmail.
312 ;; Just fix the babyl file header; don't make a new one,
313 ;; so we don't lose the Labels: file attribute, etc.
314 (let ((buffer-read-only nil))
315 (insert "BABYL OPTIONS: -*- rmail -*-\n")))
316 ((equal (point-min) (point-max))
317 ;; Empty RMAIL file. Just insert the header.
318 (rmail-insert-rmail-file-header))
319 (t
320 ;; Non-empty file in non-RMAIL format. Add header and convert.
321 (setq convert t)
322 (rmail-insert-rmail-file-header)))
323 ;; If file was not a Babyl file or if there are
324 ;; Unix format messages added at the end,
325 ;; convert file as necessary.
326 (if (or convert
327 (save-excursion
328 (goto-char (point-max))
329 (search-backward "\^_")
330 (forward-char 1)
331 (looking-at "\n*From ")))
332 (let ((buffer-read-only nil))
333 (message "Converting to Babyl format...")
334 ;; If file needs conversion, convert it all,
335 ;; except for the BABYL header.
336 ;; (rmail-convert-to-babyl-format would delete the header.)
337 (goto-char (point-min))
338 (search-forward "\n\^_" nil t)
339 (narrow-to-region (point) (point-max))
340 (rmail-convert-to-babyl-format)
341 (message "Converting to Babyl format...done")))))
342
343 ;;; I have checked that adding "-*- rmail -*-" to the BABYL OPTIONS line
344 ;;; will not cause emacs 18.55 problems.
345
346 (defun rmail-insert-rmail-file-header ()
347 (let ((buffer-read-only nil))
348 (insert "BABYL OPTIONS: -*- rmail -*-
349 Version: 5
350 Labels:
351 Note: This is the header of an rmail file.
352 Note: If you are seeing it in rmail,
353 Note: it means the file has no messages in it.\n\^_")))
354
355 (if rmail-mode-map
356 nil
357 (setq rmail-mode-map (make-keymap))
358 (suppress-keymap rmail-mode-map)
359 (define-key rmail-mode-map "a" 'rmail-add-label)
360 (define-key rmail-mode-map "b" 'rmail-bury)
361 (define-key rmail-mode-map "c" 'rmail-continue)
362 (define-key rmail-mode-map "d" 'rmail-delete-forward)
363 (define-key rmail-mode-map "\C-d" 'rmail-delete-backward)
364 (define-key rmail-mode-map "e" 'rmail-edit-current-message)
365 (define-key rmail-mode-map "f" 'rmail-forward)
366 (define-key rmail-mode-map "g" 'rmail-get-new-mail)
367 (define-key rmail-mode-map "h" 'rmail-summary)
368 (define-key rmail-mode-map "i" 'rmail-input)
369 (define-key rmail-mode-map "j" 'rmail-show-message)
370 (define-key rmail-mode-map "k" 'rmail-kill-label)
371 (define-key rmail-mode-map "l" 'rmail-summary-by-labels)
372 (define-key rmail-mode-map "\e\C-h" 'rmail-summary)
373 (define-key rmail-mode-map "\e\C-l" 'rmail-summary-by-labels)
374 (define-key rmail-mode-map "\e\C-r" 'rmail-summary-by-recipients)
375 (define-key rmail-mode-map "\e\C-s" 'rmail-summary-by-regexp)
376 (define-key rmail-mode-map "\e\C-t" 'rmail-summary-by-topic)
377 (define-key rmail-mode-map "m" 'rmail-mail)
378 (define-key rmail-mode-map "\em" 'rmail-retry-failure)
379 (define-key rmail-mode-map "n" 'rmail-next-undeleted-message)
380 (define-key rmail-mode-map "\en" 'rmail-next-message)
381 (define-key rmail-mode-map "\e\C-n" 'rmail-next-labeled-message)
382 (define-key rmail-mode-map "o" 'rmail-output-to-rmail-file)
383 (define-key rmail-mode-map "\C-o" 'rmail-output)
384 (define-key rmail-mode-map "p" 'rmail-previous-undeleted-message)
385 (define-key rmail-mode-map "\ep" 'rmail-previous-message)
386 (define-key rmail-mode-map "\e\C-p" 'rmail-previous-labeled-message)
387 (define-key rmail-mode-map "q" 'rmail-quit)
388 (define-key rmail-mode-map "r" 'rmail-reply)
389 ;; I find I can't live without the default M-r command -- rms.
390 ;; (define-key rmail-mode-map "\er" 'rmail-search-backwards)
391 (define-key rmail-mode-map "s" 'rmail-expunge-and-save)
392 (define-key rmail-mode-map "\es" 'rmail-search)
393 (define-key rmail-mode-map "t" 'rmail-toggle-header)
394 (define-key rmail-mode-map "u" 'rmail-undelete-previous-message)
395 (define-key rmail-mode-map "w" 'rmail-edit-current-message)
396 (define-key rmail-mode-map "x" 'rmail-expunge)
397 (define-key rmail-mode-map "." 'rmail-beginning-of-message)
398 (define-key rmail-mode-map "<" 'rmail-first-message)
399 (define-key rmail-mode-map ">" 'rmail-last-message)
400 (define-key rmail-mode-map " " 'scroll-up)
401 (define-key rmail-mode-map "\177" 'scroll-down)
402 (define-key rmail-mode-map "?" 'describe-mode)
403 (define-key rmail-mode-map "\C-c\C-s\C-d" 'rmail-sort-by-date)
404 (define-key rmail-mode-map "\C-c\C-s\C-s" 'rmail-sort-by-subject)
405 (define-key rmail-mode-map "\C-c\C-s\C-a" 'rmail-sort-by-author)
406 (define-key rmail-mode-map "\C-c\C-s\C-r" 'rmail-sort-by-recipient)
407 (define-key rmail-mode-map "\C-c\C-s\C-c" 'rmail-sort-by-correspondent)
408 (define-key rmail-mode-map "\C-c\C-s\C-l" 'rmail-sort-by-lines)
409 (define-key rmail-mode-map "\C-c\C-s\C-k" 'rmail-sort-by-keywords)
410 )
411 \f
412 (define-key rmail-mode-map [menu-bar] (make-sparse-keymap))
413
414 (define-key rmail-mode-map [menu-bar classify]
415 (cons "Classify" (make-sparse-keymap "Classify")))
416
417 (define-key rmail-mode-map [menu-bar classify input-menu]
418 nil)
419
420 (define-key rmail-mode-map [menu-bar classify output-menu]
421 nil)
422
423 (define-key rmail-mode-map [menu-bar classify output-inbox]
424 '("Output (inbox)..." . rmail-output))
425
426 (define-key rmail-mode-map [menu-bar classify output]
427 '("Output (Rmail)..." . rmail-output-to-rmail-file))
428
429 (define-key rmail-mode-map [menu-bar classify kill-label]
430 '("Kill Label..." . rmail-kill-label))
431
432 (define-key rmail-mode-map [menu-bar classify add-label]
433 '("Add Label..." . rmail-add-label))
434
435 (define-key rmail-mode-map [menu-bar summary]
436 (cons "Summary" (make-sparse-keymap "Summary")))
437
438 (define-key rmail-mode-map [menu-bar summary labels]
439 '("By Labels..." . rmail-summary-by-labels))
440
441 (define-key rmail-mode-map [menu-bar summary recipients]
442 '("By Recipients..." . rmail-summary-by-recipients))
443
444 (define-key rmail-mode-map [menu-bar summary topic]
445 '("By Topic..." . rmail-summary-by-topic))
446
447 (define-key rmail-mode-map [menu-bar summary regexp]
448 '("By Regexp..." . rmail-summary-by-regexp))
449
450 (define-key rmail-mode-map [menu-bar summary all]
451 '("All" . rmail-summary))
452
453 (define-key rmail-mode-map [menu-bar mail]
454 (cons "Mail" (make-sparse-keymap "Mail")))
455
456 (define-key rmail-mode-map [menu-bar mail rmail-get-new-mail]
457 '("Get New Mail" . rmail-get-new-mail))
458
459 (define-key rmail-mode-map [menu-bar mail lambda]
460 '("----"))
461
462 (define-key rmail-mode-map [menu-bar mail continue]
463 '("Continue" . rmail-continue))
464
465 (define-key rmail-mode-map [menu-bar mail resend]
466 '("Re-send..." . rmail-resend))
467
468 (define-key rmail-mode-map [menu-bar mail forward]
469 '("Forward" . rmail-forward))
470
471 (define-key rmail-mode-map [menu-bar mail retry]
472 '("Retry" . rmail-retry-failure))
473
474 (define-key rmail-mode-map [menu-bar mail reply]
475 '("Reply" . rmail-reply))
476
477 (define-key rmail-mode-map [menu-bar mail mail]
478 '("Mail" . rmail-mail))
479
480 (define-key rmail-mode-map [menu-bar delete]
481 (cons "Delete" (make-sparse-keymap "Delete")))
482
483 (define-key rmail-mode-map [menu-bar delete expunge/save]
484 '("Expunge/Save" . rmail-expunge-and-save))
485
486 (define-key rmail-mode-map [menu-bar delete expunge]
487 '("Expunge" . rmail-expunge))
488
489 (define-key rmail-mode-map [menu-bar delete undelete]
490 '("Undelete" . rmail-undelete-previous-message))
491
492 (define-key rmail-mode-map [menu-bar delete delete]
493 '("Delete" . rmail-delete-forward))
494
495 (define-key rmail-mode-map [menu-bar move]
496 (cons "Move" (make-sparse-keymap "Move")))
497
498 (define-key rmail-mode-map [menu-bar move search-back]
499 '("Search Back..." . rmail-search-backward))
500
501 (define-key rmail-mode-map [menu-bar move search]
502 '("Search..." . rmail-search))
503
504 (define-key rmail-mode-map [menu-bar move previous]
505 '("Previous Nondeleted" . rmail-previous-undeleted-message))
506
507 (define-key rmail-mode-map [menu-bar move next]
508 '("Next Nondeleted" . rmail-next-undeleted-message))
509
510 (define-key rmail-mode-map [menu-bar move last]
511 '("Last" . rmail-last-message))
512
513 (define-key rmail-mode-map [menu-bar move first]
514 '("First" . rmail-first-message))
515
516 (define-key rmail-mode-map [menu-bar move previous]
517 '("Previous" . rmail-previous-message))
518
519 (define-key rmail-mode-map [menu-bar move next]
520 '("Next" . rmail-next-message))
521 \f
522 ;; Rmail mode is suitable only for specially formatted data.
523 (put 'rmail-mode 'mode-class 'special)
524
525 (defun rmail-mode-kill-summary ()
526 (if rmail-summary-buffer (kill-buffer rmail-summary-buffer)))
527
528 ;;;###autoload
529 (defun rmail-mode ()
530 "Rmail Mode is used by \\<rmail-mode-map>\\[rmail] for editing Rmail files.
531 All normal editing commands are turned off.
532 Instead, these commands are available:
533
534 \\[rmail-beginning-of-message] Move point to front of this message (same as \\[beginning-of-buffer]).
535 \\[scroll-up] Scroll to next screen of this message.
536 \\[scroll-down] Scroll to previous screen of this message.
537 \\[rmail-next-undeleted-message] Move to Next non-deleted message.
538 \\[rmail-previous-undeleted-message] Move to Previous non-deleted message.
539 \\[rmail-next-message] Move to Next message whether deleted or not.
540 \\[rmail-previous-message] Move to Previous message whether deleted or not.
541 \\[rmail-first-message] Move to the first message in Rmail file.
542 \\[rmail-last-message] Move to the last message in Rmail file.
543 \\[rmail-show-message] Jump to message specified by numeric position in file.
544 \\[rmail-search] Search for string and show message it is found in.
545 \\[rmail-delete-forward] Delete this message, move to next nondeleted.
546 \\[rmail-delete-backward] Delete this message, move to previous nondeleted.
547 \\[rmail-undelete-previous-message] Undelete message. Tries current message, then earlier messages
548 till a deleted message is found.
549 \\[rmail-edit-current-message] Edit the current message. \\[rmail-cease-edit] to return to Rmail.
550 \\[rmail-expunge] Expunge deleted messages.
551 \\[rmail-expunge-and-save] Expunge and save the file.
552 \\[rmail-quit] Quit Rmail: expunge, save, then switch to another buffer.
553 \\[save-buffer] Save without expunging.
554 \\[rmail-get-new-mail] Move new mail from system spool directory into this file.
555 \\[rmail-mail] Mail a message (same as \\[mail-other-window]).
556 \\[rmail-continue] Continue composing outgoing message started before.
557 \\[rmail-reply] Reply to this message. Like \\[rmail-mail] but initializes some fields.
558 \\[rmail-retry-failure] Send this message again. Used on a mailer failure message.
559 \\[rmail-forward] Forward this message to another user.
560 \\[rmail-output-to-rmail-file] Output this message to an Rmail file (append it).
561 \\[rmail-output] Output this message to a Unix-format mail file (append it).
562 \\[rmail-input] Input Rmail file. Run Rmail on that file.
563 \\[rmail-add-label] Add label to message. It will be displayed in the mode line.
564 \\[rmail-kill-label] Kill label. Remove a label from current message.
565 \\[rmail-next-labeled-message] Move to Next message with specified label
566 (label defaults to last one specified).
567 Standard labels: filed, unseen, answered, forwarded, deleted.
568 Any other label is present only if you add it with \\[rmail-add-label].
569 \\[rmail-previous-labeled-message] Move to Previous message with specified label
570 \\[rmail-summary] Show headers buffer, with a one line summary of each message.
571 \\[rmail-summary-by-labels] Summarize only messages with particular label(s).
572 \\[rmail-summary-by-recipients] Summarize only messages with particular recipient(s).
573 \\[rmail-summary-by-regexp] Summarize only messages with particular regexp(s).
574 \\[rmail-summary-by-topic] Summarize only messages with subject line regexp(s).
575 \\[rmail-toggle-header] Toggle display of complete header."
576 (interactive)
577 (rmail-mode-2)
578 (rmail-set-message-counters)
579 (rmail-show-message rmail-total-messages))
580
581 (defun rmail-mode-2 ()
582 (kill-all-local-variables)
583 (rmail-mode-1)
584 (rmail-variables)
585 (run-hooks 'rmail-mode-hook))
586
587 (defun rmail-mode-1 ()
588 (setq major-mode 'rmail-mode)
589 (setq mode-name "RMAIL")
590 (setq buffer-read-only t)
591 ;; No need to auto save RMAIL files in normal circumstances
592 ;; because they contain no info except attribute changes
593 ;; and deletion of messages.
594 ;; The one exception is when messages are copied into an Rmail mode buffer.
595 ;; rmail-output-to-rmail-file enables auto save when you do that.
596 (setq buffer-auto-save-file-name nil)
597 (if (boundp 'mode-line-modified)
598 (setq mode-line-modified "--- ")
599 (setq mode-line-format
600 (cons "--- " (cdr (default-value 'mode-line-format)))))
601 (use-local-map rmail-mode-map)
602 (set-syntax-table text-mode-syntax-table)
603 (setq local-abbrev-table text-mode-abbrev-table))
604
605 (defun rmail-variables ()
606 (make-local-variable 'revert-buffer-function)
607 (setq revert-buffer-function 'rmail-revert)
608 (make-local-variable 'rmail-last-label)
609 (make-local-variable 'rmail-last-regexp)
610 (make-local-variable 'rmail-deleted-vector)
611 (make-local-variable 'rmail-summary-buffer)
612 (make-local-variable 'rmail-summary-vector)
613 (make-local-variable 'rmail-current-message)
614 (make-local-variable 'rmail-total-messages)
615 (make-local-variable 'require-final-newline)
616 (setq require-final-newline nil)
617 (make-local-variable 'rmail-overlay-list)
618 (setq rmail-overlay-list nil)
619 (make-local-variable 'version-control)
620 (setq version-control 'never)
621 (make-local-variable 'kill-buffer-hook)
622 (add-hook 'kill-buffer-hook 'rmail-mode-kill-summary)
623 (make-local-variable 'file-precious-flag)
624 (setq file-precious-flag t)
625 (make-local-variable 'rmail-message-vector)
626 (make-local-variable 'rmail-inbox-list)
627 (setq rmail-inbox-list (rmail-parse-file-inboxes))
628 ;; Provide default set of inboxes for primary mail file ~/RMAIL.
629 (and (null rmail-inbox-list)
630 (or (equal buffer-file-name (expand-file-name rmail-file-name))
631 (equal buffer-file-truename
632 (abbreviate-file-name (file-truename rmail-file-name))))
633 (setq rmail-inbox-list
634 (or rmail-primary-inbox-list
635 (list (or (getenv "MAIL")
636 (concat rmail-spool-directory
637 (user-login-name)))))))
638 (make-local-variable 'rmail-keywords)
639 ;; this gets generated as needed
640 (setq rmail-keywords nil))
641
642 ;; Handle M-x revert-buffer done in an rmail-mode buffer.
643 (defun rmail-revert (arg noconfirm)
644 (let (revert-buffer-function)
645 ;; Call our caller again, but this time it does the default thing.
646 (if (revert-buffer arg noconfirm)
647 ;; If the user said "yes", and we changed something,
648 ;; reparse the messages.
649 (progn
650 (rmail-convert-file)
651 (goto-char (point-max))
652 (rmail-set-message-counters)
653 (rmail-show-message)))))
654
655 ;; Return a list of files from this buffer's Mail: option.
656 ;; Does not assume that messages have been parsed.
657 ;; Just returns nil if buffer does not look like Babyl format.
658 (defun rmail-parse-file-inboxes ()
659 (save-excursion
660 (save-restriction
661 (widen)
662 (goto-char 1)
663 (cond ((looking-at "BABYL OPTIONS:")
664 (search-forward "\n\^_" nil 'move)
665 (narrow-to-region 1 (point))
666 (goto-char 1)
667 (if (search-forward "\nMail:" nil t)
668 (progn
669 (narrow-to-region (point) (progn (end-of-line) (point)))
670 (goto-char (point-min))
671 (mail-parse-comma-list))))))))
672
673 (defun rmail-expunge-and-save ()
674 "Expunge and save RMAIL file."
675 (interactive)
676 (rmail-expunge)
677 (save-buffer)
678 (if (rmail-summary-exists)
679 (rmail-select-summary (set-buffer-modified-p nil))))
680
681 (defun rmail-quit ()
682 "Quit out of RMAIL."
683 (interactive)
684 (rmail-expunge-and-save)
685 ;; Don't switch to the summary buffer even if it was recently visible.
686 (if rmail-summary-buffer
687 (progn
688 (replace-buffer-in-windows rmail-summary-buffer)
689 (bury-buffer rmail-summary-buffer)))
690 (let ((obuf (current-buffer)))
691 (replace-buffer-in-windows obuf)
692 (bury-buffer obuf)))
693
694 ;;;###autoload
695 (defun rmail-input (filename)
696 "Run Rmail on file FILENAME."
697 (interactive "FRun rmail on RMAIL file: ")
698 (rmail filename))
699
700 (defun rmail-find-all-files (start)
701 (if (file-accessible-directory-p start)
702 (let ((files (directory-files start nil
703 rmail-secondary-file-regexp))
704 (ret nil))
705 (while files
706 (setq file (car files))
707 (setq files (cdr files))
708 (setq ret (cons
709 (rmail-find-all-files (concat start "/" file))
710 ret)))
711 (cons (file-name-nondirectory start) ret))
712 (file-name-nondirectory start)))
713
714 (defun rmail-list-to-menu (menu-name l action &optional full-name)
715 (let ((menu (make-sparse-keymap menu-name)))
716 (mapcar
717 (function (lambda (item)
718 (if (consp item)
719 (progn
720 (setq command
721 (rmail-list-to-menu (car item) (cdr item)
722 action
723 (if full-name
724 (concat full-name "/"
725 (car item))
726 (car item))))
727 (setq name (car item)))
728 (progn
729 (setq name item)
730 (setq command
731 (list 'lambda () '(interactive)
732 (list action
733 (expand-file-name
734 (if full-name
735 (concat full-name "/" item)
736 item)
737 rmail-secondary-file-directory))))))
738 (define-key menu (vector (intern name))
739 (cons name command))))
740 l)
741 menu))
742
743 (defun rmail-construct-io-menu ()
744 (let ((files (rmail-find-all-files rmail-secondary-file-directory)))
745 (if (listp files)
746 (progn
747 (define-key rmail-mode-map [menu-bar classify input-menu]
748 (cons "Input Rmail File"
749 (rmail-list-to-menu "Input Rmail File"
750 (cdr files)
751 'rmail-input)))
752 (define-key rmail-mode-map [menu-bar classify output-menu]
753 (cons "Output Rmail File"
754 (rmail-list-to-menu "Output Rmail File"
755 (cdr files)
756 'rmail-output-to-rmail-file)))))))
757
758 \f
759 ;;;; *** Rmail input ***
760
761 ;; RLK feature not added in this version:
762 ;; argument specifies inbox file or files in various ways.
763
764 (defun rmail-get-new-mail (&optional file-name)
765 "Move any new mail from this RMAIL file's inbox files.
766 The inbox files can be specified with the file's Mail: option. The
767 variable `rmail-primary-inbox-list' specifies the inboxes for your
768 primary RMAIL file if it has no Mail: option. By default, this is
769 your /usr/spool/mail/$USER.
770
771 You can also specify the file to get new mail from. In this case, the
772 file of new mail is not changed or deleted. Noninteractively, you can
773 pass the inbox file name as an argument. Interactively, a prefix
774 argument causes us to read a file name and use that file as the inbox.
775
776 This function runs `rmail-get-new-mail-hook' before saving the updated file."
777 (interactive
778 (list (if current-prefix-arg
779 (read-file-name "Get new mail from file: "))))
780 (or (verify-visited-file-modtime (current-buffer))
781 (progn
782 (find-file (buffer-file-name))
783 (setq buffer-read-only t)
784 (if (verify-visited-file-modtime (current-buffer))
785 (rmail-forget-messages))))
786 (rmail-maybe-set-message-counters)
787 (widen)
788 ;; Get rid of all undo records for this buffer.
789 (or (eq buffer-undo-list t)
790 (setq buffer-undo-list nil))
791 (unwind-protect
792 (let ((opoint (point))
793 (new-messages 0)
794 (delete-files ())
795 ;; If buffer has not changed yet, and has not been saved yet,
796 ;; don't replace the old backup file now.
797 (make-backup-files (and make-backup-files (buffer-modified-p)))
798 (buffer-read-only nil)
799 ;; Don't make undo records for what we do in getting mail.
800 (buffer-undo-list t))
801 (goto-char (point-max))
802 (skip-chars-backward " \t\n") ; just in case of brain damage
803 (delete-region (point) (point-max)) ; caused by require-final-newline
804 (save-excursion
805 (save-restriction
806 (narrow-to-region (point) (point))
807 ;; Read in the contents of the inbox files,
808 ;; renaming them as necessary,
809 ;; and adding to the list of files to delete eventually.
810 (if file-name
811 (rmail-insert-inbox-text (list file-name) nil)
812 (setq delete-files (rmail-insert-inbox-text rmail-inbox-list t)))
813 ;; Scan the new text and convert each message to babyl format.
814 (goto-char (point-min))
815 (save-excursion
816 (setq new-messages (rmail-convert-to-babyl-format)))
817 (or (zerop new-messages)
818 (let (success)
819 (widen)
820 (search-backward "\n\^_" nil t)
821 (narrow-to-region (point) (point-max))
822 (goto-char (1+ (point-min)))
823 (rmail-count-new-messages)
824 (run-hooks 'rmail-get-new-mail-hook)
825 (save-buffer)))
826 ;; Delete the old files, now that babyl file is saved.
827 (while delete-files
828 (condition-case ()
829 ;; First, try deleting.
830 (condition-case ()
831 (delete-file (car delete-files))
832 (file-error
833 ;; If we can't delete it, truncate it.
834 (write-region (point) (point) (car delete-files))))
835 (file-error nil))
836 (setq delete-files (cdr delete-files)))))
837 (if (= new-messages 0)
838 (progn (goto-char opoint)
839 (if (or file-name rmail-inbox-list)
840 (message "(No new mail has arrived)")))
841 (if (rmail-summary-exists)
842 (rmail-select-summary
843 (rmail-update-summary)))
844 (message "%d new message%s read"
845 new-messages (if (= 1 new-messages) "" "s"))
846 (and (boundp 'display-time-string)
847 (stringp display-time-string)
848 (string-match " Mail" display-time-string)
849 (setq display-time-string
850 (concat
851 (substring display-time-string 0 (match-beginning 0))
852 (substring display-time-string (match-end 0))))
853 (force-mode-line-update 'all))))
854 ;; Don't leave the buffer screwed up if we get a disk-full error.
855 (rmail-show-message)))
856
857 (defun rmail-insert-inbox-text (files renamep)
858 (let (file tofile delete-files movemail popmail)
859 (while files
860 (setq file (file-truename
861 (expand-file-name (substitute-in-file-name (car files))))
862 ;;>> un*x specific <<
863 ;; The "+" used to be "~", which is an extremely poor choice;
864 ;; it might accidentally be deleted when space is low
865 ;; (as happened to me!).
866 tofile (concat file "+"))
867 ;; If getting from mail spool directory,
868 ;; use movemail to move rather than just renaming,
869 ;; so as to interlock with the mailer.
870 (setq movemail (string= (file-name-directory file)
871 (file-truename rmail-spool-directory))
872 popmail (string-match "^po:" (file-name-nondirectory file)))
873 (if popmail (setq file (file-name-nondirectory file)
874 renamep t))
875 (if movemail
876 (progn
877 (setq tofile (expand-file-name
878 ;; Generate name to move to from inbox name,
879 ;; in case of multiple inboxes that need moving.
880 (concat ".newmail-" (file-name-nondirectory file))
881 ;; Use the directory of this rmail file
882 ;; because it's a nuisance to use the homedir
883 ;; if that is on a full disk and this rmail
884 ;; file isn't.
885 (file-name-directory
886 (expand-file-name buffer-file-name))))
887 ;; On some systems, /usr/spool/mail/foo is a directory
888 ;; and the actual inbox is /usr/spool/mail/foo/foo.
889 (if (file-directory-p file)
890 (setq file (expand-file-name (user-login-name)
891 file)))))
892 (if popmail
893 (message "Getting mail from post office ...")
894 (if (or (and (file-exists-p tofile)
895 (/= 0 (nth 7 (file-attributes tofile))))
896 (and (file-exists-p file)
897 (/= 0 (nth 7 (file-attributes file)))))
898 (message "Getting mail from %s..." file)))
899 ;; Set TOFILE if have not already done so, and
900 ;; rename or copy the file FILE to TOFILE if and as appropriate.
901 (cond ((not renamep)
902 (setq tofile file))
903 ((or (file-exists-p tofile) (and (not popmail)
904 (not (file-exists-p file))))
905 nil)
906 ((and (not movemail) (not popmail))
907 ;; Try copying. If that fails (perhaps no space),
908 ;; rename instead.
909 (condition-case nil
910 (copy-file file tofile nil)
911 (error
912 ;; Third arg is t so we can replace existing file TOFILE.
913 (rename-file file tofile t)))
914 ;; Make the real inbox file empty.
915 ;; Leaving it deleted could cause lossage
916 ;; because mailers often won't create the file.
917 (condition-case ()
918 (write-region (point) (point) file)
919 (file-error nil)))
920 (t
921 (let ((errors nil))
922 (unwind-protect
923 (save-excursion
924 (setq errors (generate-new-buffer " *rmail loss*"))
925 (buffer-disable-undo errors)
926 (call-process
927 (or rmail-movemail-program
928 (expand-file-name "movemail" exec-directory))
929 nil errors nil file tofile)
930 (if (not (buffer-modified-p errors))
931 ;; No output => movemail won
932 nil
933 (set-buffer errors)
934 (subst-char-in-region (point-min) (point-max)
935 ?\n ?\ )
936 (goto-char (point-max))
937 (skip-chars-backward " \t")
938 (delete-region (point) (point-max))
939 (goto-char (point-min))
940 (if (looking-at "movemail: ")
941 (delete-region (point-min) (match-end 0)))
942 (beep t)
943 (message (concat "movemail: "
944 (buffer-substring (point-min)
945 (point-max))))
946 (sit-for 3)
947 nil))
948 (if errors (kill-buffer errors))))))
949 ;; At this point, TOFILE contains the name to read:
950 ;; Either the alternate name (if we renamed)
951 ;; or the actual inbox (if not renaming).
952 (if (file-exists-p tofile)
953 (let (size)
954 (goto-char (point-max))
955 (setq size (nth 1 (insert-file-contents tofile)))
956 (goto-char (point-max))
957 (or (= (preceding-char) ?\n)
958 (zerop size)
959 (insert ?\n))
960 (setq delete-files (cons tofile delete-files))))
961 (message "")
962 (setq files (cdr files)))
963 delete-files))
964
965 ;; the rmail-break-forwarded-messages feature is not implemented
966 (defun rmail-convert-to-babyl-format ()
967 (let ((count 0) start
968 (case-fold-search nil)
969 (invalid-input-resync
970 (function (lambda ()
971 (message "Invalid Babyl format in inbox!")
972 (sit-for 1)
973 ;; Try to get back in sync with a real message.
974 (if (re-search-forward
975 (concat mmdf-delim1 "\\|^From") nil t)
976 (beginning-of-line)
977 (goto-char (point-max)))))))
978 (goto-char (point-min))
979 (save-restriction
980 (while (not (eobp))
981 (cond ((looking-at "BABYL OPTIONS:");Babyl header
982 (if (search-forward "\n\^_" nil t)
983 ;; If we find the proper terminator, delete through there.
984 (delete-region (point-min) (point))
985 (funcall invalid-input-resync)
986 (delete-region (point-min) (point))))
987 ;; Babyl format message
988 ((looking-at "\^L")
989 (or (search-forward "\n\^_" nil t)
990 (funcall invalid-input-resync))
991 (setq count (1+ count))
992 ;; Make sure there is no extra white space after the ^_
993 ;; at the end of the message.
994 ;; Narrowing will make sure that whatever follows the junk
995 ;; will be treated properly.
996 (delete-region (point)
997 (save-excursion
998 (skip-chars-forward " \t\n")
999 (point)))
1000 (narrow-to-region (point) (point-max)))
1001 ;;*** MMDF format
1002 ((let ((case-fold-search t))
1003 (looking-at mmdf-delim1))
1004 (let ((case-fold-search t))
1005 (replace-match "\^L\n0, unseen,,\n*** EOOH ***\n")
1006 (setq start (point))
1007 (re-search-forward mmdf-delim2 nil t)
1008 (replace-match "\^_"))
1009 (save-excursion
1010 (save-restriction
1011 (narrow-to-region start (1- (point)))
1012 (goto-char (point-min))
1013 (while (search-forward "\n\^_" nil t); single char "\^_"
1014 (replace-match "\n^_")))); 2 chars: "^" and "_"
1015 (narrow-to-region (point) (point-max))
1016 (setq count (1+ count)))
1017 ;;*** Mail format
1018 ((looking-at "^From ")
1019 (setq start (point))
1020 (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
1021 (rmail-nuke-pinhead-header)
1022 ;; If this message has a Content-Length field,
1023 ;; skip to the end of the contents.
1024 (let* ((header-end (save-excursion
1025 (and (re-search-forward "\n\n" nil t)
1026 (1- (point)))))
1027 (case-fold-search t)
1028 (size
1029 ;; Get the numeric value from the Content-Length field.
1030 (save-excursion
1031 ;; Back up to end of prev line,
1032 ;; in case the Content-Length field comes first.
1033 (forward-char -1)
1034 (and (search-forward "\ncontent-length: "
1035 header-end t)
1036 (let ((beg (point))
1037 (eol (progn (end-of-line) (point))))
1038 (string-to-int (buffer-substring beg eol)))))))
1039 (and size
1040 (if (and (natnump size)
1041 (<= (+ header-end size) (point-max))
1042 ;; Make sure this would put us at a position
1043 ;; that we could continue from.
1044 (save-excursion
1045 (goto-char (+ header-end size))
1046 (skip-chars-forward "\n")
1047 (or (eobp)
1048 (and (looking-at "BABYL OPTIONS:")
1049 (search-forward "\n\^_" nil t))
1050 (and (looking-at "\^L")
1051 (search-forward "\n\^_" nil t))
1052 (let ((case-fold-search t))
1053 (looking-at mmdf-delim1))
1054 (looking-at "From "))))
1055 (goto-char (+ header-end size))
1056 (message "Ignoring invalid Content-Length field")
1057 (sit-for 1 0 t))))
1058
1059 (if (re-search-forward
1060 (concat "^[\^_]?\\("
1061 rmail-unix-mail-delimiter
1062 "\\|"
1063 mmdf-delim1 "\\|"
1064 "^BABYL OPTIONS:\\|"
1065 "\^L\n[01],\\)") nil t)
1066 (goto-char (match-beginning 1))
1067 (goto-char (point-max)))
1068 (setq count (1+ count))
1069 (save-excursion
1070 (save-restriction
1071 (narrow-to-region start (point))
1072 (goto-char (point-min))
1073 (while (search-forward "\n\^_" nil t); single char
1074 (replace-match "\n^_")))); 2 chars: "^" and "_"
1075 (insert ?\^_)
1076 (narrow-to-region (point) (point-max)))
1077 ;;
1078 ;; This kludge is because some versions of sendmail.el
1079 ;; insert an extra newline at the beginning that shouldn't
1080 ;; be there. sendmail.el has been fixed, but old versions
1081 ;; may still be in use. -- rms, 7 May 1993.
1082 ((eolp) (delete-char 1))
1083 (t (error "Cannot convert to babyl format")))))
1084 count))
1085
1086 ;; Delete the "From ..." line, creating various other headers with
1087 ;; information from it if they don't already exist. Now puts the
1088 ;; original line into a mail-from: header line for debugging and for
1089 ;; use by the rmail-output function.
1090 (defun rmail-nuke-pinhead-header ()
1091 (save-excursion
1092 (save-restriction
1093 (let ((start (point))
1094 (end (progn
1095 (condition-case ()
1096 (search-forward "\n\n")
1097 (error
1098 (goto-char (point-max))
1099 (insert "\n\n")))
1100 (point)))
1101 has-from has-date)
1102 (narrow-to-region start end)
1103 (let ((case-fold-search t))
1104 (goto-char start)
1105 (setq has-from (search-forward "\nFrom:" nil t))
1106 (goto-char start)
1107 (setq has-date (and (search-forward "\nDate:" nil t) (point)))
1108 (goto-char start))
1109 (let ((case-fold-search nil))
1110 (if (re-search-forward (concat "^" rmail-unix-mail-delimiter) nil t)
1111 (replace-match
1112 (concat
1113 "Mail-from: \\&"
1114 ;; Keep and reformat the date if we don't
1115 ;; have a Date: field.
1116 (if has-date
1117 ""
1118 (concat
1119 "Date: \\3, \\5 \\4 \\9 \\6 "
1120
1121 ;; The timezone could be matched by group 7 or group 10.
1122 ;; If neither of them matched, assume EST, since only
1123 ;; Easterners would be so sloppy.
1124 ;; It's a shame the substitution can't use "\\10".
1125 (cond
1126 ((/= (match-beginning 7) (match-end 7)) "\\7")
1127 ((/= (match-beginning 10) (match-end 10))
1128 (buffer-substring (match-beginning 10)
1129 (match-end 10)))
1130 (t "EST"))
1131 "\n"))
1132 ;; Keep and reformat the sender if we don't
1133 ;; have a From: field.
1134 (if has-from
1135 ""
1136 "From: \\1\n"))
1137 t)))))))
1138 \f
1139 ;;;; *** Rmail Message Formatting and Header Manipulation ***
1140
1141 (defun rmail-reformat-message (beg end)
1142 (goto-char beg)
1143 (forward-line 1)
1144 (if (/= (following-char) ?0)
1145 (error "Bad format in RMAIL file."))
1146 (let ((buffer-read-only nil)
1147 (delta (- (buffer-size) end)))
1148 (delete-char 1)
1149 (insert ?1)
1150 (forward-line 1)
1151 (let ((case-fold-search t))
1152 (while (looking-at "Summary-line:\\|Mail-From:")
1153 (forward-line 1)))
1154 (if (looking-at "\\*\\*\\* EOOH \\*\\*\\*\n")
1155 (delete-region (point)
1156 (progn (forward-line 1) (point))))
1157 (let ((str (buffer-substring (point)
1158 (save-excursion (search-forward "\n\n" end 'move)
1159 (point)))))
1160 (insert str "*** EOOH ***\n")
1161 (narrow-to-region (point) (- (buffer-size) delta)))
1162 (goto-char (point-min))
1163 (if rmail-message-filter (funcall rmail-message-filter))
1164 (if rmail-ignored-headers (rmail-clear-headers))))
1165
1166 (defun rmail-clear-headers (&optional ignored-headers)
1167 (or ignored-headers (setq ignored-headers rmail-ignored-headers))
1168 (if (search-forward "\n\n" nil t)
1169 (save-restriction
1170 (narrow-to-region (point-min) (point))
1171 (let ((buffer-read-only nil))
1172 (while (let ((case-fold-search t))
1173 (goto-char (point-min))
1174 (re-search-forward ignored-headers nil t))
1175 (beginning-of-line)
1176 (delete-region (point)
1177 (progn (re-search-forward "\n[^ \t]")
1178 (forward-char -1)
1179 (point))))))))
1180
1181 (defun rmail-toggle-header ()
1182 "Show original message header if pruned header currently shown, or vice versa."
1183 (interactive)
1184 (rmail-maybe-set-message-counters)
1185 (narrow-to-region (rmail-msgbeg rmail-current-message) (point-max))
1186 (let ((buffer-read-only nil))
1187 (goto-char (point-min))
1188 (forward-line 1)
1189 (if (= (following-char) ?1)
1190 (progn (delete-char 1)
1191 (insert ?0)
1192 (forward-line 1)
1193 (let ((case-fold-search t))
1194 (while (looking-at "Summary-Line:\\|Mail-From:")
1195 (forward-line 1)))
1196 (insert "*** EOOH ***\n")
1197 (forward-char -1)
1198 (search-forward "\n*** EOOH ***\n")
1199 (forward-line -1)
1200 (let ((temp (point)))
1201 (and (search-forward "\n\n" nil t)
1202 (delete-region temp (point))))
1203 (goto-char (point-min))
1204 (search-forward "\n*** EOOH ***\n")
1205 (narrow-to-region (point) (point-max)))
1206 (rmail-reformat-message (point-min) (point-max))))
1207 (rmail-highlight-headers))
1208 \f
1209 ;;;; *** Rmail Attributes and Keywords ***
1210
1211 ;; Make a string describing current message's attributes and keywords
1212 ;; and set it up as the name of a minor mode
1213 ;; so it will appear in the mode line.
1214 (defun rmail-display-labels ()
1215 (let ((blurb "") (beg (point-min-marker)) (end (point-max-marker)))
1216 (save-excursion
1217 (unwind-protect
1218 (progn
1219 (widen)
1220 (goto-char (rmail-msgbeg rmail-current-message))
1221 (forward-line 1)
1222 (if (looking-at "[01],")
1223 (progn
1224 (narrow-to-region (point) (progn (end-of-line) (point)))
1225 ;; Truly valid BABYL format requires a space before each
1226 ;; attribute or keyword name. Put them in if missing.
1227 (let (buffer-read-only)
1228 (goto-char (point-min))
1229 (while (search-forward "," nil t)
1230 (or (looking-at "[ ,]") (eobp)
1231 (insert " "))))
1232 (goto-char (point-max))
1233 (if (search-backward ",," nil 'move)
1234 (progn
1235 (if (> (point) (1+ (point-min)))
1236 (setq blurb (buffer-substring (+ 1 (point-min)) (point))))
1237 (if (> (- (point-max) (point)) 2)
1238 (setq blurb
1239 (concat blurb
1240 ";"
1241 (buffer-substring (+ (point) 3)
1242 (1- (point-max)))))))))))
1243 ;; Note: we don't use save-restriction because that does not work right
1244 ;; if changes are made outside the saved restriction
1245 ;; before that restriction is restored.
1246 (narrow-to-region beg end)
1247 (set-marker beg nil)
1248 (set-marker end nil)))
1249 (while (string-match " +," blurb)
1250 (setq blurb (concat (substring blurb 0 (match-beginning 0)) ","
1251 (substring blurb (match-end 0)))))
1252 (while (string-match ", +" blurb)
1253 (setq blurb (concat (substring blurb 0 (match-beginning 0)) ","
1254 (substring blurb (match-end 0)))))
1255 (setq mode-line-process
1256 (concat " " rmail-current-message "/" rmail-total-messages
1257 blurb))))
1258
1259 ;; Turn an attribute of a message on or off according to STATE.
1260 ;; ATTR is the name of the attribute, as a string.
1261 ;; MSGNUM is message number to change; nil means current message.
1262 (defun rmail-set-attribute (attr state &optional msgnum)
1263 (let ((omax (point-max-marker))
1264 (omin (point-min-marker))
1265 (buffer-read-only nil))
1266 (or msgnum (setq msgnum rmail-current-message))
1267 (if (> msgnum 0)
1268 (unwind-protect
1269 (save-excursion
1270 (widen)
1271 (goto-char (+ 3 (rmail-msgbeg msgnum)))
1272 (let ((curstate
1273 (not
1274 (null (search-backward (concat ", " attr ",")
1275 (prog1 (point) (end-of-line)) t)))))
1276 (or (eq curstate (not (not state)))
1277 (if curstate
1278 (delete-region (point) (1- (match-end 0)))
1279 (beginning-of-line)
1280 (forward-char 2)
1281 (insert " " attr ","))))
1282 (if (string= attr "deleted")
1283 (rmail-set-message-deleted-p msgnum state)))
1284 ;; Note: we don't use save-restriction because that does not work right
1285 ;; if changes are made outside the saved restriction
1286 ;; before that restriction is restored.
1287 (narrow-to-region omin omax)
1288 (set-marker omin nil)
1289 (set-marker omax nil)
1290 (if (= msgnum rmail-current-message)
1291 (rmail-display-labels))))))
1292
1293 ;; Return t if the attributes/keywords line of msg number MSG
1294 ;; contains a match for the regexp LABELS.
1295 (defun rmail-message-labels-p (msg labels)
1296 (save-excursion
1297 (save-restriction
1298 (widen)
1299 (goto-char (rmail-msgbeg msg))
1300 (forward-char 3)
1301 (re-search-backward labels (prog1 (point) (end-of-line)) t))))
1302 \f
1303 ;;;; *** Rmail Message Selection And Support ***
1304
1305 (defun rmail-msgend (n)
1306 (marker-position (aref rmail-message-vector (1+ n))))
1307
1308 (defun rmail-msgbeg (n)
1309 (marker-position (aref rmail-message-vector n)))
1310
1311 (defun rmail-widen-to-current-msgbeg (function)
1312 "Call FUNCTION with point at start of internal data of current message.
1313 Assumes that bounds were previously narrowed to display the message in Rmail.
1314 The bounds are widened enough to move point where desired, then narrowed
1315 again afterward.
1316
1317 FUNCTION may not change the visible text of the message, but it may
1318 change the invisible header text."
1319 (save-excursion
1320 (let ((obeg (- (point-max) (point-min))))
1321 (unwind-protect
1322 (progn
1323 (narrow-to-region (rmail-msgbeg rmail-current-message)
1324 (point-max))
1325 (goto-char (point-min))
1326 (funcall function))
1327 ;; Note: we don't use save-restriction because that does not work right
1328 ;; if changes are made outside the saved restriction
1329 ;; before that restriction is restored.
1330 ;; Here we assume that changes made by FUNCTION
1331 ;; occur before the visible region of the message.
1332 (narrow-to-region (- (point-max) obeg) (point-max))))))
1333
1334 (defun rmail-forget-messages ()
1335 (unwind-protect
1336 (if (vectorp rmail-message-vector)
1337 (let* ((i 0)
1338 (v rmail-message-vector)
1339 (n (length v)))
1340 (while (< i n)
1341 (move-marker (aref v i) nil)
1342 (setq i (1+ i)))))
1343 (setq rmail-message-vector nil)
1344 (setq rmail-deleted-vector nil)))
1345
1346 (defun rmail-maybe-set-message-counters ()
1347 (if (not (and rmail-deleted-vector
1348 rmail-message-vector
1349 rmail-current-message
1350 rmail-total-messages))
1351 (rmail-set-message-counters)))
1352
1353 (defun rmail-count-new-messages (&optional nomsg)
1354 (let* ((case-fold-search nil)
1355 (total-messages 0)
1356 (messages-head nil)
1357 (deleted-head nil))
1358 (or nomsg (message "Counting new messages..."))
1359 (goto-char (point-max))
1360 ;; Put at the end of messages-head
1361 ;; the entry for message N+1, which marks
1362 ;; the end of message N. (N = number of messages).
1363 (search-backward "\n\^_")
1364 (forward-char 1)
1365 (setq messages-head (list (point-marker)))
1366 (rmail-set-message-counters-counter (point-min))
1367 (setq rmail-current-message (1+ rmail-total-messages))
1368 (setq rmail-total-messages
1369 (+ rmail-total-messages total-messages))
1370 (setq rmail-message-vector
1371 (vconcat rmail-message-vector (cdr messages-head)))
1372 (aset rmail-message-vector
1373 rmail-current-message (car messages-head))
1374 (setq rmail-deleted-vector
1375 (concat rmail-deleted-vector deleted-head))
1376 (setq rmail-summary-vector
1377 (vconcat rmail-summary-vector (make-vector total-messages nil)))
1378 (goto-char (point-min))
1379 (or nomsg (message "Counting new messages...done (%d)" total-messages))))
1380
1381 (defun rmail-set-message-counters ()
1382 (rmail-forget-messages)
1383 (save-excursion
1384 (save-restriction
1385 (widen)
1386 (let* ((point-save (point))
1387 (total-messages 0)
1388 (messages-after-point)
1389 (case-fold-search nil)
1390 (messages-head nil)
1391 (deleted-head nil))
1392 (message "Counting messages...")
1393 (goto-char (point-max))
1394 ;; Put at the end of messages-head
1395 ;; the entry for message N+1, which marks
1396 ;; the end of message N. (N = number of messages).
1397 (search-backward "\n\^_" nil t)
1398 (if (/= (point) (point-max)) (forward-char 1))
1399 (setq messages-head (list (point-marker)))
1400 (rmail-set-message-counters-counter (min (point) point-save))
1401 (setq messages-after-point total-messages)
1402 (rmail-set-message-counters-counter)
1403 (setq rmail-total-messages total-messages)
1404 (setq rmail-current-message
1405 (min total-messages
1406 (max 1 (- total-messages messages-after-point))))
1407 (setq rmail-message-vector
1408 (apply 'vector (cons (point-min-marker) messages-head))
1409 rmail-deleted-vector (concat "D" deleted-head)
1410 rmail-summary-vector (make-vector rmail-total-messages nil))
1411 (message "Counting messages...done")))))
1412
1413 (defun rmail-set-message-counters-counter (&optional stop)
1414 (while (search-backward "\n\^_\^L\n" stop t)
1415 (forward-char 1)
1416 (setq messages-head (cons (point-marker) messages-head))
1417 (save-excursion
1418 (setq deleted-head
1419 (cons (if (search-backward ", deleted,"
1420 (prog1 (point)
1421 (forward-line 2))
1422 t)
1423 ?D ?\ )
1424 deleted-head)))
1425 (if (zerop (% (setq total-messages (1+ total-messages)) 20))
1426 (message "Counting messages...%d" total-messages))))
1427
1428 (defun rmail-beginning-of-message ()
1429 "Show current message starting from the beginning."
1430 (interactive)
1431 (rmail-show-message rmail-current-message))
1432
1433 (defun rmail-show-message (&optional n)
1434 "Show message number N (prefix argument), counting from start of file.
1435 If summary buffer is currently displayed, update current message there also."
1436 (interactive "p")
1437 (rmail-maybe-set-message-counters)
1438 (widen)
1439 (if (zerop rmail-total-messages)
1440 (progn (narrow-to-region (point-min) (1- (point-max)))
1441 (goto-char (point-min))
1442 (setq mode-line-process nil))
1443 (let (blurb)
1444 (if (not n)
1445 (setq n rmail-current-message)
1446 (cond ((<= n 0)
1447 (setq n 1
1448 rmail-current-message 1
1449 blurb "No previous message"))
1450 ((> n rmail-total-messages)
1451 (setq n rmail-total-messages
1452 rmail-current-message rmail-total-messages
1453 blurb "No following message"))
1454 (t
1455 (setq rmail-current-message n))))
1456 (let ((beg (rmail-msgbeg n))
1457 (end (rmail-msgend n)))
1458 (goto-char beg)
1459 (forward-line 1)
1460 (if (= (following-char) ?0)
1461 (progn
1462 (rmail-reformat-message beg end)
1463 (rmail-set-attribute "unseen" nil))
1464 (search-forward "\n*** EOOH ***\n" end t)
1465 (narrow-to-region (point) end))
1466 (goto-char (point-min))
1467 (rmail-display-labels)
1468 (rmail-highlight-headers)
1469 (if transient-mark-mode (deactivate-mark))
1470 (run-hooks 'rmail-show-message-hook)
1471 ;; If there is a summary buffer, try to move to this message
1472 ;; in that buffer. But don't complain if this message
1473 ;; is not mentioned in the summary.
1474 (if (rmail-summary-exists)
1475 (let ((curr-msg rmail-current-message))
1476 (rmail-select-summary
1477 (rmail-summary-goto-msg curr-msg t t))))
1478 (if blurb
1479 (message blurb))))))
1480
1481 ;; Find all occurrences of certain fields, and highlight them.
1482 (defun rmail-highlight-headers ()
1483 ;; Do this only if the system supports faces.
1484 (if (and (fboundp 'internal-find-face)
1485 rmail-highlighted-headers)
1486 (save-excursion
1487 (search-forward "\n\n" nil 'move)
1488 (save-restriction
1489 (narrow-to-region (point-min) (point))
1490 (let ((case-fold-search t)
1491 (inhibit-read-only t)
1492 ;; Highlight with boldface if that is available.
1493 ;; Otherwise use the `highlight' face.
1494 (face (or rmail-highlight-face
1495 (if (face-differs-from-default-p 'bold)
1496 'bold 'highlight)))
1497 ;; List of overlays to reuse.
1498 (overlays rmail-overlay-list))
1499 (goto-char (point-min))
1500 (while (re-search-forward rmail-highlighted-headers nil t)
1501 (skip-chars-forward " \t")
1502 (let ((beg (point))
1503 overlay)
1504 (while (progn (forward-line 1)
1505 (looking-at "[ \t]")))
1506 ;; Back up over newline, then trailing spaces or tabs
1507 (forward-char -1)
1508 (while (member (preceding-char) '(? ?\t))
1509 (forward-char -1))
1510 (if overlays
1511 ;; Reuse an overlay we already have.
1512 (progn
1513 (setq overlay (car overlays)
1514 overlays (cdr overlays))
1515 (overlay-put overlay 'face face)
1516 (move-overlay overlay beg (point)))
1517 ;; Make a new overlay and add it to
1518 ;; rmail-overlay-list.
1519 (setq overlay (make-overlay beg (point)))
1520 (overlay-put overlay 'face face)
1521 (setq rmail-overlay-list
1522 (cons overlay rmail-overlay-list))))))))))
1523
1524 (defun rmail-next-message (n)
1525 "Show following message whether deleted or not.
1526 With prefix arg N, moves forward N messages, or backward if N is negative."
1527 (interactive "p")
1528 (rmail-maybe-set-message-counters)
1529 (rmail-show-message (+ rmail-current-message n)))
1530
1531 (defun rmail-previous-message (n)
1532 "Show previous message whether deleted or not.
1533 With prefix arg N, moves backward N messages, or forward if N is negative."
1534 (interactive "p")
1535 (rmail-next-message (- n)))
1536
1537 (defun rmail-next-undeleted-message (n)
1538 "Show following non-deleted message.
1539 With prefix arg N, moves forward N non-deleted messages,
1540 or backward if N is negative.
1541
1542 Returns t if a new message is being shown, nil otherwise."
1543 (interactive "p")
1544 (rmail-maybe-set-message-counters)
1545 (let ((lastwin rmail-current-message)
1546 (current rmail-current-message))
1547 (while (and (> n 0) (< current rmail-total-messages))
1548 (setq current (1+ current))
1549 (if (not (rmail-message-deleted-p current))
1550 (setq lastwin current n (1- n))))
1551 (while (and (< n 0) (> current 1))
1552 (setq current (1- current))
1553 (if (not (rmail-message-deleted-p current))
1554 (setq lastwin current n (1+ n))))
1555 (if (/= lastwin rmail-current-message)
1556 (progn (rmail-show-message lastwin)
1557 t)
1558 (if (< n 0)
1559 (message "No previous nondeleted message"))
1560 (if (> n 0)
1561 (message "No following nondeleted message"))
1562 nil)))
1563
1564 (defun rmail-previous-undeleted-message (n)
1565 "Show previous non-deleted message.
1566 With prefix argument N, moves backward N non-deleted messages,
1567 or forward if N is negative."
1568 (interactive "p")
1569 (rmail-next-undeleted-message (- n)))
1570
1571 (defun rmail-first-message ()
1572 "Show first message in file."
1573 (interactive)
1574 (rmail-maybe-set-message-counters)
1575 (rmail-show-message 1))
1576
1577 (defun rmail-last-message ()
1578 "Show last message in file."
1579 (interactive)
1580 (rmail-maybe-set-message-counters)
1581 (rmail-show-message rmail-total-messages))
1582
1583 (defun rmail-what-message ()
1584 (let ((where (point))
1585 (low 1)
1586 (high rmail-total-messages)
1587 (mid (/ rmail-total-messages 2)))
1588 (while (> (- high low) 1)
1589 (if (>= where (rmail-msgbeg mid))
1590 (setq low mid)
1591 (setq high mid))
1592 (setq mid (+ low (/ (- high low) 2))))
1593 (if (>= where (rmail-msgbeg high)) high low)))
1594
1595 (defun rmail-message-recipients-p (msg recipients &optional primary-only)
1596 (save-restriction
1597 (goto-char (rmail-msgbeg msg))
1598 (search-forward "\n*** EOOH ***\n")
1599 (narrow-to-region (point) (progn (search-forward "\n\n") (point)))
1600 (or (string-match recipients (or (mail-fetch-field "To") ""))
1601 (string-match recipients (or (mail-fetch-field "From") ""))
1602 (if (not primary-only)
1603 (string-match recipients (or (mail-fetch-field "Cc") ""))))))
1604
1605 (defun rmail-message-regexp-p (msg regexp)
1606 "Return t, if for message number MSG, regexp REGEXP matches in the header."
1607 (goto-char (rmail-msgbeg msg))
1608 (let ((end
1609 (save-excursion
1610 (search-forward "*** EOOH ***" (point-max)) (point))))
1611 (re-search-forward regexp end t)))
1612
1613 (defun rmail-search-backward (regexp &optional n)
1614 "Show message containing next match for REGEXP.
1615 Prefix argument gives repeat count; negative argument means search
1616 backwards (through earlier messages).
1617 Interactively, empty argument means use same regexp used last time."
1618 (interactive
1619 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg) 0))
1620 (prompt
1621 (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
1622 regexp)
1623 (if rmail-search-last-regexp
1624 (setq prompt (concat prompt
1625 "(default "
1626 rmail-search-last-regexp
1627 ") ")))
1628 (setq regexp (read-string prompt))
1629 (cond ((not (equal regexp ""))
1630 (setq rmail-search-last-regexp regexp))
1631 ((not rmail-search-last-regexp)
1632 (error "No previous Rmail search string")))
1633 (list rmail-search-last-regexp
1634 (prefix-numeric-value current-prefix-arg))))
1635 (rmail-search regexp (- n)))
1636
1637 (defvar rmail-search-last-regexp nil)
1638 (defun rmail-search (regexp &optional n)
1639 "Show message containing next match for REGEXP.
1640 Prefix argument gives repeat count; negative argument means search
1641 backwards (through earlier messages).
1642 Interactively, empty argument means use same regexp used last time."
1643 (interactive
1644 (let* ((reversep (< (prefix-numeric-value current-prefix-arg) 0))
1645 (prompt
1646 (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
1647 regexp)
1648 (if rmail-search-last-regexp
1649 (setq prompt (concat prompt
1650 "(default "
1651 rmail-search-last-regexp
1652 ") ")))
1653 (setq regexp (read-string prompt))
1654 (cond ((not (equal regexp ""))
1655 (setq rmail-search-last-regexp regexp))
1656 ((not rmail-search-last-regexp)
1657 (error "No previous Rmail search string")))
1658 (list rmail-search-last-regexp
1659 (prefix-numeric-value current-prefix-arg))))
1660 (or n (setq n 1))
1661 (message "%sRmail search for %s..."
1662 (if (< n 0) "Reverse " "")
1663 regexp)
1664 (rmail-maybe-set-message-counters)
1665 (let ((omin (point-min))
1666 (omax (point-max))
1667 (opoint (point))
1668 win
1669 (reversep (< n 0))
1670 (msg rmail-current-message))
1671 (unwind-protect
1672 (progn
1673 (widen)
1674 (while (/= n 0)
1675 ;; Check messages one by one, advancing message number up or down
1676 ;; but searching forward through each message.
1677 (if reversep
1678 (while (and (null win) (> msg 1))
1679 (goto-char (rmail-msgbeg (setq msg (1- msg))))
1680 (setq win (re-search-forward
1681 regexp (rmail-msgend msg) t)))
1682 (while (and (null win) (< msg rmail-total-messages))
1683 (goto-char (rmail-msgbeg (setq msg (1+ msg))))
1684 (setq win (re-search-forward regexp (rmail-msgend msg) t))))
1685 (setq n (+ n (if reversep 1 -1)))))
1686 (if win
1687 (progn
1688 ;; If this is a reverse search and we found a message,
1689 ;; search backward thru this message to position point.
1690 (if reversep
1691 (progn
1692 (goto-char (rmail-msgend msg))
1693 (re-search-backward
1694 regexp (rmail-msgbeg msg) t)))
1695 (setq win (point))
1696 (rmail-show-message msg)
1697 (message "%sRmail search for %s...done"
1698 (if reversep "Reverse " "")
1699 regexp)
1700 (goto-char win))
1701 (goto-char opoint)
1702 (narrow-to-region omin omax)
1703 (ding)
1704 (message "Search failed: %s" regexp)))))
1705
1706 (defun rmail-search-backwards (regexp &optional n)
1707 "Show message containing previous match for REGEXP.
1708 Prefix argument gives repeat count; negative argument means search
1709 forward (through later messages).
1710 Interactively, empty argument means use same regexp used last time."
1711 (interactive
1712 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg) 0))
1713 (prompt
1714 (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
1715 regexp)
1716 (if rmail-search-last-regexp
1717 (setq prompt (concat prompt
1718 "(default "
1719 rmail-search-last-regexp
1720 ") ")))
1721 (setq regexp (read-string prompt))
1722 (cond ((not (equal regexp ""))
1723 (setq rmail-search-last-regexp regexp))
1724 ((not rmail-search-last-regexp)
1725 (error "No previous Rmail search string")))
1726 (list rmail-search-last-regexp
1727 (prefix-numeric-value current-prefix-arg))))
1728 (rmail-search regexp (- (or n -1))))
1729
1730 ;; Show the first message which has the `unseen' attribute.
1731 (defun rmail-first-unseen-message ()
1732 (rmail-maybe-set-message-counters)
1733 (let ((current 1)
1734 found)
1735 (save-restriction
1736 (widen)
1737 (while (and (not found) (< current rmail-total-messages))
1738 (if (rmail-message-labels-p current ", ?\\(unseen\\),")
1739 (setq found current))
1740 (setq current (1+ current))))
1741 ;; Let the caller show the message.
1742 ;; (if found
1743 ;; (rmail-show-message found))
1744 found))
1745 \f
1746 ;;;; *** Rmail Message Deletion Commands ***
1747
1748 (defun rmail-message-deleted-p (n)
1749 (= (aref rmail-deleted-vector n) ?D))
1750
1751 (defun rmail-set-message-deleted-p (n state)
1752 (aset rmail-deleted-vector n (if state ?D ?\ )))
1753
1754 (defun rmail-delete-message ()
1755 "Delete this message and stay on it."
1756 (interactive)
1757 (rmail-set-attribute "deleted" t))
1758
1759 (defun rmail-undelete-previous-message ()
1760 "Back up to deleted message, select it, and undelete it."
1761 (interactive)
1762 (let ((msg rmail-current-message))
1763 (while (and (> msg 0)
1764 (not (rmail-message-deleted-p msg)))
1765 (setq msg (1- msg)))
1766 (if (= msg 0)
1767 (error "No previous deleted message")
1768 (if (/= msg rmail-current-message)
1769 (rmail-show-message msg))
1770 (rmail-set-attribute "deleted" nil)
1771 (if (rmail-summary-exists)
1772 (save-excursion
1773 (set-buffer rmail-summary-buffer)
1774 (rmail-summary-mark-undeleted msg)))
1775 (rmail-maybe-display-summary))))
1776
1777 (defun rmail-delete-forward (&optional backward)
1778 "Delete this message and move to next nondeleted one.
1779 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
1780 With prefix argument, delete and move backward.
1781
1782 Returns t if a new message is displayed after the delete, or nil otherwise."
1783 (interactive "P")
1784 (rmail-set-attribute "deleted" t)
1785 (let ((del-msg rmail-current-message))
1786 (if (rmail-summary-exists)
1787 (save-excursion
1788 (set-buffer rmail-summary-buffer)
1789 (rmail-summary-mark-deleted del-msg)))
1790 (prog1 (rmail-next-undeleted-message (if backward -1 1))
1791 (rmail-maybe-display-summary))))
1792
1793 (defun rmail-delete-backward ()
1794 "Delete this message and move to previous nondeleted one.
1795 Deleted messages stay in the file until the \\[rmail-expunge] command is given."
1796 (interactive)
1797 (rmail-delete-forward t))
1798
1799 ;; Compute the message number a given message would have after expunging.
1800 ;; The present number of the message is OLDNUM.
1801 ;; DELETEDVEC should be rmail-deleted-vector.
1802 ;; The value is nil for a message that would be deleted.
1803 (defun rmail-msg-number-after-expunge (deletedvec oldnum)
1804 (if (or (null oldnum) (= (aref deletedvec oldnum) ?D))
1805 nil
1806 (let ((i 0)
1807 (newnum 0))
1808 (while (< i oldnum)
1809 (if (/= (aref deletedvec i) ?D)
1810 (setq newnum (1+ newnum)))
1811 (setq i (1+ i)))
1812 newnum)))
1813
1814 (defun rmail-only-expunge ()
1815 "Actually erase all deleted messages in the file."
1816 (interactive)
1817 (message "Expunging deleted messages...")
1818 ;; Discard all undo records for this buffer.
1819 (or (eq buffer-undo-list t)
1820 (setq buffer-undo-list nil))
1821 (rmail-maybe-set-message-counters)
1822 (let* ((omax (- (buffer-size) (point-max)))
1823 (omin (- (buffer-size) (point-min)))
1824 (opoint (if (and (> rmail-current-message 0)
1825 (rmail-message-deleted-p rmail-current-message))
1826 0
1827 (- (point) (point-min))))
1828 (messages-head (cons (aref rmail-message-vector 0) nil))
1829 (messages-tail messages-head)
1830 ;; Don't make any undo records for the expunging.
1831 (buffer-undo-list t)
1832 (win))
1833 (unwind-protect
1834 (save-excursion
1835 (widen)
1836 (goto-char (point-min))
1837 (let ((counter 0)
1838 (number 1)
1839 (total rmail-total-messages)
1840 (new-message-number rmail-current-message)
1841 (new-summary nil)
1842 (rmailbuf (current-buffer))
1843 (buffer-read-only nil)
1844 (messages rmail-message-vector)
1845 (deleted rmail-deleted-vector)
1846 (summary rmail-summary-vector))
1847 (setq rmail-total-messages nil
1848 rmail-current-message nil
1849 rmail-message-vector nil
1850 rmail-deleted-vector nil
1851 rmail-summary-vector nil)
1852
1853 ;; Find each sendmail buffer that is set to reply
1854 ;; to a message in this buffer, and update its
1855 ;; message number.
1856 (let ((bufs (buffer-list)))
1857 (while bufs
1858 (save-excursion
1859 (set-buffer (car bufs))
1860 (and (boundp 'rmail-send-actions-rmail-buffer)
1861 (eq rmail-send-actions-rmail-buffer rmailbuf)
1862 (setq rmail-send-actions-rmail-msg-number
1863 (rmail-msg-number-after-expunge
1864 deleted
1865 rmail-send-actions-rmail-msg-number))))
1866 (setq bufs (cdr bufs))))
1867
1868 (while (<= number total)
1869 (if (= (aref deleted number) ?D)
1870 (progn
1871 (delete-region
1872 (marker-position (aref messages number))
1873 (marker-position (aref messages (1+ number))))
1874 (move-marker (aref messages number) nil)
1875 (if (> new-message-number counter)
1876 (setq new-message-number (1- new-message-number))))
1877 (setq counter (1+ counter))
1878 (setq messages-tail
1879 (setcdr messages-tail
1880 (cons (aref messages number) nil)))
1881 (setq new-summary
1882 (cons (if (= counter number) (aref summary (1- number)))
1883 new-summary)))
1884 (if (zerop (% (setq number (1+ number)) 20))
1885 (message "Expunging deleted messages...%d" number)))
1886 (setq messages-tail
1887 (setcdr messages-tail
1888 (cons (aref messages number) nil)))
1889 (setq rmail-current-message new-message-number
1890 rmail-total-messages counter
1891 rmail-message-vector (apply 'vector messages-head)
1892 rmail-deleted-vector (make-string (1+ counter) ?\ )
1893 rmail-summary-vector (vconcat (nreverse new-summary))
1894 win t)))
1895 (message "Expunging deleted messages...done")
1896 (if (not win)
1897 (narrow-to-region (- (buffer-size) omin) (- (buffer-size) omax)))
1898 (rmail-show-message
1899 (if (zerop rmail-current-message) 1 nil))
1900 (forward-char opoint))))
1901
1902 (defun rmail-expunge ()
1903 "Erase deleted messages from Rmail file and summary buffer."
1904 (interactive)
1905 (rmail-only-expunge)
1906 (if (rmail-summary-exists)
1907 (rmail-select-summary
1908 (rmail-update-summary))))
1909 \f
1910 ;;;; *** Rmail Mailing Commands ***
1911
1912 (defun rmail-start-mail (&rest args)
1913 (if (and window-system rmail-mail-new-frame)
1914 (prog1
1915 (apply 'mail-other-frame args)
1916 (modify-frame-parameters (selected-frame)
1917 '((dedicated . t))))
1918 (apply 'mail-other-window args)))
1919
1920 (defun rmail-mail ()
1921 "Send mail in another window.
1922 While composing the message, use \\[mail-yank-original] to yank the
1923 original message into it."
1924 (interactive)
1925 (rmail-start-mail nil nil nil nil nil (current-buffer)))
1926
1927 (defun rmail-continue ()
1928 "Continue composing outgoing message previously being composed."
1929 (interactive)
1930 (rmail-start-mail t))
1931
1932 (defun rmail-reply (just-sender)
1933 "Reply to the current message.
1934 Normally include CC: to all other recipients of original message;
1935 prefix argument means ignore them. While composing the reply,
1936 use \\[mail-yank-original] to yank the original message into it."
1937 (interactive "P")
1938 (let (from reply-to cc subject date to message-id resent-reply-to
1939 (msgnum rmail-current-message)
1940 (rmail-buffer (current-buffer)))
1941 (save-excursion
1942 (save-restriction
1943 (widen)
1944 (goto-char (rmail-msgbeg rmail-current-message))
1945 (forward-line 1)
1946 (if (= (following-char) ?0)
1947 (narrow-to-region
1948 (progn (forward-line 2)
1949 (point))
1950 (progn (search-forward "\n\n" (rmail-msgend rmail-current-message)
1951 'move)
1952 (point)))
1953 (narrow-to-region (point)
1954 (progn (search-forward "\n*** EOOH ***\n")
1955 (beginning-of-line) (point))))
1956 (setq resent-reply-to (mail-fetch-field "resent-reply-to" t)
1957 from (mail-fetch-field "from")
1958 reply-to (or resent-reply-to
1959 (mail-fetch-field "reply-to" nil t)
1960 from)
1961 cc (cond (just-sender nil)
1962 (resent-reply-to (mail-fetch-field "resent-cc" t))
1963 (t (mail-fetch-field "cc" nil t)))
1964 subject (or (and resent-reply-to
1965 (mail-fetch-field "resent-subject" t))
1966 (mail-fetch-field "subject"))
1967 date (or (and resent-reply-to
1968 (mail-fetch-field "resent-date" t))
1969 (mail-fetch-field "date"))
1970 to (cond (resent-reply-to
1971 (or (mail-fetch-field "resent-to" t)) "")
1972 ((mail-fetch-field "to" nil t))
1973 ;((mail-fetch-field "apparently-to")) ack gag barf
1974 (t ""))
1975 message-id (cond (resent-reply-to
1976 (mail-fetch-field "resent-message-id" t))
1977 ((mail-fetch-field "message-id"))))))
1978 (and (stringp subject)
1979 (or (string-match (concat "\\`" (regexp-quote rmail-reply-prefix))
1980 subject)
1981 (setq subject (concat rmail-reply-prefix subject))))
1982 (rmail-start-mail nil
1983 (mail-strip-quoted-names reply-to)
1984 subject
1985 (rmail-make-in-reply-to-field from date message-id)
1986 (if just-sender
1987 nil
1988 (let* ((cc-list (rmail-dont-reply-to
1989 (mail-strip-quoted-names
1990 (if (null cc) to (concat to ", " cc))))))
1991 (if (string= cc-list "") nil cc-list)))
1992 (current-buffer)
1993 (list (list '(lambda ()
1994 (let ((msgnum rmail-send-actions-rmail-msg-number))
1995 (save-excursion
1996 (set-buffer rmail-send-actions-rmail-buffer)
1997 (if msgnum
1998 (rmail-set-attribute "answered" t msgnum))))))))
1999 ;; We keep the rmail buffer and message number in these
2000 ;; buffer-local vars in the sendmail buffer,
2001 ;; so that rmail-only-expunge can relocate the message number.
2002 (make-local-variable 'rmail-send-actions-rmail-buffer)
2003 (make-local-variable 'rmail-send-actions-rmail-msg-number)
2004 (setq rmail-send-actions-rmail-buffer rmail-buffer)
2005 (setq rmail-send-actions-rmail-msg-number msgnum)))
2006
2007 (defun rmail-make-in-reply-to-field (from date message-id)
2008 (cond ((not from)
2009 (if message-id
2010 message-id
2011 nil))
2012 (mail-use-rfc822
2013 (require 'rfc822)
2014 (let ((tem (car (rfc822-addresses from))))
2015 (if message-id
2016 (if (string-match
2017 (regexp-quote (if (string-match "@[^@]*\\'" tem)
2018 (substring tem 0 (match-beginning 0))
2019 tem))
2020 message-id)
2021 ;; Message-ID is sufficiently informative
2022 message-id
2023 (concat message-id " (" tem ")"))
2024 ;; Copy TEM, discarding text properties.
2025 (setq tem (copy-sequence tem))
2026 (set-text-properties 0 (length tem) nil tem)
2027 (setq tem (copy-sequence tem))
2028 ;; Use prin1 to fake RFC822 quoting
2029 (let ((field (prin1-to-string tem)))
2030 (if date
2031 (concat field "'s message of " date)
2032 field)))))
2033 ((let* ((foo "[^][\000-\037\177-\377()<>@,;:\\\" ]+")
2034 (bar "[^][\000-\037\177-\377()<>@,;:\\\"]+"))
2035 ;; Can't use format because format loses on \000 (unix *^&%*^&%$!!)
2036 (or (string-match (concat "\\`[ \t]*\\(" bar
2037 "\\)\\(<" foo "@" foo ">\\)?[ \t]*\\'")
2038 ;; "Unix Loser <Foo@bar.edu>" => "Unix Loser"
2039 from)
2040 (string-match (concat "\\`[ \t]*<" foo "@" foo ">[ \t]*(\\("
2041 bar "\\))[ \t]*\\'")
2042 ;; "<Bugs@bar.edu>" (Losing Unix) => "Losing Unix"
2043 from)))
2044 (let ((start (match-beginning 1))
2045 (end (match-end 1)))
2046 ;; Trim whitespace which above regexp match allows
2047 (while (and (< start end)
2048 (memq (aref from start) '(?\t ?\ )))
2049 (setq start (1+ start)))
2050 (while (and (< start end)
2051 (memq (aref from (1- end)) '(?\t ?\ )))
2052 (setq end (1- end)))
2053 (let ((field (substring from start end)))
2054 (if date (setq field (concat "message from " field " on " date)))
2055 (if message-id
2056 ;; "<AA259@bar.edu> (message from Unix Loser on 1-Apr-89)"
2057 (concat message-id " (" field ")")
2058 field))))
2059 (t
2060 ;; If we can't kludge it simply, do it correctly
2061 (let ((mail-use-rfc822 t))
2062 (rmail-make-in-reply-to-field from date message-id)))))
2063
2064 (defun rmail-forward (resend)
2065 "Forward the current message to another user.
2066 With prefix argument, \"resend\" the message instead of forwarding it;
2067 see the documentation of `rmail-resend'."
2068 (interactive "P")
2069 (if resend
2070 (call-interactively 'rmail-resend)
2071 (let ((forward-buffer (current-buffer))
2072 (msgnum rmail-current-message)
2073 (subject (concat "["
2074 (let ((from (or (mail-fetch-field "From")
2075 (mail-fetch-field ">From"))))
2076 (if from
2077 (concat (mail-strip-quoted-names from) ": ")
2078 ""))
2079 (or (mail-fetch-field "Subject") "")
2080 "]")))
2081 ;; If only one window, use it for the mail buffer.
2082 ;; Otherwise, use another window for the mail buffer
2083 ;; so that the Rmail buffer remains visible
2084 ;; and sending the mail will get back to it.
2085 (if (funcall (if (and (not rmail-mail-new-frame) (one-window-p t))
2086 (function mail)
2087 (function rmail-start-mail))
2088 nil nil subject nil nil nil
2089 (list (list (function
2090 (lambda ()
2091 (let ((msgnum
2092 rmail-send-actions-rmail-msg-number))
2093 (save-excursion
2094 (set-buffer rmail-send-actions-rmail-buffer)
2095 (if msgnum
2096 (rmail-set-attribute
2097 "forwarded" t msgnum)))))))))
2098 ;; The mail buffer is now current.
2099 (save-excursion
2100 ;; We keep the rmail buffer and message number in these
2101 ;; buffer-local vars in the sendmail buffer,
2102 ;; so that rmail-only-expunge can relocate the message number.
2103 (make-local-variable 'rmail-send-actions-rmail-buffer)
2104 (make-local-variable 'rmail-send-actions-rmail-msg-number)
2105 (setq rmail-send-actions-rmail-buffer forward-buffer)
2106 (setq rmail-send-actions-rmail-msg-number msgnum)
2107 ;; Insert after header separator--before signature if any.
2108 (goto-char (point-min))
2109 (search-forward-regexp
2110 (concat "^" (regexp-quote mail-header-separator) "$"))
2111 (forward-line 1)
2112 (insert "------- Start of forwarded message -------\n")
2113 (insert-buffer-substring forward-buffer)
2114 (insert "------- End of forwarded message -------\n")
2115 (push-mark))))))
2116
2117 (defun rmail-resend (address &optional from comment mail-alias-file)
2118 "Resend current message to ADDRESSES.
2119 ADDRESSES should be a single address, a string consisting of several
2120 addresses separated by commas, or a list of addresses.
2121
2122 Optional FROM is the address to resend the message from, and
2123 defaults to the username of the person redistributing the message.
2124 Optional COMMENT is a string that will be inserted as a comment in the
2125 resent message.
2126 Optional ALIAS-FILE is alternate aliases file to be used by sendmail,
2127 typically for purposes of moderating a list."
2128 (interactive "sResend to: ")
2129 (require 'sendmail)
2130 (require 'mailalias)
2131 (if (not from) (setq from (user-login-name)))
2132 (let ((tembuf (generate-new-buffer " sendmail temp"))
2133 (mail-header-separator "")
2134 (case-fold-search nil)
2135 (mailbuf (current-buffer)))
2136 (unwind-protect
2137 (save-excursion
2138 ;;>> Copy message into temp buffer
2139 (set-buffer tembuf)
2140 (insert-buffer-substring mailbuf)
2141 (goto-char (point-min))
2142 ;; Delete any Sender field, since that's not specifyable.
2143 ; Only delete Sender fields in the actual header.
2144 (re-search-forward "^$" nil 'move)
2145 ; Using "while" here rather than "if" because some buggy mail
2146 ; software may have inserted multiple Sender fields.
2147 (while (re-search-backward "^Sender:" nil t)
2148 (let (beg)
2149 (setq beg (point))
2150 (forward-line 1)
2151 (while (looking-at "[ \t]")
2152 (forward-line 1))
2153 (delete-region beg (point))))
2154 ; Go back to the beginning of the buffer so the Resent- fields
2155 ; are inserted there.
2156 (goto-char (point-min))
2157 ;;>> Insert resent-from:
2158 (insert "Resent-From: " from "\n")
2159 (insert "Resent-Date: " (mail-rfc822-date) "\n")
2160 ;;>> Insert resent-to: and bcc if need be.
2161 (let ((before (point)))
2162 (if mail-self-blind
2163 (insert "Resent-Bcc: " (user-login-name) "\n"))
2164 (insert "Resent-To: " (if (stringp address)
2165 address
2166 (mapconcat 'identity address ",\n\t"))
2167 "\n")
2168 (save-excursion
2169 (expand-mail-aliases before (point))))
2170 ;;>> Set up comment, if any.
2171 (if (and (sequencep comment) (not (zerop (length comment))))
2172 (let ((before (point))
2173 after)
2174 (insert comment)
2175 (or (eolp) (insert "\n"))
2176 (setq after (point))
2177 (goto-char before)
2178 (while (< (point) after)
2179 (insert "Resent-Comment: ")
2180 (forward-line 1))))
2181 ;; Don't expand aliases in the destination fields
2182 ;; of the original message.
2183 (let (mail-aliases)
2184 (funcall send-mail-function)))
2185 (kill-buffer tembuf))
2186 (rmail-set-attribute "resent" t rmail-current-message)))
2187
2188 (defvar mail-unsent-separator
2189 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
2190 "^ *---+ +Returned message +---+ *$\\|"
2191 "^ *---+ +Original message +---+ *$\\|"
2192 "^ *--+ +begin message +--+ *$\\|"
2193 "^ *---+ +Original message follows +---+ *$\\|"
2194 "^|? *---+ +Message text follows: +---+ *|?$")
2195 "A regexp that matches the separator before the text of a failed message.")
2196
2197 (defun rmail-retry-failure ()
2198 "Edit a mail message which is based on the contents of the current message.
2199 For a message rejected by the mail system, extract the interesting headers and
2200 the body of the original message.
2201 The variable `mail-unsent-separator' should match the string that
2202 delimits the returned original message.
2203 The variable `rmail-retry-ignored-headers' is a regular expression
2204 specifying headers which should not be copied into the new message."
2205 (interactive)
2206 (require 'mail-utils)
2207 (let (mail-buffer bounce-start bounce-end resending)
2208 (save-excursion
2209 ;; Narrow down to just the quoted original message
2210 (rmail-beginning-of-message)
2211 (let ((case-fold-search t))
2212 (or (re-search-forward mail-unsent-separator nil t)
2213 (error "Cannot parse this as a failure message")))
2214 (save-restriction
2215 (let ((old-end (point-max)))
2216 ;; One message contained a few random lines before the old
2217 ;; message header. The first line of the message started with
2218 ;; two hyphens. A blank line follows these random lines.
2219 (skip-chars-forward "\n")
2220 (if (looking-at "^--")
2221 (progn
2222 (search-forward "\n\n")
2223 (skip-chars-forward "\n")))
2224 (beginning-of-line)
2225 (narrow-to-region (point) (point-max))
2226 (setq mail-buffer (current-buffer)
2227 bounce-start (point)
2228 bounce-end (point-max))
2229 (or (search-forward "\n\n" nil t)
2230 (error "Cannot find end of header in failed message")))))
2231 ;; Start sending a new message; default header fields from the original.
2232 ;; Turn off the usual actions for initializing the message body
2233 ;; because we want to get only the text from the failure message.
2234 (let (mail-signature mail-setup-hook)
2235 (if (rmail-start-mail nil nil nil nil nil mail-buffer)
2236 ;; Insert original text as initial text of new draft message.
2237 (progn
2238 (erase-buffer)
2239 (insert-buffer-substring mail-buffer bounce-start bounce-end)
2240 (goto-char (point-min))
2241 (rmail-clear-headers rmail-retry-ignored-headers)
2242 (rmail-clear-headers "^sender:")
2243 (goto-char (point-min))
2244 (save-restriction
2245 (search-forward "\n\n")
2246 (forward-line -1)
2247 (narrow-to-region (point-min) (point))
2248 (setq resending (mail-fetch-field "resent-to"))
2249 (if mail-self-blind
2250 (if resending
2251 (insert "Resent-Bcc: " (user-login-name) "\n")
2252 (insert "BCC: " (user-login-name) "\n"))))
2253 (insert mail-header-separator)
2254 (mail-position-on-field (if resending "Resent-To" "To") t)
2255 (set-buffer mail-buffer)
2256 (rmail-beginning-of-message))))))
2257
2258 (defun rmail-bury ()
2259 "Bury current Rmail buffer and its summary buffer."
2260 (interactive)
2261 ;; This let var was called rmail-buffer, but that interfered
2262 ;; with the buffer-local var used in summary buffers.
2263 (let ((buffer-to-bury (current-buffer)))
2264 (if (rmail-summary-exists)
2265 (let (window)
2266 (while (setq window (get-buffer-window rmail-summary-buffer))
2267 (set-window-buffer window (other-buffer rmail-summary-buffer)))
2268 (bury-buffer rmail-summary-buffer)))
2269 (switch-to-buffer (other-buffer (current-buffer)))
2270 (bury-buffer buffer-to-bury)))
2271
2272 (defun rmail-summary-exists ()
2273 "Non-nil iff in an RMAIL buffer and an associated summary buffer exists.
2274 In fact, the non-nil value returned is the summary buffer itself."
2275 (and rmail-summary-buffer (buffer-name rmail-summary-buffer)
2276 rmail-summary-buffer))
2277
2278 (defun rmail-summary-displayed ()
2279 "t iff in RMAIL buffer and an associated summary buffer is displayed."
2280 (and rmail-summary-buffer (get-buffer-window rmail-summary-buffer)))
2281
2282 (defvar rmail-redisplay-summary nil
2283 "*Non-nil means Rmail should show the summary when it changes.
2284 This has an effect only if a summary buffer exists.")
2285
2286 (defvar rmail-summary-window-size nil
2287 "*Non-nil means specify the height for an Rmail summary window.")
2288
2289 ;; Put the summary buffer back on the screen, if user wants that.
2290 (defun rmail-maybe-display-summary ()
2291 (let ((selected (selected-window))
2292 window)
2293 ;; If requested, make sure the summary is displayed.
2294 (and rmail-summary-buffer (buffer-name rmail-summary-buffer)
2295 rmail-redisplay-summary
2296 (if (get-buffer-window rmail-summary-buffer 0)
2297 ;; It's already in some frame; show that one.
2298 (let ((frame (window-frame
2299 (get-buffer-window rmail-summary-buffer 0))))
2300 (make-frame-visible frame)
2301 (raise-frame frame))
2302 (display-buffer rmail-summary-buffer)))
2303 ;; If requested, set the height of the summary window.
2304 (and rmail-summary-buffer (buffer-name rmail-summary-buffer)
2305 rmail-summary-window-size
2306 (setq window (get-buffer-window rmail-summary-buffer))
2307 ;; Don't try to change the size if just one window in frame.
2308 (not (eq window (frame-root-window (window-frame window))))
2309 (unwind-protect
2310 (progn
2311 (select-window window)
2312 (enlarge-window (- rmail-summary-window-size
2313 (window-height))))
2314 (select-window selected)))))
2315 \f
2316 ;;;; *** Rmail Specify Inbox Files ***
2317
2318 (autoload 'set-rmail-inbox-list "rmailmsc"
2319 "Set the inbox list of the current RMAIL file to FILE-NAME.
2320 This may be a list of file names separated by commas.
2321 If FILE-NAME is empty, remove any inbox list."
2322 t)
2323
2324 ;;;; *** Rmail Commands for Labels ***
2325
2326 (autoload 'rmail-add-label "rmailkwd"
2327 "Add LABEL to labels associated with current RMAIL message.
2328 Completion is performed over known labels when reading."
2329 t)
2330
2331 (autoload 'rmail-kill-label "rmailkwd"
2332 "Remove LABEL from labels associated with current RMAIL message.
2333 Completion is performed over known labels when reading."
2334 t)
2335
2336 (autoload 'rmail-next-labeled-message "rmailkwd"
2337 "Show next message with LABEL. Defaults to last label used.
2338 With prefix argument N moves forward N messages with this label."
2339 t)
2340
2341 (autoload 'rmail-previous-labeled-message "rmailkwd"
2342 "Show previous message with LABEL. Defaults to last label used.
2343 With prefix argument N moves backward N messages with this label."
2344 t)
2345
2346 (autoload 'rmail-read-label "rmailkwd"
2347 "PROMPT and read with completion an Rmail message label."
2348 t)
2349
2350 ;;;; *** Rmail Edit Mode ***
2351
2352 (autoload 'rmail-edit-current-message "rmailedit"
2353 "Edit the contents of the current message"
2354 t)
2355
2356 ;;;; *** Rmail Sorting ***
2357
2358 (autoload 'rmail-sort-by-date "rmailsort"
2359 "Sort messages of current Rmail file by date.
2360 If prefix argument REVERSE is non-nil, sort them in reverse order." t)
2361
2362 (autoload 'rmail-sort-by-subject "rmailsort"
2363 "Sort messages of current Rmail file by subject.
2364 If prefix argument REVERSE is non-nil, sort them in reverse order." t)
2365
2366 (autoload 'rmail-sort-by-author "rmailsort"
2367 "Sort messages of current Rmail file by author.
2368 If prefix argument REVERSE is non-nil, sort them in reverse order." t)
2369
2370 (autoload 'rmail-sort-by-recipient "rmailsort"
2371 "Sort messages of current Rmail file by recipient.
2372 If prefix argument REVERSE is non-nil, sort them in reverse order." t)
2373
2374 (autoload 'rmail-sort-by-correspondent "rmailsort"
2375 "Sort messages of current Rmail file by other correspondent.
2376 If prefix argument REVERSE is non-nil, sort them in reverse order." t)
2377
2378 (autoload 'rmail-sort-by-lines "rmailsort"
2379 "Sort messages of current Rmail file by number of lines.
2380 If prefix argument REVERSE is non-nil, sort them in reverse order." t)
2381
2382 (autoload 'rmail-sort-by-keywords "rmailsort"
2383 "Sort messages of current Rmail file by labels.
2384 If prefix argument REVERSE is non-nil, sort them in reverse order.
2385 KEYWORDS is a comma-separated list of labels." t)
2386 \f
2387 ;;;; *** Rmail Summary Mode ***
2388
2389 (autoload 'rmail-summary "rmailsum"
2390 "Display a summary of all messages, one line per message."
2391 t)
2392
2393 (autoload 'rmail-summary-by-labels "rmailsum"
2394 "Display a summary of all messages with one or more LABELS.
2395 LABELS should be a string containing the desired labels, separated by commas."
2396 t)
2397
2398 (autoload 'rmail-summary-by-recipients "rmailsum"
2399 "Display a summary of all messages with the given RECIPIENTS.
2400 Normally checks the To, From and Cc fields of headers; but if PRIMARY-ONLY
2401 is non-nil (prefix arg given), only look in the To and From fields.
2402 RECIPIENTS is a string of regexps separated by commas."
2403 t)
2404
2405 (autoload 'rmail-summary-by-regexp "rmailsum"
2406 "Display a summary of all messages according to regexp REGEXP.
2407 If the regular expression is found in the header of the message
2408 \(including in the date and other lines, as well as the subject line),
2409 Emacs will list the header line in the RMAIL-summary."
2410 t)
2411
2412 (autoload 'rmail-summary-by-topic "rmailsum"
2413 "Display a summary of all messages with the given SUBJECT.
2414 Normally checks the Subject field of headers;
2415 but if WHOLE-MESSAGE is non-nil (prefix arg given),
2416 look in the whole message.
2417 SUBJECT is a string of regexps separated by commas."
2418 t)
2419 \f
2420 ;;;; *** Rmail output messages to files ***
2421
2422 (autoload 'rmail-output-to-rmail-file "rmailout"
2423 "Append the current message to an Rmail file named FILE-NAME.
2424 If the file does not exist, ask if it should be created.
2425 If file is being visited, the message is appended to the Emacs
2426 buffer visiting that file."
2427 t)
2428
2429 (autoload 'rmail-output "rmailout"
2430 "Append this message to Unix mail file named FILE-NAME."
2431 t)
2432
2433 ;;;; *** Rmail undigestification ***
2434
2435 (autoload 'undigestify-rmail-message "undigest"
2436 "Break up a digest message into its constituent messages.
2437 Leaves original message, deleted, before the undigestified messages."
2438 t)
2439
2440 (provide 'rmail)
2441
2442 ;;; rmail.el ends here