1 ;;; rmail.el --- main code of "RMAIL" mail reader for Emacs.
4 ;; Last-Modified: 24 Apr 1992
6 ;; Copyright (C) 1985, 1986, 1987, 1988, 1991, 1992 Free Software Foundation, Inc.
8 ;; This file is part of GNU Emacs.
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)
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.
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.
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.
32 ; These variables now declared paths.el
33 ;(defvar rmail-spool-directory "/usr/spool/mail/"
34 ; "This is the name of the directory used by the system mailer for\n\
35 ;delivering new mail. It's name should end with a slash.")
36 ;(defvar rmail-file-name
37 ; (expand-file-name "~/RMAIL")
41 (defvar rmail-dont-reply-to-names nil
"\
42 *A regexp specifying names to prune of reply to messages.
43 nil means dont reply to yourself.")
46 (defvar rmail-default-dont-reply-to-names
"info-" "\
47 A regular expression specifying part of the value of the default value of
48 the variable `rmail-dont-reply-to-names', for when the user does not set
49 `rmail-dont-reply-to-names' explicitly. (The other part of the default
50 value is the user's name.)
51 It is useful to set this variable in the site customisation file.")
54 (defvar rmail-ignored-headers
"^via:\\|^mail-from:\\|^origin:\\|^status:\\|^received:\\|^message-id:\\|^summary-line:" "\
55 *Gubbish headers one would rather not see.")
58 (defvar rmail-delete-after-output nil
"\
59 *Non-nil means automatically delete a message that is copied to a file.")
62 (defconst rmail-primary-inbox-list nil
"\
63 *List of files which are inboxes for user's primary mail file ~/RMAIL.
64 `nil' means the default, which is (\"/usr/spool/mail/$USER\" \"~/mbox\")
65 \(the first name varies depending on the operating system,
66 and the value of the environment variable MAIL overrides it).")
68 ;; these may be altered by site-init.el to match the format of mmdf files
69 ;; delimitation used on a given host (delim1 and delim2 from the config
72 (defvar mmdf-delim1
"^\001\001\001\001\n"
73 "Regexp marking the start of an mmdf message")
74 (defvar mmdf-delim2
"^\001\001\001\001\n"
75 "Regexp marking the end of an mmdf message")
77 (defvar rmail-message-filter nil
78 "If non nil, is a filter function for new headers in RMAIL.
79 Called with region narrowed to unformatted header.")
81 (defvar rmail-mode-map nil
)
83 (defvar rmail-inbox-list nil
)
84 (defvar rmail-keywords nil
)
86 ;; Message counters and markers. Deleted flags.
88 (defvar rmail-current-message nil
)
89 (defvar rmail-total-messages nil
)
90 (defvar rmail-message-vector nil
)
91 (defvar rmail-deleted-vector nil
)
93 ;; These are used by autoloaded rmail-summary.
95 (defvar rmail-summary-buffer nil
)
96 (defvar rmail-summary-vector nil
)
98 ;; `Sticky' default variables.
100 ;; Last individual label specified to a or k.
101 (defvar rmail-last-label nil
)
102 ;; Last set of labels specified to C-M-n or C-M-p or C-M-l.
103 (defvar rmail-last-multi-labels nil
)
104 (defvar rmail-last-file nil
)
105 (defvar rmail-last-rmail-file nil
)
107 ;;; Regexp matching the delimiter of messages in UNIX mail format
108 ;;; (UNIX From lines), minus the initial ^. Note that if you change
109 ;;; this expression, you must change the code in rmail-nuke-pinhead-header
110 ;;; that knows the exact ordering of the \\( \\) subexpressions.
111 (defvar rmail-unix-mail-delimiter
112 "From \\([^ \n]*\\(\\|\".*\"[^ \n]*\\)\\) ?\\([^ \n]*\\) \\([^ ]*\\) *\\([0-9]*\\) \\([0-9:]*\\)\\( ?[A-Z]?[A-Z][A-Z]T\\( DST\\)?\\| ?[-+]?[0-9][0-9][0-9][0-9]\\|\\) [0-9][0-9]\\([0-9]*\\) *\\(remote from [^\n]*\\)?\n" nil
)
114 ;;;; *** Rmail Mode ***
117 (defun rmail (&optional file-name-arg
)
118 "Read and edit incoming mail.
119 Moves messages into file named by rmail-file-name (a babyl format file)
120 and edits that file in RMAIL Mode.
121 Type \\[describe-mode] once editing that file, for a list of RMAIL commands.
123 May be called with filename as argument; then performs rmail editing on
124 that file, but does not copy any new mail into the file."
125 (interactive (if current-prefix-arg
126 (list (read-file-name "Run rmail on RMAIL file: "
129 (setq rmail-last-file
(expand-file-name "~/xmail")))
130 (or rmail-last-rmail-file
131 (setq rmail-last-rmail-file
(expand-file-name "~/XMAIL")))
132 (let* ((file-name (expand-file-name (or file-name-arg rmail-file-name
)))
133 (existed (get-file-buffer file-name
)))
134 ;; Like find-file, but in the case where a buffer existed
135 ;; and the file was reverted, recompute the message-data.
136 (if (and existed
(not (verify-visited-file-modtime existed
)))
138 ;; Don't be confused by apparent local-variables spec
139 ;; in the last message in the RMAIL file.
140 (let ((inhibit-local-variables t
))
141 (find-file file-name
))
142 (if (verify-visited-file-modtime existed
)
143 (progn (rmail-forget-messages)
144 (rmail-set-message-counters))))
145 (let ((inhibit-local-variables t
))
146 (find-file file-name
)))
147 (if (and existed
(> (buffer-size) 0))
148 ;; Buffer not new and not empty; ensure in proper mode, but that's all.
149 (or (eq major-mode
'rmail-mode
)
152 ;; Provide default set of inboxes for primary mail file ~/RMAIL.
153 (and (null rmail-inbox-list
)
155 (setq rmail-inbox-list
156 (or rmail-primary-inbox-list
159 (concat rmail-spool-directory
160 (user-original-login-name)))))))
161 ;; Convert all or part to Babyl file if possible.
163 (goto-char (point-max))
164 (if (null rmail-inbox-list
)
166 (rmail-set-message-counters)
167 (rmail-show-message))))
169 ;; Show the first unseen message, which might be from a previous session
170 ;; or might have been just read in by rmail-get-new-mail.
171 (rmail-first-unseen-message)))
173 ;; Given the value of MAILPATH, return a list of inbox file names.
174 ;; This is turned off because it is not clear that the user wants
175 ;; all these inboxes to feed into the primary rmail file.
176 ; (defun rmail-convert-mailpath (string)
178 ; (while (setq idx (string-match "[%:]" string))
179 ; (let ((this (substring string 0 idx)))
180 ; (setq string (substring string (1+ idx)))
181 ; (setq list (cons (if (string-match "%" this)
182 ; (substring this 0 (string-match "%" this))
187 ; I have checked that adding "-*- rmail -*-" to the BABYL OPTIONS line
188 ; will not cause emacs 18.55 problems.
190 (defun rmail-convert-file ()
193 (goto-char (point-min))
194 ;; If file doesn't start like a Babyl file,
195 ;; convert it to one, by adding a header and converting each message.
196 (cond ((looking-at "BABYL OPTIONS:"))
197 ((looking-at "Version: 5\n")
198 ;; Losing babyl file made by old version of Rmail.
199 ;; Just fix the babyl file header; don't make a new one,
200 ;; so we don't lose the Labels: file attribute, etc.
201 (let ((buffer-read-only nil
))
202 (insert "BABYL OPTIONS: -*- rmail -*-\n")))
205 (rmail-insert-rmail-file-header)))
206 ;; If file was not a Babyl file or if there are
207 ;; Unix format messages added at the end,
208 ;; convert file as necessary.
210 (progn (goto-char (point-max))
211 (search-backward "\^_")
213 (looking-at "\n*From ")))
214 (let ((buffer-read-only nil
))
215 (message "Converting to Babyl format...")
216 (narrow-to-region (point) (point-max))
217 (rmail-convert-to-babyl-format)
218 (message "Converting to Babyl format...done")))))
220 ; I have checked that adding "-*- rmail -*-" to the BABYL OPTIONS line
221 ; will not cause emacs 18.55 problems.
223 (defun rmail-insert-rmail-file-header ()
224 (let ((buffer-read-only nil
))
225 (insert "BABYL OPTIONS: -*- rmail -*-
228 Note: This is the header of an rmail file.
229 Note: If you are seeing it in rmail,
230 Note: it means the file has no messages in it.\n\^_")))
234 (setq rmail-mode-map
(make-keymap))
235 (suppress-keymap rmail-mode-map
)
236 (define-key rmail-mode-map
"." 'rmail-beginning-of-message
)
237 (define-key rmail-mode-map
" " 'scroll-up
)
238 (define-key rmail-mode-map
"\177" 'scroll-down
)
239 (define-key rmail-mode-map
"n" 'rmail-next-undeleted-message
)
240 (define-key rmail-mode-map
"p" 'rmail-previous-undeleted-message
)
241 (define-key rmail-mode-map
"\en" 'rmail-next-message
)
242 (define-key rmail-mode-map
"\ep" 'rmail-previous-message
)
243 (define-key rmail-mode-map
"\e\C-n" 'rmail-next-labeled-message
)
244 (define-key rmail-mode-map
"\e\C-p" 'rmail-previous-labeled-message
)
245 (define-key rmail-mode-map
"a" 'rmail-add-label
)
246 (define-key rmail-mode-map
"k" 'rmail-kill-label
)
247 (define-key rmail-mode-map
"d" 'rmail-delete-forward
)
248 (define-key rmail-mode-map
"u" 'rmail-undelete-previous-message
)
249 (define-key rmail-mode-map
"x" 'rmail-expunge
)
250 (define-key rmail-mode-map
"s" 'rmail-expunge-and-save
)
251 (define-key rmail-mode-map
"g" 'rmail-get-new-mail
)
252 (define-key rmail-mode-map
"h" 'rmail-summary
)
253 (define-key rmail-mode-map
"\e\C-h" 'rmail-summary
)
254 (define-key rmail-mode-map
"l" 'rmail-summary-by-labels
)
255 (define-key rmail-mode-map
"\e\C-l" 'rmail-summary-by-labels
)
256 (define-key rmail-mode-map
"\e\C-r" 'rmail-summary-by-recipients
)
257 (define-key rmail-mode-map
"\e\C-s" 'rmail-summary-by-regexp
)
258 (define-key rmail-mode-map
"t" 'rmail-toggle-header
)
259 (define-key rmail-mode-map
"m" 'rmail-mail
)
260 (define-key rmail-mode-map
"r" 'rmail-reply
)
261 (define-key rmail-mode-map
"\e\C-m" 'rmail-retry-failure
)
262 (define-key rmail-mode-map
"c" 'rmail-continue
)
263 (define-key rmail-mode-map
"f" 'rmail-forward
)
264 (define-key rmail-mode-map
"\es" 'rmail-search
)
265 (define-key rmail-mode-map
"<" 'rmail-first-message
)
266 (define-key rmail-mode-map
">" 'rmail-last-message
)
267 (define-key rmail-mode-map
"j" 'rmail-show-message
)
268 (define-key rmail-mode-map
"o" 'rmail-output-to-rmail-file
)
269 (define-key rmail-mode-map
"\C-o" 'rmail-output
)
270 (define-key rmail-mode-map
"i" 'rmail-input
)
271 (define-key rmail-mode-map
"q" 'rmail-quit
)
272 (define-key rmail-mode-map
"?" 'describe-mode
)
273 (define-key rmail-mode-map
"w" 'rmail-edit-current-message
)
274 (define-key rmail-mode-map
"e" 'rmail-edit-current-message
)
275 (define-key rmail-mode-map
"\C-d" 'rmail-delete-backward
))
277 ;; Rmail mode is suitable only for specially formatted data.
278 (put 'rmail-mode
'mode-class
'special
)
281 "Rmail Mode is used by \\<rmail-mode-map>\\[rmail] for editing Rmail files.
282 All normal editing commands are turned off.
283 Instead, these commands are available:
285 \\[rmail-beginning-of-message] Move point to front of this message (same as \\[beginning-of-buffer]).
286 \\[scroll-up] Scroll to next screen of this message.
287 \\[scroll-down] Scroll to previous screen of this message.
288 \\[rmail-next-undeleted-message] Move to Next non-deleted message.
289 \\[rmail-previous-undeleted-message] Move to Previous non-deleted message.
290 \\[rmail-next-message] Move to Next message whether deleted or not.
291 \\[rmail-previous-message] Move to Previous message whether deleted or not.
292 \\[rmail-first-message] Move to the first message in Rmail file.
293 \\[rmail-last-message] Move to the last message in Rmail file.
294 \\[rmail-show-message] Jump to message specified by numeric position in file.
295 \\[rmail-search] Search for string and show message it is found in.
296 \\[rmail-delete-forward] Delete this message, move to next nondeleted.
297 \\[rmail-delete-backward] Delete this message, move to previous nondeleted.
298 \\[rmail-undelete-previous-message] Undelete message. Tries current message, then earlier messages
299 till a deleted message is found.
300 \\[rmail-expunge] Expunge deleted messages.
301 \\[rmail-expunge-and-save] Expunge and save the file.
302 \\[rmail-quit] Quit Rmail: expunge, save, then switch to another buffer.
303 \\[save-buffer] Save without expunging.
304 \\[rmail-get-new-mail] Move new mail from system spool directory or mbox into this file.
305 \\[rmail-mail] Mail a message (same as \\[mail-other-window]).
306 \\[rmail-continue] Continue composing outgoing message started before.
307 \\[rmail-reply] Reply to this message. Like m but initializes some fields.
308 \\[rmail-retry-failure] Send this message again. Used on a mailer failure message.
309 \\[rmail-forward] Forward this message to another user.
310 \\[rmail-output-to-rmail-file] Output this message to an Rmail file (append it).
311 \\[rmail-output] Output this message to a Unix-format mail file (append it).
312 \\[rmail-input] Input Rmail file. Run Rmail on that file.
313 \\[rmail-add-label] Add label to message. It will be displayed in the mode line.
314 \\[rmail-kill-label] Kill label. Remove a label from current message.
315 \\[rmail-next-labeled-message] Move to Next message with specified label
316 (label defaults to last one specified).
317 Standard labels: filed, unseen, answered, forwarded, deleted.
318 Any other label is present only if you add it with `a'.
319 \\[rmail-previous-labeled-message] Move to Previous message with specified label
320 \\[rmail-summary] Show headers buffer, with a one line summary of each message.
321 \\[rmail-summary-by-labels] Like h only just messages with particular label(s) are summarized.
322 \\[rmail-summary-by-recipients] Like h only just messages with particular recipient(s) are summarized.
323 \\[rmail-toggle-header] Toggle header, show Rmail header if unformatted or vice versa.
324 \\[rmail-edit-current-message] Edit the current message. \\[rmail-cease-edit] to return to Rmail."
327 (rmail-set-message-counters)
328 (rmail-show-message))
330 (defun rmail-mode-2 ()
331 (kill-all-local-variables)
334 (run-hooks 'rmail-mode-hook
))
336 (defun rmail-mode-1 ()
337 (setq major-mode
'rmail-mode
)
338 (setq mode-name
"RMAIL")
339 (setq buffer-read-only t
)
340 ;; No need to auto save RMAIL files.
341 (setq buffer-auto-save-file-name nil
)
342 (if (boundp 'mode-line-modified
)
343 (setq mode-line-modified
"--- ")
344 (setq mode-line-format
345 (cons "--- " (cdr (default-value 'mode-line-format
)))))
346 (use-local-map rmail-mode-map
)
347 (set-syntax-table text-mode-syntax-table
)
348 (setq local-abbrev-table text-mode-abbrev-table
))
350 (defun rmail-variables ()
351 (make-local-variable 'revert-buffer-function
)
352 (setq revert-buffer-function
'rmail-revert
)
353 (make-local-variable 'rmail-last-label
)
354 (make-local-variable 'rmail-deleted-vector
)
355 (make-local-variable 'rmail-summary-buffer
)
356 (make-local-variable 'rmail-summary-vector
)
357 (make-local-variable 'rmail-current-message
)
358 (make-local-variable 'rmail-total-messages
)
359 (make-local-variable 'require-final-newline
)
360 (setq require-final-newline nil
)
361 (make-local-variable 'version-control
)
362 (setq version-control
'never
)
363 (make-local-variable 'file-precious-flag
)
364 (setq file-precious-flag t
)
365 (make-local-variable 'rmail-message-vector
)
366 (make-local-variable 'rmail-last-file
)
367 (make-local-variable 'rmail-inbox-list
)
368 (setq rmail-inbox-list
(rmail-parse-file-inboxes))
369 (make-local-variable 'rmail-keywords
)
370 ;; this gets generated as needed
371 (setq rmail-keywords nil
))
373 ;; Handle M-x revert-buffer done in an rmail-mode buffer.
374 (defun rmail-revert (arg noconfirm
)
375 (let (revert-buffer-function)
376 ;; Call our caller again, but this time it does the default thing.
377 (if (revert-buffer arg noconfirm
)
378 ;; If the user said "yes", and we changed something,
379 ;; reparse the messages.
382 (goto-char (point-max))
383 (rmail-set-message-counters)
384 (rmail-show-message)))))
386 ;; Return a list of files from this buffer's Mail: option.
387 ;; Does not assume that messages have been parsed.
388 ;; Just returns nil if buffer does not look like Babyl format.
389 (defun rmail-parse-file-inboxes ()
394 (cond ((looking-at "BABYL OPTIONS:")
395 (search-forward "\n\^_" nil
'move
)
396 (narrow-to-region 1 (point))
398 (if (search-forward "\nMail:" nil t
)
400 (narrow-to-region (point) (progn (end-of-line) (point)))
401 (goto-char (point-min))
402 (mail-parse-comma-list))))))))
404 (defun rmail-expunge-and-save ()
405 "Expunge and save RMAIL file."
413 (rmail-expunge-and-save)
414 ;; Don't switch to the summary buffer even if it was recently visible.
415 (if rmail-summary-buffer
416 (bury-buffer rmail-summary-buffer
))
417 (let ((obuf (current-buffer)))
418 (switch-to-buffer (other-buffer))
422 (defun rmail-input (filename)
423 "Run RMAIL on file FILENAME."
424 (interactive "FRun rmail on RMAIL file: ")
428 ;;;; *** Rmail input ***
430 ;; RLK feature not added in this version:
431 ;; argument specifies inbox file or files in various ways.
433 (defun rmail-get-new-mail (&optional file-name
)
434 "Move any new mail from this RMAIL file's inbox files.
435 The inbox files can be specified with the file's Mail: option. The
436 variable `rmail-primary-inbox-list' specifies the inboxes for your
437 primary RMAIL file if it has no Mail: option. These are normally your
438 ~/mbox and your /usr/spool/mail/$USER.
440 You can also specify the file to get new mail from. In this case, the
441 file of new mail is not changed or deleted. Noninteractively, you can
442 pass the inbox file name as an argument. Interactively, a prefix
443 argument causes us to read a file name and use that file as the inbox."
445 (list (if current-prefix-arg
446 (read-file-name "Get new mail from file: "))))
447 (or (verify-visited-file-modtime (current-buffer))
449 (find-file (buffer-file-name))
450 (if (verify-visited-file-modtime (current-buffer))
451 (rmail-forget-messages))))
452 (rmail-maybe-set-message-counters)
454 ;; Get rid of all undo records for this buffer.
455 (or (eq buffer-undo-list t
)
456 (setq buffer-undo-list nil
))
458 (let ((opoint (point))
461 ;; If buffer has not changed yet, and has not been saved yet,
462 ;; don't replace the old backup file now.
463 (make-backup-files (and make-backup-files
(buffer-modified-p)))
464 (buffer-read-only nil
)
465 ;; Don't make undo records for what we do in getting mail.
466 (buffer-undo-list t
))
467 (goto-char (point-max))
468 (skip-chars-backward " \t\n") ; just in case of brain damage
469 (delete-region (point) (point-max)) ; caused by require-final-newline
472 (narrow-to-region (point) (point))
473 ;; Read in the contents of the inbox files,
474 ;; renaming them as necessary,
475 ;; and adding to the list of files to delete eventually.
477 (rmail-insert-inbox-text (list file-name
) nil
)
478 (setq delete-files
(rmail-insert-inbox-text rmail-inbox-list t
)))
479 ;; Scan the new text and convert each message to babyl format.
480 (goto-char (point-min))
482 (setq new-messages
(rmail-convert-to-babyl-format)))
483 (or (zerop new-messages
)
486 (search-backward "\n\^_")
487 (narrow-to-region (point) (point-max))
488 (goto-char (1+ (point-min)))
489 (rmail-count-new-messages)
491 ;; Delete the old files, now that babyl file is saved.
494 (delete-file (car delete-files
))
496 (setq delete-files
(cdr delete-files
)))))
497 (if (= new-messages
0)
498 (progn (goto-char opoint
)
499 (if (or file-name rmail-inbox-list
)
500 (message "(No new mail has arrived)")))
501 (message "%d new message%s read"
502 new-messages
(if (= 1 new-messages
) "" "s"))
503 (and (boundp 'display-time-string
)
504 (string-match " Mail" display-time-string
)
505 (setq display-time-string
507 (substring display-time-string
0 (match-beginning 0))
508 (substring display-time-string
(match-end 0))))
509 (force-mode-line-update 'all
))))
510 ;; Don't leave the buffer screwed up if we get a disk-full error.
511 (rmail-show-message)))
513 (defun rmail-insert-inbox-text (files renamep
)
514 (let (file tofile delete-files movemail
)
516 (setq file
(expand-file-name (substitute-in-file-name (car files
)))
517 ;;>> un*x specific <<
518 ;; The "+" used to be "~", which is an extremely poor choice;
519 ;; it might accidentally be deleted when space is low
520 ;; (as happened to me!).
521 tofile
(concat file
"+"))
522 ;; If getting from mail spool directory,
523 ;; use movemail to move rather than just renaming,
524 ;; so as to interlock with the mailer.
525 (setq movemail
(equal (file-name-directory file
) rmail-spool-directory
))
528 (setq tofile
(expand-file-name
529 ;; Generate name to move to from inbox name,
530 ;; in case of multiple inboxes that need moving.
531 (concat ".newmail-" (file-name-nondirectory file
))
533 (expand-file-name rmail-file-name
))))
534 ;; On some systems, /usr/spool/mail/foo is a directory
535 ;; and the actual inbox is /usr/spool/mail/foo/foo.
536 (if (file-directory-p file
)
537 (setq file
(expand-file-name (user-original-login-name)
539 (if (or (file-exists-p tofile
) (file-exists-p file
))
540 (message "Getting mail from %s..." file
))
541 ;; Set TOFILE if have not already done so, and
542 ;; rename or copy the file FILE to TOFILE if and as appropriate.
545 ((or (file-exists-p tofile
) (not (file-exists-p file
)))
548 (rename-file file tofile nil
))
553 (setq errors
(generate-new-buffer " *rmail loss*"))
554 (buffer-disable-undo errors
)
556 (expand-file-name "movemail" exec-directory
)
557 nil errors nil file tofile
)
558 (if (not (buffer-modified-p errors
))
559 ;; No output => movemail won
562 (subst-char-in-region (point-min) (point-max)
564 (goto-char (point-max))
565 (skip-chars-backward " \t")
566 (delete-region (point) (point-max))
567 (goto-char (point-min))
568 (if (looking-at "movemail: ")
569 (delete-region (point-min) (match-end 0)))
571 (message (concat "movemail: "
572 (buffer-substring (point-min)
576 (if errors
(kill-buffer errors
))))))
577 ;; At this point, TOFILE contains the name to read:
578 ;; Either the alternate name (if we renamed)
579 ;; or the actual inbox (if not renaming).
580 (if (file-exists-p tofile
)
582 (goto-char (point-max))
583 (setq size
(nth 1 (insert-file-contents tofile
)))
584 (goto-char (point-max))
585 (or (= (preceding-char) ?
\n)
588 (setq delete-files
(cons tofile delete-files
))))
590 (setq files
(cdr files
)))
593 ;; the rmail-break-forwarded-messages feature is not implemented
594 (defun rmail-convert-to-babyl-format ()
595 (let ((count 0) start
596 (case-fold-search nil
)
597 (invalid-input-resync
599 (message "Invalid Babyl format in inbox!")
601 ;; Try to get back in sync with a real message.
602 (if (re-search-forward
603 (concat mmdf-delim1
"\\|^From") nil t
)
605 (goto-char (point-max)))))))
606 (goto-char (point-min))
609 (cond ((looking-at "BABYL OPTIONS:");Babyl header
610 (if (search-forward "\n\^_" nil t
)
611 ;; If we find the proper terminator, delete through there.
612 (delete-region (point-min) (point))
613 (funcall invalid-input-resync
)
614 (delete-region (point-min) (point))))
615 ;; Babyl format message
617 (or (search-forward "\n\^_" nil t
)
618 (funcall invalid-input-resync
))
619 (setq count
(1+ count
))
620 ;; Make sure there is no extra white space after the ^_
621 ;; at the end of the message.
622 ;; Narrowing will make sure that whatever follows the junk
623 ;; will be treated properly.
624 (delete-region (point)
626 (skip-chars-forward " \t\n")
628 (narrow-to-region (point) (point-max)))
630 ((let ((case-fold-search t
))
631 (looking-at mmdf-delim1
))
632 (let ((case-fold-search t
))
633 (replace-match "\^L\n0, unseen,,\n*** EOOH ***\n")
635 (re-search-forward mmdf-delim2 nil t
)
636 (replace-match "\^_"))
639 (narrow-to-region start
(1- (point)))
640 (goto-char (point-min))
641 (while (search-forward "\n\^_" nil t
); single char "\^_"
642 (replace-match "\n^_")))); 2 chars: "^" and "_"
643 (narrow-to-region (point) (point-max))
644 (setq count
(1+ count
)))
646 ((looking-at "^From ")
648 (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
649 (rmail-nuke-pinhead-header)
650 (if (re-search-forward
652 rmail-unix-mail-delimiter
656 "\^L\n[01],\\)") nil t
)
657 (goto-char (match-beginning 1))
658 (goto-char (point-max)))
659 (setq count
(1+ count
))
662 (narrow-to-region start
(point))
663 (goto-char (point-min))
664 (while (search-forward "\n\^_" nil t
); single char
665 (replace-match "\n^_")))); 2 chars: "^" and "_"
667 (narrow-to-region (point) (point-max)))
669 ;;This is a kludge, in case we're wrong about mmdf not
670 ;;allowing anything in between. If it loses, we'll have
671 ;;to look for something else
672 (t (error "Cannot convert to babyl format")))))
675 ;; Delete the "From ..." line, creating various other headers with
676 ;; information from it if they don't already exist. Now puts the
677 ;; original line into a mail-from: header line for debugging.
678 (defun rmail-nuke-pinhead-header ()
681 (let ((start (point))
684 (search-forward "\n\n")
686 (goto-char (point-max))
690 (narrow-to-region start end
)
691 (let ((case-fold-search t
))
693 (setq has-from
(search-forward "\nFrom:" nil t
))
695 (setq has-date
(and (search-forward "\nDate:" nil t
) (point)))
697 (let ((case-fold-search nil
))
698 (if (re-search-forward (concat "^" rmail-unix-mail-delimiter
) nil t
)
702 ;; Keep and reformat the date if we don't
703 ;; have a Date: field.
706 ;; If no time zone specified, assume est.
707 (if (= (match-beginning 7) (match-end 7))
708 "Date: \\3, \\5 \\4 \\9 \\6 EST\n"
709 "Date: \\3, \\5 \\4 \\9 \\6\\7\n"))
710 ;; Keep and reformat the sender if we don't
711 ;; have a From: field.
714 "From: \\1\n")))))))))
716 ;;;; *** Rmail Message Formatting and Header Manipulation ***
718 (defun rmail-reformat-message (beg end
)
721 (if (/= (following-char) ?
0)
722 (error "Bad format in RMAIL file."))
723 (let ((buffer-read-only nil
)
724 (delta (- (buffer-size) end
)))
728 (if (looking-at "Summary-line: ")
730 (if (looking-at "\\*\\*\\* EOOH \\*\\*\\*\n")
731 (delete-region (point)
732 (progn (forward-line 1) (point))))
733 (let ((str (buffer-substring (point)
734 (save-excursion (search-forward "\n\n" end
'move
)
736 (insert str
"*** EOOH ***\n")
737 (narrow-to-region (point) (- (buffer-size) delta
)))
738 (goto-char (point-min))
739 (if rmail-ignored-headers
(rmail-clear-headers))
740 (if rmail-message-filter
(funcall rmail-message-filter
))))
742 (defun rmail-clear-headers ()
743 (if (search-forward "\n\n" nil t
)
745 (narrow-to-region (point-min) (point))
746 (let ((buffer-read-only nil
))
747 (while (let ((case-fold-search t
))
748 (goto-char (point-min))
749 (re-search-forward rmail-ignored-headers nil t
))
751 (delete-region (point)
752 (progn (re-search-forward "\n[^ \t]")
756 (defun rmail-toggle-header ()
757 "Show original message header if pruned header currently shown, or vice versa."
759 (rmail-maybe-set-message-counters)
760 (narrow-to-region (rmail-msgbeg rmail-current-message
) (point-max))
761 (let ((buffer-read-only nil
))
762 (goto-char (point-min))
764 (if (= (following-char) ?
1)
765 (progn (delete-char 1)
768 (if (looking-at "Summary-Line:")
770 (insert "*** EOOH ***\n")
772 (search-forward "\n*** EOOH ***\n")
774 (let ((temp (point)))
775 (and (search-forward "\n\n" nil t
)
776 (delete-region temp
(point))))
777 (goto-char (point-min))
778 (search-forward "\n*** EOOH ***\n")
779 (narrow-to-region (point) (point-max)))
780 (rmail-reformat-message (point-min) (point-max)))))
782 ;;;; *** Rmail Attributes and Keywords ***
784 ;; Make a string describing current message's attributes and keywords
785 ;; and set it up as the name of a minor mode
786 ;; so it will appear in the mode line.
787 (defun rmail-display-labels ()
788 (let ((blurb "") (beg (point-min-marker)) (end (point-max-marker)))
793 (goto-char (rmail-msgbeg rmail-current-message
))
795 (if (looking-at "[01],")
797 (narrow-to-region (point) (progn (end-of-line) (point)))
798 ;; Truly valid BABYL format requires a space before each
799 ;; attribute or keyword name. Put them in if missing.
800 (let (buffer-read-only)
801 (goto-char (point-min))
802 (while (search-forward "," nil t
)
803 (or (looking-at "[ ,]") (eobp)
805 (goto-char (point-max))
806 (if (search-backward ",," nil
'move
)
808 (if (> (point) (1+ (point-min)))
809 (setq blurb
(buffer-substring (+ 1 (point-min)) (point))))
810 (if (> (- (point-max) (point)) 2)
814 (buffer-substring (+ (point) 3)
815 (1- (point-max)))))))))))
816 ;; Note: we don't use save-restriction because that does not work right
817 ;; if changes are made outside the saved restriction
818 ;; before that restriction is restored.
819 (narrow-to-region beg end
)
821 (set-marker end nil
)))
822 (while (string-match " +," blurb
)
823 (setq blurb
(concat (substring blurb
0 (match-beginning 0)) ","
824 (substring blurb
(match-end 0)))))
825 (while (string-match ", +" blurb
)
826 (setq blurb
(concat (substring blurb
0 (match-beginning 0)) ","
827 (substring blurb
(match-end 0)))))
828 (setq mode-line-process
829 (concat " " rmail-current-message
"/" rmail-total-messages
832 ;; Turn an attribute of a message on or off according to STATE.
833 ;; ATTR is the name of the attribute, as a string.
834 ;; MSGNUM is message number to change; nil means current message.
835 (defun rmail-set-attribute (attr state
&optional msgnum
)
836 (let ((omax (point-max-marker))
837 (omin (point-min-marker))
838 (buffer-read-only nil
))
839 (or msgnum
(setq msgnum rmail-current-message
))
843 (goto-char (+ 3 (rmail-msgbeg msgnum
)))
846 (null (search-backward (concat ", " attr
",")
847 (prog1 (point) (end-of-line)) t
)))))
848 (or (eq curstate
(not (not state
)))
850 (delete-region (point) (1- (match-end 0)))
853 (insert " " attr
","))))
854 (if (string= attr
"deleted")
855 (rmail-set-message-deleted-p msgnum state
)))
856 ;; Note: we don't use save-restriction because that does not work right
857 ;; if changes are made outside the saved restriction
858 ;; before that restriction is restored.
859 (narrow-to-region omin omax
)
860 (set-marker omin nil
)
861 (set-marker omax nil
)
862 (if (= msgnum rmail-current-message
)
863 (rmail-display-labels)))))
865 ;; Return t if the attributes/keywords line of msg number MSG
866 ;; contains a match for the regexp LABELS.
867 (defun rmail-message-labels-p (msg labels
)
871 (goto-char (rmail-msgbeg msg
))
873 (re-search-backward labels
(prog1 (point) (end-of-line)) t
))))
875 ;;;; *** Rmail Message Selection And Support ***
877 (defun rmail-msgend (n)
878 (marker-position (aref rmail-message-vector
(1+ n
))))
880 (defun rmail-msgbeg (n)
881 (marker-position (aref rmail-message-vector n
)))
883 (defun rmail-widen-to-current-msgbeg (function)
884 "Call FUNCTION with point at start of internal data of current message.
885 Assumes that bounds were previously narrowed to display the message in Rmail.
886 The bounds are widened enough to move point where desired, then narrowed
889 FUNCTION may not change the visible text of the message, but it may
890 change the invisible header text."
892 (let ((obeg (- (point-max) (point-min))))
895 (narrow-to-region (rmail-msgbeg rmail-current-message
)
897 (goto-char (point-min))
899 ;; Note: we don't use save-restriction because that does not work right
900 ;; if changes are made outside the saved restriction
901 ;; before that restriction is restored.
902 ;; Here we assume that changes made by FUNCTION
903 ;; occur before the visible region of the message.
904 (narrow-to-region (- (point-max) obeg
) (point-max))))))
906 (defun rmail-forget-messages ()
908 (if (vectorp rmail-message-vector
)
910 (v rmail-message-vector
)
913 (move-marker (aref v i
) nil
)
915 (setq rmail-message-vector nil
)
916 (setq rmail-deleted-vector nil
)))
918 (defun rmail-maybe-set-message-counters ()
919 (if (not (and rmail-deleted-vector
921 rmail-current-message
922 rmail-total-messages
))
923 (rmail-set-message-counters)))
925 (defun rmail-count-new-messages (&optional nomsg
)
926 (let* ((case-fold-search nil
)
930 (or nomsg
(message "Counting new messages..."))
931 (goto-char (point-max))
932 ;; Put at the end of messages-head
933 ;; the entry for message N+1, which marks
934 ;; the end of message N. (N = number of messages).
935 (search-backward "\n\^_")
937 (setq messages-head
(list (point-marker)))
938 (rmail-set-message-counters-counter (point-min))
939 (setq rmail-current-message
(1+ rmail-total-messages
))
940 (setq rmail-total-messages
941 (+ rmail-total-messages total-messages
))
942 (setq rmail-message-vector
943 (vconcat rmail-message-vector
(cdr messages-head
)))
944 (aset rmail-message-vector
945 rmail-current-message
(car messages-head
))
946 (setq rmail-deleted-vector
947 (concat rmail-deleted-vector deleted-head
))
948 (setq rmail-summary-vector
949 (vconcat rmail-summary-vector
(make-vector total-messages nil
)))
950 (goto-char (point-min))
951 (or nomsg
(message "Counting new messages...done (%d)" total-messages
))))
953 (defun rmail-set-message-counters ()
954 (rmail-forget-messages)
958 (let* ((point-save (point))
960 (messages-after-point)
961 (case-fold-search nil
)
964 (message "Counting messages...")
965 (goto-char (point-max))
966 ;; Put at the end of messages-head
967 ;; the entry for message N+1, which marks
968 ;; the end of message N. (N = number of messages).
969 (search-backward "\n\^_")
971 (setq messages-head
(list (point-marker)))
972 (rmail-set-message-counters-counter (min (point) point-save
))
973 (setq messages-after-point total-messages
)
974 (rmail-set-message-counters-counter)
975 (setq rmail-total-messages total-messages
)
976 (setq rmail-current-message
978 (max 1 (- total-messages messages-after-point
))))
979 (setq rmail-message-vector
980 (apply 'vector
(cons (point-min-marker) messages-head
))
981 rmail-deleted-vector
(concat "D" deleted-head
)
982 rmail-summary-vector
(make-vector rmail-total-messages nil
))
983 (message "Counting messages...done")))))
985 (defun rmail-set-message-counters-counter (&optional stop
)
986 (while (search-backward "\n\^_\^L\n" stop t
)
988 (setq messages-head
(cons (point-marker) messages-head
))
991 (cons (if (search-backward ", deleted,"
997 (if (zerop (%
(setq total-messages
(1+ total-messages
)) 20))
998 (message "Counting messages...%d" total-messages
))))
1000 (defun rmail-beginning-of-message ()
1001 "Show current message starting from the beginning."
1003 (rmail-show-message rmail-current-message
))
1005 (defun rmail-show-message (&optional n
)
1006 "Show message number N (prefix argument), counting from start of file."
1008 (rmail-maybe-set-message-counters)
1010 (if (zerop rmail-total-messages
)
1011 (progn (narrow-to-region (point-min) (1- (point-max)))
1012 (goto-char (point-min))
1013 (setq mode-line-process nil
))
1016 (setq n rmail-current-message
)
1019 rmail-current-message
1
1020 blurb
"No previous message"))
1021 ((> n rmail-total-messages
)
1022 (setq n rmail-total-messages
1023 rmail-current-message rmail-total-messages
1024 blurb
"No following message"))
1026 (setq rmail-current-message n
))))
1027 (let ((beg (rmail-msgbeg n
))
1028 (end (rmail-msgend n
)))
1031 (if (= (following-char) ?
0)
1033 (rmail-reformat-message beg end
)
1034 (rmail-set-attribute "unseen" nil
))
1035 (search-forward "\n*** EOOH ***\n" end t
)
1036 (narrow-to-region (point) end
))
1037 (goto-char (point-min))
1038 (rmail-display-labels)
1039 (run-hooks 'rmail-show-message-hook
)
1041 (message blurb
))))))
1043 (defun rmail-next-message (n)
1044 "Show following message whether deleted or not.
1045 With prefix arg N, moves forward N messages, or backward if N is negative."
1047 (rmail-maybe-set-message-counters)
1048 (rmail-show-message (+ rmail-current-message n
)))
1050 (defun rmail-previous-message (n)
1051 "Show previous message whether deleted or not.
1052 With prefix arg N, moves backward N messages, or forward if N is negative."
1054 (rmail-next-message (- n
)))
1056 (defun rmail-next-undeleted-message (n)
1057 "Show following non-deleted message.
1058 With prefix arg N, moves forward N non-deleted messages,
1059 or backward if N is negative."
1061 (rmail-maybe-set-message-counters)
1062 (let ((lastwin rmail-current-message
)
1063 (current rmail-current-message
))
1064 (while (and (> n
0) (< current rmail-total-messages
))
1065 (setq current
(1+ current
))
1066 (if (not (rmail-message-deleted-p current
))
1067 (setq lastwin current n
(1- n
))))
1068 (while (and (< n
0) (> current
1))
1069 (setq current
(1- current
))
1070 (if (not (rmail-message-deleted-p current
))
1071 (setq lastwin current n
(1+ n
))))
1072 (if (/= lastwin rmail-current-message
)
1073 (rmail-show-message lastwin
))
1075 (error "No previous nondeleted message"))
1077 (error "No following nondeleted message"))))
1079 (defun rmail-previous-undeleted-message (n)
1080 "Show previous non-deleted message.
1081 With prefix argument N, moves backward N non-deleted messages,
1082 or forward if N is negative."
1084 (rmail-next-undeleted-message (- n
)))
1086 (defun rmail-first-message ()
1087 "Show first message in file."
1089 (rmail-maybe-set-message-counters)
1090 (rmail-show-message 1))
1092 (defun rmail-last-message ()
1093 "Show last message in file."
1095 (rmail-maybe-set-message-counters)
1096 (rmail-show-message rmail-total-messages
))
1098 (defun rmail-what-message ()
1099 (let ((where (point))
1101 (high rmail-total-messages
)
1102 (mid (/ rmail-total-messages
2)))
1103 (while (> (- high low
) 1)
1104 (if (>= where
(rmail-msgbeg mid
))
1107 (setq mid
(+ low
(/ (- high low
) 2))))
1108 (if (>= where
(rmail-msgbeg high
)) high low
)))
1110 (defvar rmail-search-last-regexp nil
)
1111 (defun rmail-search (regexp &optional reversep
)
1112 "Show message containing next match for REGEXP.
1113 Search in reverse (earlier messages) with non-nil second arg REVERSEP.
1114 Interactively, empty argument means use same regexp used last time,
1115 and reverse search is specified by a negative numeric arg."
1117 (let* ((reversep (< (prefix-numeric-value current-prefix-arg
) 0))
1119 (concat (if reversep
"Reverse " "") "Rmail search (regexp): "))
1121 (if rmail-search-last-regexp
1122 (setq prompt
(concat prompt
1124 rmail-search-last-regexp
1126 (setq regexp
(read-string prompt
))
1127 (cond ((not (equal regexp
""))
1128 (setq rmail-search-last-regexp regexp
))
1129 ((not rmail-search-last-regexp
)
1130 (error "No previous Rmail search string")))
1131 (list rmail-search-last-regexp reversep
)))
1132 (message "%sRmail search for %s..."
1133 (if reversep
"Reverse " "")
1135 (rmail-maybe-set-message-counters)
1136 (let ((omin (point-min))
1140 (msg rmail-current-message
))
1144 ;; Check messages one by one, advancing message number up or down
1145 ;; but searching forward through each message.
1147 (while (and (null win
) (> msg
1))
1148 (goto-char (rmail-msgbeg (setq msg
(1- msg
))))
1149 (setq win
(re-search-forward
1150 regexp
(rmail-msgend msg
) t
)))
1151 (while (and (null win
) (< msg rmail-total-messages
))
1152 (goto-char (rmail-msgbeg (setq msg
(1+ msg
))))
1153 (setq win
(re-search-forward regexp
(rmail-msgend msg
) t
)))))
1156 ;; If this is a reverse search and we found a message,
1157 ;; search backward thru this message to position point.
1160 (goto-char (rmail-msgend msg
))
1162 regexp
(rmail-msgbeg msg
) t
)))
1164 (rmail-show-message msg
)
1165 (message "%sRmail search for %s...done"
1166 (if reversep
"Reverse " "")
1170 (narrow-to-region omin omax
)
1172 (message "Search failed: %s" regexp
)))))
1174 ;; Show the first message which has the `unseen' attribute.
1175 (defun rmail-first-unseen-message ()
1180 (while (and (not found
) (< current rmail-total-messages
))
1181 (if (rmail-message-labels-p current
", ?\\(unseen\\),")
1182 (setq found current
))
1183 (setq current
(1+ current
))))
1185 (rmail-show-message found
))))
1187 ;;;; *** Rmail Message Deletion Commands ***
1189 (defun rmail-message-deleted-p (n)
1190 (= (aref rmail-deleted-vector n
) ?D
))
1192 (defun rmail-set-message-deleted-p (n state
)
1193 (aset rmail-deleted-vector n
(if state ?D ?\
)))
1195 (defun rmail-delete-message ()
1196 "Delete this message and stay on it."
1198 (rmail-set-attribute "deleted" t
))
1200 (defun rmail-undelete-previous-message ()
1201 "Back up to deleted message, select it, and undelete it."
1203 (let ((msg rmail-current-message
))
1204 (while (and (> msg
0)
1205 (not (rmail-message-deleted-p msg
)))
1206 (setq msg
(1- msg
)))
1208 (error "No previous deleted message")
1209 (if (/= msg rmail-current-message
)
1210 (rmail-show-message msg
))
1211 (rmail-set-attribute "deleted" nil
))))
1213 (defun rmail-delete-forward (&optional backward
)
1214 "Delete this message and move to next nondeleted one.
1215 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
1216 With prefix argument, delete and move backward. If there is no nondeleted
1217 message to move to in the preferred or specified direction, move in the
1220 (rmail-set-attribute "deleted" t
)
1222 (rmail-next-undeleted-message (if backward -
1 1))
1225 (rmail-previous-undeleted-message (if backward -
1 1))
1228 (defun rmail-delete-backward ()
1229 "Delete this message and move to previous nondeleted one.
1230 Deleted messages stay in the file until the \\[rmail-expunge] command is given."
1232 (rmail-delete-forward t
))
1234 (defun rmail-expunge ()
1235 "Actually erase all deleted messages in the file."
1237 (message "Expunging deleted messages...")
1238 ;; Discard all undo records for this buffer.
1239 (or (eq buffer-undo-list t
)
1240 (setq buffer-undo-list nil
))
1241 (rmail-maybe-set-message-counters)
1242 (let* ((omax (- (buffer-size) (point-max)))
1243 (omin (- (buffer-size) (point-min)))
1244 (opoint (if (and (> rmail-current-message
0)
1245 (= ?D
(aref rmail-deleted-vector rmail-current-message
)))
1246 0 (- (point) (point-min))))
1247 (messages-head (cons (aref rmail-message-vector
0) nil
))
1248 (messages-tail messages-head
)
1249 ;; Don't make any undo records for the expunging.
1250 (buffer-undo-list t
)
1255 (goto-char (point-min))
1258 (total rmail-total-messages
)
1259 (new-message-number rmail-current-message
)
1261 (buffer-read-only nil
)
1262 (messages rmail-message-vector
)
1263 (deleted rmail-deleted-vector
)
1264 (summary rmail-summary-vector
))
1265 (setq rmail-total-messages nil
1266 rmail-current-message nil
1267 rmail-message-vector nil
1268 rmail-deleted-vector nil
1269 rmail-summary-vector nil
)
1270 (while (<= number total
)
1271 (if (= (aref deleted number
) ?D
)
1274 (marker-position (aref messages number
))
1275 (marker-position (aref messages
(1+ number
))))
1276 (move-marker (aref messages number
) nil
)
1277 (if (> new-message-number counter
)
1278 (setq new-message-number
(1- new-message-number
))))
1279 (setq counter
(1+ counter
))
1281 (setcdr messages-tail
1282 (cons (aref messages number
) nil
)))
1284 (cons (if (= counter number
) (aref summary
(1- number
)))
1286 (if (zerop (%
(setq number
(1+ number
)) 20))
1287 (message "Expunging deleted messages...%d" number
)))
1289 (setcdr messages-tail
1290 (cons (aref messages number
) nil
)))
1291 (setq rmail-current-message new-message-number
1292 rmail-total-messages counter
1293 rmail-message-vector
(apply 'vector messages-head
)
1294 rmail-deleted-vector
(make-string (1+ counter
) ?\
)
1295 rmail-summary-vector
(vconcat (nreverse new-summary
))
1297 (message "Expunging deleted messages...done")
1299 (narrow-to-region (- (buffer-size) omin
) (- (buffer-size) omax
)))
1301 (if (zerop rmail-current-message
) 1 nil
))
1302 (forward-char opoint
))))
1304 ;;;; *** Rmail Mailing Commands ***
1306 (defun rmail-mail ()
1307 "Send mail in another window. While composing the message, use
1308 \\[mail-yank-original] to yank the original message into it."
1310 (mail-other-window nil nil nil nil nil
(current-buffer)))
1312 (defun rmail-continue ()
1313 "Continue composing outgoing message previously being composed."
1315 (mail-other-window t
))
1317 (defun rmail-reply (just-sender)
1318 "Reply to the current message.
1319 Normally include CC: to all other recipients of original message;
1320 prefix argument means ignore them. While composing the reply,
1321 use \\[mail-yank-original] to yank the original message into it."
1323 (let (from reply-to cc subject date to message-id resent-reply-to
)
1327 (goto-char (rmail-msgbeg rmail-current-message
))
1329 (if (= (following-char) ?
0)
1331 (progn (forward-line 2)
1333 (progn (search-forward "\n\n" (rmail-msgend rmail-current-message
)
1336 (narrow-to-region (point)
1337 (progn (search-forward "\n*** EOOH ***\n")
1338 (beginning-of-line) (point))))
1339 (setq resent-reply-to
(mail-fetch-field "resent-reply-to" t
)
1340 from
(mail-fetch-field "from")
1341 reply-to
(or resent-reply-to
1342 (mail-fetch-field "reply-to" nil t
)
1344 cc
(cond (just-sender nil
)
1345 (resent-reply-to (mail-fetch-field "resent-cc" t
))
1346 (t (mail-fetch-field "cc" nil t
)))
1347 subject
(or (and resent-reply-to
1348 (mail-fetch-field "resent-subject" t
))
1349 (mail-fetch-field "subject"))
1350 date
(cond (resent-reply-to
1351 (mail-fetch-field "resent-date" t
))
1352 ((mail-fetch-field "date")))
1353 to
(cond (resent-reply-to
1354 (mail-fetch-field "resent-to" t
))
1355 ((mail-fetch-field "to" nil t
))
1356 ;((mail-fetch-field "apparently-to")) ack gag barf
1358 message-id
(cond (resent-reply-to
1359 (mail-fetch-field "resent-message-id" t
))
1360 ((mail-fetch-field "message-id"))))))
1362 (string-match "\\`Re: " subject
)
1363 (setq subject
(substring subject
4)))
1364 (mail-other-window nil
1365 (mail-strip-quoted-names reply-to
)
1367 (rmail-make-in-reply-to-field from date message-id
)
1370 (let* ((cc-list (rmail-dont-reply-to
1371 (mail-strip-quoted-names
1372 (if (null cc
) to
(concat to
", " cc
))))))
1373 (if (string= cc-list
"") nil cc-list
)))
1375 (list (list '(lambda (buf msgnum
)
1378 (rmail-set-attribute "answered" t msgnum
)))
1379 (current-buffer) rmail-current-message
)))))
1381 (defun rmail-make-in-reply-to-field (from date message-id
)
1388 (let ((tem (car (rfc822-addresses from
))))
1391 (regexp-quote (if (string-match "@[^@]*\\'" tem
)
1392 (substring tem
0 (match-beginning 0))
1395 ;; Message-ID is sufficiently informative
1397 (concat message-id
" (" tem
")"))
1398 ;; Use prin1 to fake RFC822 quoting
1399 (let ((field (prin1-to-string tem
)))
1401 (concat field
"'s message of " date
)
1403 ((let* ((foo "[^][\000-\037\177-\377()<>@,;:\\\" ]+")
1404 (bar "[^][\000-\037\177-\377()<>@,;:\\\"]+"))
1405 ;; Can't use format because format loses on \000 (unix *^&%*^&%$!!)
1406 (or (string-match (concat "\\`[ \t]*\\(" bar
1407 "\\)\\(<" foo
"@" foo
">\\)?[ \t]*\\'")
1408 ;; "Unix Loser <Foo@bar.edu>" => "Unix Loser"
1410 (string-match (concat "\\`[ \t]*<" foo
"@" foo
">[ \t]*(\\("
1411 bar
"\\))[ \t]*\\'")
1412 ;; "<Bugs@bar.edu>" (Losing Unix) => "Losing Unix"
1414 (let ((start (match-beginning 1))
1415 (end (match-end 1)))
1416 ;; Trim whitespace which above regexp match allows
1417 (while (and (< start end
)
1418 (memq (aref from start
) '(?
\t ?\
)))
1419 (setq start
(1+ start
)))
1420 (while (and (< start end
)
1421 (memq (aref from
(1- end
)) '(?
\t ?\
)))
1422 (setq end
(1- end
)))
1423 (let ((field (substring from start end
)))
1424 (if date
(setq field
(concat "message from " field
" on " date
)))
1426 ;; "<AA259@bar.edu> (message from Unix Loser on 1-Apr-89)"
1427 (concat message-id
" (" field
")")
1430 ;; If we can't kludge it simply, do it correctly
1431 (let ((mail-use-rfc822 t
))
1432 (rmail-make-in-reply-to-field from date message-id
)))))
1434 (defun rmail-forward ()
1435 "Forward the current message to another user."
1437 (let ((forward-buffer (current-buffer))
1438 (subject (concat "["
1439 (mail-strip-quoted-names (mail-fetch-field "From"))
1440 ": " (or (mail-fetch-field "Subject") "") "]")))
1441 ;; If only one window, use it for the mail buffer.
1442 ;; Otherwise, use another window for the mail buffer
1443 ;; so that the Rmail buffer remains visible
1444 ;; and sending the mail will get back to it.
1445 (if (funcall (if (one-window-p t
)
1447 (function mail-other-window
))
1448 nil nil subject nil nil nil
1449 (list (list (function (lambda (buf msgnum
)
1452 (rmail-set-attribute "forwarded" t msgnum
))))
1454 rmail-current-message
)))
1456 (goto-char (point-max))
1458 (insert-buffer forward-buffer
)))))
1460 (defun rmail-resend (address &optional from comment mail-alias-file
)
1461 "Resend current message to ADDRESSES.
1462 ADDRESSES should be a single address, a a string consisting of several
1463 addresses separated by commas, or a list of addresses.
1465 Optional FROM is the address to resend the message from, and
1466 defaults to the username of the person redistributing the message.
1467 Optional COMMENT is a string that will be inserted as a comment in the
1469 Optional ALIAS-FILE is alternate aliases file to be used by sendmail,
1470 typically for purposes of moderating a list."
1471 (interactive "sResend to: ")
1472 (if (not from
) (setq from
(user-login-name)))
1473 (let ((tembuf (generate-new-buffer " sendmail temp"))
1474 (mail-header-separator "")
1475 (case-fold-search nil
)
1476 (mailbuf (current-buffer)))
1479 ;;>> Copy message into temp buffer
1481 (insert-buffer-substring mailbuf
)
1482 (goto-char (point-min))
1483 ;;>> Insert resent-from:
1484 (insert "Resent-From: " from
"\n")
1485 (insert "Resent-Date: " (current-time-string) "\n")
1486 ;;>> Insert resent-to: and bcc if need be.
1487 (let ((before (point)))
1488 (insert "Resent-To: " (if (stringp address
)
1490 (mapconcat 'identity address
",\n\t"))
1492 (expand-mail-aliases before
(point)))
1493 ;;>> Set up comment, if any.
1494 (if (and (sequencep comment
) (not (zerop (length comment
))))
1495 (let ((before (point))
1498 (or (eolp) (insert "\n"))
1499 (setq after
(point))
1501 (while (< (point) after
)
1502 (insert "Resent-Comment: ")
1504 ;; Don't expand aliases in the destination fields
1505 ;; of the original message.
1507 (sendmail-send-it)))
1508 (kill-buffer tembuf
))))
1510 (defvar mail-unsent-separator
"^ ----- Unsent message follows -----$")
1512 (defun rmail-retry-failure ()
1513 "Edit a mail message which is based on the contents of the current message.
1514 For a message rejected by the mail system, extract the interesting headers and
1515 the body of the original message; otherwise copy the current message."
1517 (require 'mail-utils
)
1518 (let (to subj irp2 cc orig-message
)
1520 ;; Narrow down to just the quoted original message
1521 (rmail-beginning-of-message)
1522 (or (re-search-forward mail-unsent-separator nil t
)
1523 (error "Cannot parse this as a failure message"))
1525 (narrow-to-region (point) (point-max))
1526 ;; Now mail-fetch-field will get from headers of the original message,
1527 ;; not from the headers of the rejection.
1528 (setq to
(mail-fetch-field "To")
1529 subj
(mail-fetch-field "Subject")
1530 irp2
(mail-fetch-field "In-reply-to")
1531 cc
(mail-fetch-field "Cc"))
1532 ;; Get the entire text (not headers) of the original message.
1535 (progn (search-forward "\n\n") (point))
1537 ;; Start sending a new message; default header fields from the original.
1538 (if (mail-other-window nil to subj irp2 cc
(current-buffer))
1539 ;; Insert original text as initial text of new draft message.
1541 (goto-char (point-max))
1542 (insert orig-message
)
1543 (goto-char (point-min))
1546 ;;;; *** Rmail Specify Inbox Files ***
1548 (autoload 'set-rmail-inbox-list
"rmailmsc"
1549 "Set the inbox list of the current RMAIL file to FILE-NAME.
1550 This may be a list of file names separated by commas.
1551 If FILE-NAME is empty, remove any inbox list."
1554 ;;;; *** Rmail Commands for Labels ***
1556 (autoload 'rmail-add-label
"rmailkwd"
1557 "Add LABEL to labels associated with current RMAIL message.
1558 Completion is performed over known labels when reading."
1561 (autoload 'rmail-kill-label
"rmailkwd"
1562 "Remove LABEL from labels associated with current RMAIL message.
1563 Completion is performed over known labels when reading."
1566 (autoload 'rmail-next-labeled-message
"rmailkwd"
1567 "Show next message with LABEL. Defaults to last label used.
1568 With prefix argument N moves forward N messages with this label."
1571 (autoload 'rmail-previous-labeled-message
"rmailkwd"
1572 "Show previous message with LABEL. Defaults to last label used.
1573 With prefix argument N moves backward N messages with this label."
1576 ;;;; *** Rmail Edit Mode ***
1578 (autoload 'rmail-edit-current-message
"rmailedit"
1579 "Edit the contents of the current message"
1582 ;;;; *** Rmail Summary Mode ***
1584 (autoload 'rmail-summary
"rmailsum"
1585 "Display a summary of all messages, one line per message."
1588 (autoload 'rmail-summary-by-labels
"rmailsum"
1589 "Display a summary of all messages with one or more LABELS.
1590 LABELS should be a string containing the desired labels, separated by commas."
1593 (autoload 'rmail-summary-by-recipients
"rmailsum"
1594 "Display a summary of all messages with the given RECIPIENTS.
1595 Normally checks the To, From and Cc fields of headers; but if PRIMARY-ONLY
1596 is non-nil (prefix arg given), only look in the To and From fields.
1597 RECIPIENTS is a string of names separated by commas."
1600 ;;;; *** Rmail output messages to files ***
1602 (autoload 'rmail-output-to-rmail-file
"rmailout"
1603 "Append the current message to an Rmail file named FILE-NAME.
1604 If the file does not exist, ask if it should be created.
1605 If file is being visited, the message is appended to the Emacs
1606 buffer visiting that file."
1609 (autoload 'rmail-output
"rmailout"
1610 "Append this message to Unix mail file named FILE-NAME."
1613 ;;;; *** Rmail undigestification ***
1615 (autoload 'undigestify-rmail-message
"undigest"
1616 "Break up a digest message into its constituent messages.
1617 Leaves original message, deleted, before the undigestified messages."
1622 ;;; rmail.el ends here