1 ;; "RMAIL" mail reader for Emacs.
2 ;; Copyright (C) 1985, 1986, 1987, 1988, 1991 Free Software Foundation, Inc.
4 ;; This file is part of GNU Emacs.
6 ;; GNU Emacs is free software; you can redistribute it and/or modify
7 ;; it under the terms of the GNU General Public License as published by
8 ;; the Free Software Foundation; either version 1, or (at your option)
11 ;; GNU Emacs is distributed in the hope that it will be useful,
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;; GNU General Public License for more details.
16 ;; You should have received a copy of the GNU General Public License
17 ;; along with GNU Emacs; see the file COPYING. If not, write to
18 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21 ;; Souped up by shane@mit-ajax based on ideas of rlk@athena.mit.edu
22 ;; New features include attribute and keyword support, message
23 ;; selection by dispatch table, summary by attributes and keywords,
24 ;; expunging by dispatch table, sticky options for file commands.
27 ; These variables now declared paths.el
28 ;(defvar rmail-spool-directory "/usr/spool/mail/"
29 ; "This is the name of the directory used by the system mailer for\n\
30 ;delivering new mail. It's name should end with a slash.")
31 ;(defvar rmail-file-name
32 ; (expand-file-name "~/RMAIL")
36 (defvar rmail-dont-reply-to-names nil
"\
37 *A regexp specifying names to prune of reply to messages.
38 nil means dont reply to yourself.")
41 (defvar rmail-default-dont-reply-to-names
"info-" "\
42 A regular expression specifying part of the value of the default value of
43 the variable `rmail-dont-reply-to-names', for when the user does not set
44 `rmail-dont-reply-to-names' explicitly. (The other part of the default
45 value is the user's name.)
46 It is useful to set this variable in the site customisation file.")
49 (defvar rmail-ignored-headers
"^via:\\|^mail-from:\\|^origin:\\|^status:\\|^received:\\|^message-id:\\|^summary-line:" "\
50 *Gubbish headers one would rather not see.")
53 (defvar rmail-delete-after-output nil
"\
54 *Non-nil means automatically delete a message that is copied to a file.")
57 (defconst rmail-primary-inbox-list nil
"\
58 *List of files which are inboxes for user's primary mail file ~/RMAIL.
59 `nil' means the default, which is (\"/usr/spool/mail/$USER\" \"~/mbox\")
60 \(the first name varies depending on the operating system,
61 and the value of the environment variable MAIL overrides it).")
63 ;; these may be altered by site-init.el to match the format of mmdf files
64 ;; delimitation used on a given host (delim1 and delim2 from the config
67 (defvar mmdf-delim1
"^\001\001\001\001\n"
68 "Regexp marking the start of an mmdf message")
69 (defvar mmdf-delim2
"^\001\001\001\001\n"
70 "Regexp marking the end of an mmdf message")
72 (defvar rmail-message-filter nil
73 "If non nil, is a filter function for new headers in RMAIL.
74 Called with region narrowed to unformatted header.")
76 (defvar rmail-mode-map nil
)
78 (defvar rmail-inbox-list nil
)
79 (defvar rmail-keywords nil
)
81 ;; Message counters and markers. Deleted flags.
83 (defvar rmail-current-message nil
)
84 (defvar rmail-total-messages nil
)
85 (defvar rmail-message-vector nil
)
86 (defvar rmail-deleted-vector nil
)
88 ;; These are used by autoloaded rmail-summary.
90 (defvar rmail-summary-buffer nil
)
91 (defvar rmail-summary-vector nil
)
93 ;; `Sticky' default variables.
95 ;; Last individual label specified to a or k.
96 (defvar rmail-last-label nil
)
97 ;; Last set of labels specified to C-M-n or C-M-p or C-M-l.
98 (defvar rmail-last-multi-labels nil
)
99 (defvar rmail-last-file nil
)
100 (defvar rmail-last-rmail-file nil
)
102 ;;;; *** Rmail Mode ***
105 (defun rmail (&optional file-name-arg
)
106 "Read and edit incoming mail.
107 Moves messages into file named by rmail-file-name (a babyl format file)
108 and edits that file in RMAIL Mode.
109 Type \\[describe-mode] once editing that file, for a list of RMAIL commands.
111 May be called with filename as argument; then performs rmail editing on
112 that file, but does not copy any new mail into the file."
113 (interactive (if current-prefix-arg
114 (list (read-file-name "Run rmail on RMAIL file: "
117 (setq rmail-last-file
(expand-file-name "~/xmail")))
118 (or rmail-last-rmail-file
119 (setq rmail-last-rmail-file
(expand-file-name "~/XMAIL")))
120 (let* ((file-name (expand-file-name (or file-name-arg rmail-file-name
)))
121 (existed (get-file-buffer file-name
)))
122 ;; Like find-file, but in the case where a buffer existed
123 ;; and the file was reverted, recompute the message-data.
124 (if (and existed
(not (verify-visited-file-modtime existed
)))
126 ;; Don't be confused by apparent local-variables spec
127 ;; in the last message in the RMAIL file.
128 (let ((inhibit-local-variables t
))
129 (find-file file-name
))
130 (if (verify-visited-file-modtime existed
)
131 (progn (rmail-forget-messages)
132 (rmail-set-message-counters))))
133 (let ((inhibit-local-variables t
))
134 (find-file file-name
)))
135 (if (and existed
(> (buffer-size) 0))
136 ;; Buffer not new and not empty; ensure in proper mode, but that's all.
137 (or (eq major-mode
'rmail-mode
)
140 ;; Provide default set of inboxes for primary mail file ~/RMAIL.
141 (and (null rmail-inbox-list
)
143 (setq rmail-inbox-list
144 (or rmail-primary-inbox-list
147 (concat rmail-spool-directory
148 (user-original-login-name)))))))
149 ;; Convert all or part to Babyl file if possible.
151 (goto-char (point-max))
152 (if (null rmail-inbox-list
)
154 (rmail-set-message-counters)
155 (rmail-show-message))))
157 ;; Show the first unseen message, which might be from a previous session
158 ;; or might have been just read in by rmail-get-new-mail.
159 (rmail-first-unseen-message)))
161 ;; Given the value of MAILPATH, return a list of inbox file names.
162 ;; This is turned off because it is not clear that the user wants
163 ;; all these inboxes to feed into the primary rmail file.
164 ; (defun rmail-convert-mailpath (string)
166 ; (while (setq idx (string-match "[%:]" string))
167 ; (let ((this (substring string 0 idx)))
168 ; (setq string (substring string (1+ idx)))
169 ; (setq list (cons (if (string-match "%" this)
170 ; (substring this 0 (string-match "%" this))
175 ; I have checked that adding "-*- rmail -*-" to the BABYL OPTIONS line
176 ; will not cause emacs 18.55 problems.
178 (defun rmail-convert-file ()
181 (goto-char (point-min))
182 ;; If file doesn't start like a Babyl file,
183 ;; convert it to one, by adding a header and converting each message.
184 (cond ((looking-at "BABYL OPTIONS:"))
185 ((looking-at "Version: 5\n")
186 ;; Losing babyl file made by old version of Rmail.
187 ;; Just fix the babyl file header; don't make a new one,
188 ;; so we don't lose the Labels: file attribute, etc.
189 (let ((buffer-read-only nil
))
190 (insert "BABYL OPTIONS: -*- rmail -*-\n")))
193 (rmail-insert-rmail-file-header)))
194 ;; If file was not a Babyl file or if there are
195 ;; Unix format messages added at the end,
196 ;; convert file as necessary.
198 (progn (goto-char (point-max))
199 (search-backward "\^_")
201 (looking-at "\n*From ")))
202 (let ((buffer-read-only nil
))
203 (message "Converting to Babyl format...")
204 (narrow-to-region (point) (point-max))
205 (rmail-convert-to-babyl-format)
206 (message "Converting to Babyl format...done")))))
208 ; I have checked that adding "-*- rmail -*-" to the BABYL OPTIONS line
209 ; will not cause emacs 18.55 problems.
211 (defun rmail-insert-rmail-file-header ()
212 (let ((buffer-read-only nil
))
213 (insert "BABYL OPTIONS: -*- rmail -*-
216 Note: This is the header of an rmail file.
217 Note: If you are seeing it in rmail,
218 Note: it means the file has no messages in it.\n\^_")))
222 (setq rmail-mode-map
(make-keymap))
223 (suppress-keymap rmail-mode-map
)
224 (define-key rmail-mode-map
"." 'rmail-beginning-of-message
)
225 (define-key rmail-mode-map
" " 'scroll-up
)
226 (define-key rmail-mode-map
"\177" 'scroll-down
)
227 (define-key rmail-mode-map
"n" 'rmail-next-undeleted-message
)
228 (define-key rmail-mode-map
"p" 'rmail-previous-undeleted-message
)
229 (define-key rmail-mode-map
"\en" 'rmail-next-message
)
230 (define-key rmail-mode-map
"\ep" 'rmail-previous-message
)
231 (define-key rmail-mode-map
"\e\C-n" 'rmail-next-labeled-message
)
232 (define-key rmail-mode-map
"\e\C-p" 'rmail-previous-labeled-message
)
233 (define-key rmail-mode-map
"a" 'rmail-add-label
)
234 (define-key rmail-mode-map
"k" 'rmail-kill-label
)
235 (define-key rmail-mode-map
"d" 'rmail-delete-forward
)
236 (define-key rmail-mode-map
"u" 'rmail-undelete-previous-message
)
237 (define-key rmail-mode-map
"x" 'rmail-expunge
)
238 (define-key rmail-mode-map
"s" 'rmail-expunge-and-save
)
239 (define-key rmail-mode-map
"g" 'rmail-get-new-mail
)
240 (define-key rmail-mode-map
"h" 'rmail-summary
)
241 (define-key rmail-mode-map
"\e\C-h" 'rmail-summary
)
242 (define-key rmail-mode-map
"l" 'rmail-summary-by-labels
)
243 (define-key rmail-mode-map
"\e\C-l" 'rmail-summary-by-labels
)
244 (define-key rmail-mode-map
"\e\C-r" 'rmail-summary-by-recipients
)
245 (define-key rmail-mode-map
"\e\C-s" 'rmail-summary-by-regexp
)
246 (define-key rmail-mode-map
"t" 'rmail-toggle-header
)
247 (define-key rmail-mode-map
"m" 'rmail-mail
)
248 (define-key rmail-mode-map
"r" 'rmail-reply
)
249 (define-key rmail-mode-map
"\e\C-m" 'rmail-retry-failure
)
250 (define-key rmail-mode-map
"c" 'rmail-continue
)
251 (define-key rmail-mode-map
"f" 'rmail-forward
)
252 (define-key rmail-mode-map
"\es" 'rmail-search
)
253 (define-key rmail-mode-map
"<" 'rmail-first-message
)
254 (define-key rmail-mode-map
">" 'rmail-last-message
)
255 (define-key rmail-mode-map
"j" 'rmail-show-message
)
256 (define-key rmail-mode-map
"o" 'rmail-output-to-rmail-file
)
257 (define-key rmail-mode-map
"\C-o" 'rmail-output
)
258 (define-key rmail-mode-map
"i" 'rmail-input
)
259 (define-key rmail-mode-map
"q" 'rmail-quit
)
260 (define-key rmail-mode-map
"?" 'describe-mode
)
261 (define-key rmail-mode-map
"w" 'rmail-edit-current-message
)
262 (define-key rmail-mode-map
"e" 'rmail-edit-current-message
)
263 (define-key rmail-mode-map
"\C-d" 'rmail-delete-backward
))
265 ;; Rmail mode is suitable only for specially formatted data.
266 (put 'rmail-mode
'mode-class
'special
)
269 "Rmail Mode is used by \\<rmail-mode-map>\\[rmail] for editing Rmail files.
270 All normal editing commands are turned off.
271 Instead, these commands are available:
273 \\[rmail-beginning-of-message] Move point to front of this message (same as \\[beginning-of-buffer]).
274 \\[scroll-up] Scroll to next screen of this message.
275 \\[scroll-down] Scroll to previous screen of this message.
276 \\[rmail-next-undeleted-message] Move to Next non-deleted message.
277 \\[rmail-previous-undeleted-message] Move to Previous non-deleted message.
278 \\[rmail-next-message] Move to Next message whether deleted or not.
279 \\[rmail-previous-message] Move to Previous message whether deleted or not.
280 \\[rmail-first-message] Move to the first message in Rmail file.
281 \\[rmail-last-message] Move to the last message in Rmail file.
282 \\[rmail-show-message] Jump to message specified by numeric position in file.
283 \\[rmail-search] Search for string and show message it is found in.
284 \\[rmail-delete-forward] Delete this message, move to next nondeleted.
285 \\[rmail-delete-backward] Delete this message, move to previous nondeleted.
286 \\[rmail-undelete-previous-message] Undelete message. Tries current message, then earlier messages
287 till a deleted message is found.
288 \\[rmail-expunge] Expunge deleted messages.
289 \\[rmail-expunge-and-save] Expunge and save the file.
290 \\[rmail-quit] Quit Rmail: expunge, save, then switch to another buffer.
291 \\[save-buffer] Save without expunging.
292 \\[rmail-get-new-mail] Move new mail from system spool directory or mbox into this file.
293 \\[rmail-mail] Mail a message (same as \\[mail-other-window]).
294 \\[rmail-continue] Continue composing outgoing message started before.
295 \\[rmail-reply] Reply to this message. Like m but initializes some fields.
296 \\[rmail-retry-failure] Send this message again. Used on a mailer failure message.
297 \\[rmail-forward] Forward this message to another user.
298 \\[rmail-output-to-rmail-file] Output this message to an Rmail file (append it).
299 \\[rmail-output] Output this message to a Unix-format mail file (append it).
300 \\[rmail-input] Input Rmail file. Run Rmail on that file.
301 \\[rmail-add-label] Add label to message. It will be displayed in the mode line.
302 \\[rmail-kill-label] Kill label. Remove a label from current message.
303 \\[rmail-next-labeled-message] Move to Next message with specified label
304 (label defaults to last one specified).
305 Standard labels: filed, unseen, answered, forwarded, deleted.
306 Any other label is present only if you add it with `a'.
307 \\[rmail-previous-labeled-message] Move to Previous message with specified label
308 \\[rmail-summary] Show headers buffer, with a one line summary of each message.
309 \\[rmail-summary-by-labels] Like h only just messages with particular label(s) are summarized.
310 \\[rmail-summary-by-recipients] Like h only just messages with particular recipient(s) are summarized.
311 \\[rmail-toggle-header] Toggle header, show Rmail header if unformatted or vice versa.
312 \\[rmail-edit-current-message] Edit the current message. \\[rmail-cease-edit] to return to Rmail."
315 (rmail-set-message-counters)
316 (rmail-show-message))
318 (defun rmail-mode-2 ()
319 (kill-all-local-variables)
322 (run-hooks 'rmail-mode-hook
))
324 (defun rmail-mode-1 ()
325 (setq major-mode
'rmail-mode
)
326 (setq mode-name
"RMAIL")
327 (setq buffer-read-only t
)
328 ;; No need to auto save RMAIL files.
329 (setq buffer-auto-save-file-name nil
)
330 (if (boundp 'mode-line-modified
)
331 (setq mode-line-modified
"--- ")
332 (setq mode-line-format
333 (cons "--- " (cdr (default-value 'mode-line-format
)))))
334 (use-local-map rmail-mode-map
)
335 (set-syntax-table text-mode-syntax-table
)
336 (setq local-abbrev-table text-mode-abbrev-table
))
338 (defun rmail-variables ()
339 (make-local-variable 'revert-buffer-function
)
340 (setq revert-buffer-function
'rmail-revert
)
341 (make-local-variable 'rmail-last-label
)
342 (make-local-variable 'rmail-deleted-vector
)
343 (make-local-variable 'rmail-summary-buffer
)
344 (make-local-variable 'rmail-summary-vector
)
345 (make-local-variable 'rmail-current-message
)
346 (make-local-variable 'rmail-total-messages
)
347 (make-local-variable 'require-final-newline
)
348 (setq require-final-newline nil
)
349 (make-local-variable 'version-control
)
350 (setq version-control
'never
)
351 (make-local-variable 'file-precious-flag
)
352 (setq file-precious-flag t
)
353 (make-local-variable 'rmail-message-vector
)
354 (make-local-variable 'rmail-last-file
)
355 (make-local-variable 'rmail-inbox-list
)
356 (setq rmail-inbox-list
(rmail-parse-file-inboxes))
357 (make-local-variable 'rmail-keywords
)
358 ;; this gets generated as needed
359 (setq rmail-keywords nil
))
361 ;; Handle M-x revert-buffer done in an rmail-mode buffer.
362 (defun rmail-revert (arg noconfirm
)
363 (let (revert-buffer-function)
364 ;; Call our caller again, but this time it does the default thing.
365 (if (revert-buffer arg noconfirm
)
366 ;; If the user said "yes", and we changed something,
367 ;; reparse the messages.
370 (goto-char (point-max))
371 (rmail-set-message-counters)
372 (rmail-show-message)))))
374 ;; Return a list of files from this buffer's Mail: option.
375 ;; Does not assume that messages have been parsed.
376 ;; Just returns nil if buffer does not look like Babyl format.
377 (defun rmail-parse-file-inboxes ()
382 (cond ((looking-at "BABYL OPTIONS:")
383 (search-forward "\n\^_" nil
'move
)
384 (narrow-to-region 1 (point))
386 (if (search-forward "\nMail:" nil t
)
388 (narrow-to-region (point) (progn (end-of-line) (point)))
389 (goto-char (point-min))
390 (mail-parse-comma-list))))))))
392 (defun rmail-expunge-and-save ()
393 "Expunge and save RMAIL file."
401 (rmail-expunge-and-save)
402 ;; Don't switch to the summary buffer even if it was recently visible.
403 (if rmail-summary-buffer
404 (bury-buffer rmail-summary-buffer
))
405 (let ((obuf (current-buffer)))
406 (switch-to-buffer (other-buffer))
410 (defun rmail-input (filename)
411 "Run RMAIL on file FILENAME."
412 (interactive "FRun rmail on RMAIL file: ")
416 ;;;; *** Rmail input ***
418 ;; RLK feature not added in this version:
419 ;; argument specifies inbox file or files in various ways.
421 (defun rmail-get-new-mail (&optional file-name
)
422 "Move any new mail from this RMAIL file's inbox files.
423 The inbox files can be specified with the file's Mail: option. The
424 variable `rmail-primary-inbox-list' specifies the inboxes for your
425 primary RMAIL file if it has no Mail: option. These are normally your
426 ~/mbox and your /usr/spool/mail/$USER.
428 You can also specify the file to get new mail from. In this case, the
429 file of new mail is not changed or deleted. Noninteractively, you can
430 pass the inbox file name as an argument. Interactively, a prefix
431 argument causes us to read a file name and use that file as the inbox."
433 (list (if current-prefix-arg
434 (read-file-name "Get new mail from file: "))))
435 (or (verify-visited-file-modtime (current-buffer))
437 (find-file (buffer-file-name))
438 (if (verify-visited-file-modtime (current-buffer))
439 (rmail-forget-messages))))
440 (rmail-maybe-set-message-counters)
442 ;; Get rid of all undo records for this buffer.
443 (or (eq buffer-undo-list t
)
444 (setq buffer-undo-list nil
))
446 (let ((opoint (point))
449 ;; If buffer has not changed yet, and has not been saved yet,
450 ;; don't replace the old backup file now.
451 (make-backup-files (and make-backup-files
(buffer-modified-p)))
452 (buffer-read-only nil
)
453 ;; Don't make undo records for what we do in getting mail.
454 (buffer-undo-list t
))
455 (goto-char (point-max))
456 (skip-chars-backward " \t\n") ; just in case of brain damage
457 (delete-region (point) (point-max)) ; caused by require-final-newline
460 (narrow-to-region (point) (point))
461 ;; Read in the contents of the inbox files,
462 ;; renaming them as necessary,
463 ;; and adding to the list of files to delete eventually.
465 (rmail-insert-inbox-text (list file-name
) nil
)
466 (setq delete-files
(rmail-insert-inbox-text rmail-inbox-list t
)))
467 ;; Scan the new text and convert each message to babyl format.
468 (goto-char (point-min))
470 (setq new-messages
(rmail-convert-to-babyl-format)))
471 (or (zerop new-messages
)
474 (search-backward "\n\^_")
475 (narrow-to-region (point) (point-max))
476 (goto-char (1+ (point-min)))
477 (rmail-count-new-messages)
479 ;; Delete the old files, now that babyl file is saved.
482 (delete-file (car delete-files
))
484 (setq delete-files
(cdr delete-files
)))))
485 (if (= new-messages
0)
486 (progn (goto-char opoint
)
487 (if (or file-name rmail-inbox-list
)
488 (message "(No new mail has arrived)")))
489 (message "%d new message%s read"
490 new-messages
(if (= 1 new-messages
) "" "s"))
491 (and (boundp 'display-time-string
)
492 (string-match " Mail" display-time-string
)
493 (setq display-time-string
495 (substring display-time-string
0 (match-beginning 0))
496 (substring display-time-string
(match-end 0))))
497 (force-mode-line-update 'all
))))
498 ;; Don't leave the buffer screwed up if we get a disk-full error.
499 (rmail-show-message)))
501 (defun rmail-insert-inbox-text (files renamep
)
502 (let (file tofile delete-files movemail
)
504 (setq file
(expand-file-name (substitute-in-file-name (car files
)))
505 ;;>> un*x specific <<
506 tofile
(concat file
"~"))
507 ;; If getting from mail spool directory,
508 ;; use movemail to move rather than just renaming,
509 ;; so as to interlock with the mailer.
510 (setq movemail
(equal (file-name-directory file
) rmail-spool-directory
))
513 (setq tofile
(expand-file-name
514 ;; Generate name to move to from inbox name,
515 ;; in case of multiple inboxes that need moving.
516 (concat ".newmail-" (file-name-nondirectory file
))
518 (expand-file-name rmail-file-name
))))
519 ;; On some systems, /usr/spool/mail/foo is a directory
520 ;; and the actual inbox is /usr/spool/mail/foo/foo.
521 (if (file-directory-p file
)
522 (setq file
(expand-file-name (user-original-login-name)
524 (if (or (file-exists-p tofile
) (file-exists-p file
))
525 (message "Getting mail from %s..." file
))
526 ;; Set TOFILE if have not already done so, and
527 ;; rename or copy the file FILE to TOFILE if and as appropriate.
530 ((or (file-exists-p tofile
) (not (file-exists-p file
)))
533 (rename-file file tofile nil
))
538 (setq errors
(generate-new-buffer " *rmail loss*"))
539 (buffer-disable-undo errors
)
541 (expand-file-name "movemail" exec-directory
)
542 nil errors nil file tofile
)
543 (if (not (buffer-modified-p errors
))
544 ;; No output => movemail won
547 (subst-char-in-region (point-min) (point-max)
549 (goto-char (point-max))
550 (skip-chars-backward " \t")
551 (delete-region (point) (point-max))
552 (goto-char (point-min))
553 (if (looking-at "movemail: ")
554 (delete-region (point-min) (match-end 0)))
556 (message (concat "movemail: "
557 (buffer-substring (point-min)
561 (if errors
(kill-buffer errors
))))))
562 ;; At this point, TOFILE contains the name to read:
563 ;; Either the alternate name (if we renamed)
564 ;; or the actual inbox (if not renaming).
565 (if (file-exists-p tofile
)
567 (goto-char (point-max))
568 (setq size
(nth 1 (insert-file-contents tofile
)))
569 (goto-char (point-max))
570 (or (= (preceding-char) ?
\n)
573 (setq delete-files
(cons tofile delete-files
))))
575 (setq files
(cdr files
)))
578 ;; the rmail-break-forwarded-messages feature is not implemented
579 (defun rmail-convert-to-babyl-format ()
580 (let ((count 0) start
581 (case-fold-search nil
)
582 (invalid-input-resync
584 (message "Invalid Babyl format in inbox!")
586 ;; Try to get back in sync with a real message.
587 (if (re-search-forward
588 (concat mmdf-delim1
"\\|^From") nil t
)
590 (goto-char (point-max)))))))
591 (goto-char (point-min))
594 (cond ((looking-at "BABYL OPTIONS:");Babyl header
595 (if (search-forward "\n\^_" nil t
)
596 ;; If we find the proper terminator, delete through there.
597 (delete-region (point-min) (point))
598 (funcall invalid-input-resync
)
599 (delete-region (point-min) (point))))
600 ;; Babyl format message
602 (or (search-forward "\n\^_" nil t
)
603 (funcall invalid-input-resync
))
604 (setq count
(1+ count
))
605 ;; Make sure there is no extra white space after the ^_
606 ;; at the end of the message.
607 ;; Narrowing will make sure that whatever follows the junk
608 ;; will be treated properly.
609 (delete-region (point)
611 (skip-chars-forward " \t\n")
613 (narrow-to-region (point) (point-max)))
615 ((let ((case-fold-search t
))
616 (looking-at mmdf-delim1
))
617 (let ((case-fold-search t
))
618 (replace-match "\^L\n0, unseen,,\n*** EOOH ***\n")
620 (re-search-forward mmdf-delim2 nil t
)
621 (replace-match "\^_"))
624 (narrow-to-region start
(1- (point)))
625 (goto-char (point-min))
626 (while (search-forward "\n\^_" nil t
); single char "\^_"
627 (replace-match "\n^_")))); 2 chars: "^" and "_"
628 (narrow-to-region (point) (point-max))
629 (setq count
(1+ count
)))
631 ((looking-at "^From ")
633 (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
634 (rmail-nuke-pinhead-header)
635 (if (re-search-forward
637 "From [^ \n]*\\(\\|\".*\"[^ \n]*\\) ?[^ \n]* [^ \n]* *"
638 "[0-9]* [0-9:]*\\( ?[A-Z]?[A-Z][A-Z]T\\| ?[-+]?[0-9][0-9][0-9][0-9]\\|\\) " ; EDT, -0500
639 "[0-9]+ *\\(remote from [^\n]*\\)?$\\|"
642 "\^L\n[01],\\)") nil t
)
643 (goto-char (match-beginning 1))
644 (goto-char (point-max)))
645 (setq count
(1+ count
))
648 (narrow-to-region start
(point))
649 (goto-char (point-min))
650 (while (search-forward "\n\^_" nil t
); single char
651 (replace-match "\n^_")))); 2 chars: "^" and "_"
653 (narrow-to-region (point) (point-max)))
655 ;;This is a kludge, in case we're wrong about mmdf not
656 ;;allowing anything in between. If it loses, we'll have
657 ;;to look for something else
658 (t (error "Cannot convert to babyl format")))))
661 ;; Delete the "From ..." line, creating various other headers with
662 ;; information from it if they don't already exist. Now puts the
663 ;; original line into a mail-from: header line for debugging.
664 (defun rmail-nuke-pinhead-header ()
667 (let ((start (point))
670 (search-forward "\n\n")
672 (goto-char (point-max))
676 (narrow-to-region start end
)
677 (let ((case-fold-search t
))
679 (setq has-from
(search-forward "\nFrom:" nil t
))
681 (setq has-date
(and (search-forward "\nDate:" nil t
) (point)))
683 (let ((case-fold-search nil
))
684 (if (re-search-forward
685 "^From \\([^ ]*\\(\\|\".*\"[^ ]*\\)\\) ?\\([^ ]*\\) \\([^ ]*\\) *\\([0-9]*\\) \\([0-9:]*\\)\\( ?[A-Z]?[A-Z][A-Z]T\\| ?[-+]?[0-9][0-9][0-9][0-9]\\|\\) [0-9][0-9]\\([0-9]*\\) *\\(remote from [^\n]*\\)?\n" nil t
)
689 ;; Keep and reformat the date if we don't
690 ;; have a Date: field.
693 ;; If no time zone specified, assume est.
694 (if (= (match-beginning 7) (match-end 7))
695 "Date: \\3, \\5 \\4 \\8 \\6 EST\n"
696 "Date: \\3, \\5 \\4 \\8 \\6\\7\n"))
697 ;; Keep and reformat the sender if we don't
698 ;; have a From: field.
701 "From: \\1\n")))))))))
703 ;;;; *** Rmail Message Formatting and Header Manipulation ***
705 (defun rmail-reformat-message (beg end
)
708 (if (/= (following-char) ?
0)
709 (error "Bad format in RMAIL file."))
710 (let ((buffer-read-only nil
)
711 (delta (- (buffer-size) end
)))
715 (if (looking-at "Summary-line: ")
717 (if (looking-at "\\*\\*\\* EOOH \\*\\*\\*\n")
718 (delete-region (point)
719 (progn (forward-line 1) (point))))
720 (let ((str (buffer-substring (point)
721 (save-excursion (search-forward "\n\n" end
'move
)
723 (insert str
"*** EOOH ***\n")
724 (narrow-to-region (point) (- (buffer-size) delta
)))
725 (goto-char (point-min))
726 (if rmail-ignored-headers
(rmail-clear-headers))
727 (if rmail-message-filter
(funcall rmail-message-filter
))))
729 (defun rmail-clear-headers ()
730 (if (search-forward "\n\n" nil t
)
732 (narrow-to-region (point-min) (point))
733 (let ((buffer-read-only nil
))
734 (while (let ((case-fold-search t
))
735 (goto-char (point-min))
736 (re-search-forward rmail-ignored-headers nil t
))
738 (delete-region (point)
739 (progn (re-search-forward "\n[^ \t]")
743 (defun rmail-toggle-header ()
744 "Show original message header if pruned header currently shown, or vice versa."
746 (rmail-maybe-set-message-counters)
747 (narrow-to-region (rmail-msgbeg rmail-current-message
) (point-max))
748 (let ((buffer-read-only nil
))
749 (goto-char (point-min))
751 (if (= (following-char) ?
1)
752 (progn (delete-char 1)
755 (if (looking-at "Summary-Line:")
757 (insert "*** EOOH ***\n")
759 (search-forward "\n*** EOOH ***\n")
761 (let ((temp (point)))
762 (and (search-forward "\n\n" nil t
)
763 (delete-region temp
(point))))
764 (goto-char (point-min))
765 (search-forward "\n*** EOOH ***\n")
766 (narrow-to-region (point) (point-max)))
767 (rmail-reformat-message (point-min) (point-max)))))
769 ;;;; *** Rmail Attributes and Keywords ***
771 ;; Make a string describing current message's attributes and keywords
772 ;; and set it up as the name of a minor mode
773 ;; so it will appear in the mode line.
774 (defun rmail-display-labels ()
775 (let ((blurb "") (beg (point-min-marker)) (end (point-max-marker)))
780 (goto-char (rmail-msgbeg rmail-current-message
))
782 (if (looking-at "[01],")
784 (narrow-to-region (point) (progn (end-of-line) (point)))
785 ;; Truly valid BABYL format requires a space before each
786 ;; attribute or keyword name. Put them in if missing.
787 (let (buffer-read-only)
788 (goto-char (point-min))
789 (while (search-forward "," nil t
)
790 (or (looking-at "[ ,]") (eobp)
792 (goto-char (point-max))
793 (if (search-backward ",," nil
'move
)
795 (if (> (point) (1+ (point-min)))
796 (setq blurb
(buffer-substring (+ 1 (point-min)) (point))))
797 (if (> (- (point-max) (point)) 2)
801 (buffer-substring (+ (point) 3)
802 (1- (point-max)))))))))))
803 ;; Note: we don't use save-restriction because that does not work right
804 ;; if changes are made outside the saved restriction
805 ;; before that restriction is restored.
806 (narrow-to-region beg end
)
808 (set-marker end nil
)))
809 (while (string-match " +," blurb
)
810 (setq blurb
(concat (substring blurb
0 (match-beginning 0)) ","
811 (substring blurb
(match-end 0)))))
812 (while (string-match ", +" blurb
)
813 (setq blurb
(concat (substring blurb
0 (match-beginning 0)) ","
814 (substring blurb
(match-end 0)))))
815 (setq mode-line-process
816 (concat " " rmail-current-message
"/" rmail-total-messages
819 ;; Turn an attribute of a message on or off according to STATE.
820 ;; ATTR is the name of the attribute, as a string.
821 ;; MSGNUM is message number to change; nil means current message.
822 (defun rmail-set-attribute (attr state
&optional msgnum
)
823 (let ((omax (point-max-marker))
824 (omin (point-min-marker))
825 (buffer-read-only nil
))
826 (or msgnum
(setq msgnum rmail-current-message
))
830 (goto-char (+ 3 (rmail-msgbeg msgnum
)))
833 (null (search-backward (concat ", " attr
",")
834 (prog1 (point) (end-of-line)) t
)))))
835 (or (eq curstate
(not (not state
)))
837 (delete-region (point) (1- (match-end 0)))
840 (insert " " attr
","))))
841 (if (string= attr
"deleted")
842 (rmail-set-message-deleted-p msgnum state
)))
843 ;; Note: we don't use save-restriction because that does not work right
844 ;; if changes are made outside the saved restriction
845 ;; before that restriction is restored.
846 (narrow-to-region omin omax
)
847 (set-marker omin nil
)
848 (set-marker omax nil
)
849 (if (= msgnum rmail-current-message
)
850 (rmail-display-labels)))))
852 ;; Return t if the attributes/keywords line of msg number MSG
853 ;; contains a match for the regexp LABELS.
854 (defun rmail-message-labels-p (msg labels
)
858 (goto-char (rmail-msgbeg msg
))
860 (re-search-backward labels
(prog1 (point) (end-of-line)) t
))))
862 ;;;; *** Rmail Message Selection And Support ***
864 (defun rmail-msgend (n)
865 (marker-position (aref rmail-message-vector
(1+ n
))))
867 (defun rmail-msgbeg (n)
868 (marker-position (aref rmail-message-vector n
)))
870 (defun rmail-widen-to-current-msgbeg (function)
871 "Call FUNCTION with point at start of internal data of current message.
872 Assumes that bounds were previously narrowed to display the message in Rmail.
873 The bounds are widened enough to move point where desired, then narrowed
876 FUNCTION may not change the visible text of the message, but it may
877 change the invisible header text."
879 (let ((obeg (- (point-max) (point-min))))
882 (narrow-to-region (rmail-msgbeg rmail-current-message
)
884 (goto-char (point-min))
886 ;; Note: we don't use save-restriction because that does not work right
887 ;; if changes are made outside the saved restriction
888 ;; before that restriction is restored.
889 ;; Here we assume that changes made by FUNCTION
890 ;; occur before the visible region of the message.
891 (narrow-to-region (- (point-max) obeg
) (point-max))))))
893 (defun rmail-forget-messages ()
895 (if (vectorp rmail-message-vector
)
897 (v rmail-message-vector
)
900 (move-marker (aref v i
) nil
)
902 (setq rmail-message-vector nil
)
903 (setq rmail-deleted-vector nil
)))
905 (defun rmail-maybe-set-message-counters ()
906 (if (not (and rmail-deleted-vector
908 rmail-current-message
909 rmail-total-messages
))
910 (rmail-set-message-counters)))
912 (defun rmail-count-new-messages (&optional nomsg
)
913 (let* ((case-fold-search nil
)
917 (or nomsg
(message "Counting new messages..."))
918 (goto-char (point-max))
919 ;; Put at the end of messages-head
920 ;; the entry for message N+1, which marks
921 ;; the end of message N. (N = number of messages).
922 (search-backward "\n\^_")
924 (setq messages-head
(list (point-marker)))
925 (rmail-set-message-counters-counter (point-min))
926 (setq rmail-current-message
(1+ rmail-total-messages
))
927 (setq rmail-total-messages
928 (+ rmail-total-messages total-messages
))
929 (setq rmail-message-vector
930 (vconcat rmail-message-vector
(cdr messages-head
)))
931 (aset rmail-message-vector
932 rmail-current-message
(car messages-head
))
933 (setq rmail-deleted-vector
934 (concat rmail-deleted-vector deleted-head
))
935 (setq rmail-summary-vector
936 (vconcat rmail-summary-vector
(make-vector total-messages nil
)))
937 (goto-char (point-min))
938 (or nomsg
(message "Counting new messages...done (%d)" total-messages
))))
940 (defun rmail-set-message-counters ()
941 (rmail-forget-messages)
945 (let* ((point-save (point))
947 (messages-after-point)
948 (case-fold-search nil
)
951 (message "Counting messages...")
952 (goto-char (point-max))
953 ;; Put at the end of messages-head
954 ;; the entry for message N+1, which marks
955 ;; the end of message N. (N = number of messages).
956 (search-backward "\n\^_")
958 (setq messages-head
(list (point-marker)))
959 (rmail-set-message-counters-counter (min (point) point-save
))
960 (setq messages-after-point total-messages
)
961 (rmail-set-message-counters-counter)
962 (setq rmail-total-messages total-messages
)
963 (setq rmail-current-message
965 (max 1 (- total-messages messages-after-point
))))
966 (setq rmail-message-vector
967 (apply 'vector
(cons (point-min-marker) messages-head
))
968 rmail-deleted-vector
(concat "D" deleted-head
)
969 rmail-summary-vector
(make-vector rmail-total-messages nil
))
970 (message "Counting messages...done")))))
972 (defun rmail-set-message-counters-counter (&optional stop
)
973 (while (search-backward "\n\^_\^L\n" stop t
)
975 (setq messages-head
(cons (point-marker) messages-head
))
978 (cons (if (search-backward ", deleted,"
984 (if (zerop (%
(setq total-messages
(1+ total-messages
)) 20))
985 (message "Counting messages...%d" total-messages
))))
987 (defun rmail-beginning-of-message ()
988 "Show current message starting from the beginning."
990 (rmail-show-message rmail-current-message
))
992 (defun rmail-show-message (&optional n
)
993 "Show message number N (prefix argument), counting from start of file."
995 (rmail-maybe-set-message-counters)
997 (if (zerop rmail-total-messages
)
998 (progn (narrow-to-region (point-min) (1- (point-max)))
999 (goto-char (point-min))
1000 (setq mode-line-process nil
))
1003 (setq n rmail-current-message
)
1006 rmail-current-message
1
1007 blurb
"No previous message"))
1008 ((> n rmail-total-messages
)
1009 (setq n rmail-total-messages
1010 rmail-current-message rmail-total-messages
1011 blurb
"No following message"))
1013 (setq rmail-current-message n
))))
1014 (let ((beg (rmail-msgbeg n
))
1015 (end (rmail-msgend n
)))
1018 (if (= (following-char) ?
0)
1020 (rmail-reformat-message beg end
)
1021 (rmail-set-attribute "unseen" nil
))
1022 (search-forward "\n*** EOOH ***\n" end t
)
1023 (narrow-to-region (point) end
))
1024 (goto-char (point-min))
1025 (rmail-display-labels)
1026 (run-hooks 'rmail-show-message-hook
)
1028 (message blurb
))))))
1030 (defun rmail-next-message (n)
1031 "Show following message whether deleted or not.
1032 With prefix arg N, moves forward N messages, or backward if N is negative."
1034 (rmail-maybe-set-message-counters)
1035 (rmail-show-message (+ rmail-current-message n
)))
1037 (defun rmail-previous-message (n)
1038 "Show previous message whether deleted or not.
1039 With prefix arg N, moves backward N messages, or forward if N is negative."
1041 (rmail-next-message (- n
)))
1043 (defun rmail-next-undeleted-message (n)
1044 "Show following non-deleted message.
1045 With prefix arg N, moves forward N non-deleted messages,
1046 or backward if N is negative."
1048 (rmail-maybe-set-message-counters)
1049 (let ((lastwin rmail-current-message
)
1050 (current rmail-current-message
))
1051 (while (and (> n
0) (< current rmail-total-messages
))
1052 (setq current
(1+ current
))
1053 (if (not (rmail-message-deleted-p current
))
1054 (setq lastwin current n
(1- n
))))
1055 (while (and (< n
0) (> current
1))
1056 (setq current
(1- current
))
1057 (if (not (rmail-message-deleted-p current
))
1058 (setq lastwin current n
(1+ n
))))
1059 (if (/= lastwin rmail-current-message
)
1060 (rmail-show-message lastwin
))
1062 (error "No previous nondeleted message"))
1064 (error "No following nondeleted message"))))
1066 (defun rmail-previous-undeleted-message (n)
1067 "Show previous non-deleted message.
1068 With prefix argument N, moves backward N non-deleted messages,
1069 or forward if N is negative."
1071 (rmail-next-undeleted-message (- n
)))
1073 (defun rmail-first-message ()
1074 "Show first message in file."
1076 (rmail-maybe-set-message-counters)
1077 (rmail-show-message 1))
1079 (defun rmail-last-message ()
1080 "Show last message in file."
1082 (rmail-maybe-set-message-counters)
1083 (rmail-show-message rmail-total-messages
))
1085 (defun rmail-what-message ()
1086 (let ((where (point))
1088 (high rmail-total-messages
)
1089 (mid (/ rmail-total-messages
2)))
1090 (while (> (- high low
) 1)
1091 (if (>= where
(rmail-msgbeg mid
))
1094 (setq mid
(+ low
(/ (- high low
) 2))))
1095 (if (>= where
(rmail-msgbeg high
)) high low
)))
1097 (defvar rmail-search-last-regexp nil
)
1098 (defun rmail-search (regexp &optional reversep
)
1099 "Show message containing next match for REGEXP.
1100 Search in reverse (earlier messages) with non-nil second arg REVERSEP.
1101 Interactively, empty argument means use same regexp used last time,
1102 and reverse search is specified by a negative numeric arg."
1104 (let* ((reversep (< (prefix-numeric-value current-prefix-arg
) 0))
1106 (concat (if reversep
"Reverse " "") "Rmail search (regexp): "))
1108 (if rmail-search-last-regexp
1109 (setq prompt
(concat prompt
1111 rmail-search-last-regexp
1113 (setq regexp
(read-string prompt
))
1114 (cond ((not (equal regexp
""))
1115 (setq rmail-search-last-regexp regexp
))
1116 ((not rmail-search-last-regexp
)
1117 (error "No previous Rmail search string")))
1118 (list rmail-search-last-regexp reversep
)))
1119 (message "%sRmail search for %s..."
1120 (if reversep
"Reverse " "")
1122 (rmail-maybe-set-message-counters)
1123 (let ((omin (point-min))
1127 (msg rmail-current-message
))
1131 ;; Check messages one by one, advancing message number up or down
1132 ;; but searching forward through each message.
1134 (while (and (null win
) (> msg
1))
1135 (goto-char (rmail-msgbeg (setq msg
(1- msg
))))
1136 (setq win
(re-search-forward
1137 regexp
(rmail-msgend msg
) t
)))
1138 (while (and (null win
) (< msg rmail-total-messages
))
1139 (goto-char (rmail-msgbeg (setq msg
(1+ msg
))))
1140 (setq win
(re-search-forward regexp
(rmail-msgend msg
) t
)))))
1143 ;; If this is a reverse search and we found a message,
1144 ;; search backward thru this message to position point.
1147 (goto-char (rmail-msgend msg
))
1149 regexp
(rmail-msgbeg msg
) t
)))
1151 (rmail-show-message msg
)
1152 (message "%sRmail search for %s...done"
1153 (if reversep
"Reverse " "")
1157 (narrow-to-region omin omax
)
1159 (message "Search failed: %s" regexp
)))))
1161 ;; Show the first message which has the `unseen' attribute.
1162 (defun rmail-first-unseen-message ()
1167 (while (and (not found
) (< current rmail-total-messages
))
1168 (if (rmail-message-labels-p current
", ?\\(unseen\\),")
1169 (setq found current
))
1170 (setq current
(1+ current
))))
1172 (rmail-show-message found
))))
1174 ;;;; *** Rmail Message Deletion Commands ***
1176 (defun rmail-message-deleted-p (n)
1177 (= (aref rmail-deleted-vector n
) ?D
))
1179 (defun rmail-set-message-deleted-p (n state
)
1180 (aset rmail-deleted-vector n
(if state ?D ?\
)))
1182 (defun rmail-delete-message ()
1183 "Delete this message and stay on it."
1185 (rmail-set-attribute "deleted" t
))
1187 (defun rmail-undelete-previous-message ()
1188 "Back up to deleted message, select it, and undelete it."
1190 (let ((msg rmail-current-message
))
1191 (while (and (> msg
0)
1192 (not (rmail-message-deleted-p msg
)))
1193 (setq msg
(1- msg
)))
1195 (error "No previous deleted message")
1196 (if (/= msg rmail-current-message
)
1197 (rmail-show-message msg
))
1198 (rmail-set-attribute "deleted" nil
))))
1200 (defun rmail-delete-forward (&optional backward
)
1201 "Delete this message and move to next nondeleted one.
1202 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
1203 With prefix argument, delete and move backward. If there is no nondeleted
1204 message to move to in the preferred or specified direction, move in the
1207 (rmail-set-attribute "deleted" t
)
1209 (rmail-next-undeleted-message (if backward -
1 1))
1212 (rmail-previous-undeleted-message (if backward -
1 1))
1215 (defun rmail-delete-backward ()
1216 "Delete this message and move to previous nondeleted one.
1217 Deleted messages stay in the file until the \\[rmail-expunge] command is given."
1219 (rmail-delete-forward t
))
1221 (defun rmail-expunge ()
1222 "Actually erase all deleted messages in the file."
1224 (message "Expunging deleted messages...")
1225 ;; Discard all undo records for this buffer.
1226 (or (eq buffer-undo-list t
)
1227 (setq buffer-undo-list nil
))
1228 (rmail-maybe-set-message-counters)
1229 (let* ((omax (- (buffer-size) (point-max)))
1230 (omin (- (buffer-size) (point-min)))
1231 (opoint (if (and (> rmail-current-message
0)
1232 (= ?D
(aref rmail-deleted-vector rmail-current-message
)))
1233 0 (- (point) (point-min))))
1234 (messages-head (cons (aref rmail-message-vector
0) nil
))
1235 (messages-tail messages-head
)
1236 ;; Don't make any undo records for the expunging.
1237 (buffer-undo-list t
)
1242 (goto-char (point-min))
1245 (total rmail-total-messages
)
1246 (new-message-number rmail-current-message
)
1248 (buffer-read-only nil
)
1249 (messages rmail-message-vector
)
1250 (deleted rmail-deleted-vector
)
1251 (summary rmail-summary-vector
))
1252 (setq rmail-total-messages nil
1253 rmail-current-message nil
1254 rmail-message-vector nil
1255 rmail-deleted-vector nil
1256 rmail-summary-vector nil
)
1257 (while (<= number total
)
1258 (if (= (aref deleted number
) ?D
)
1261 (marker-position (aref messages number
))
1262 (marker-position (aref messages
(1+ number
))))
1263 (move-marker (aref messages number
) nil
)
1264 (if (> new-message-number counter
)
1265 (setq new-message-number
(1- new-message-number
))))
1266 (setq counter
(1+ counter
))
1268 (setcdr messages-tail
1269 (cons (aref messages number
) nil
)))
1271 (cons (if (= counter number
) (aref summary
(1- number
)))
1273 (if (zerop (%
(setq number
(1+ number
)) 20))
1274 (message "Expunging deleted messages...%d" number
)))
1276 (setcdr messages-tail
1277 (cons (aref messages number
) nil
)))
1278 (setq rmail-current-message new-message-number
1279 rmail-total-messages counter
1280 rmail-message-vector
(apply 'vector messages-head
)
1281 rmail-deleted-vector
(make-string (1+ counter
) ?\
)
1282 rmail-summary-vector
(vconcat (nreverse new-summary
))
1284 (message "Expunging deleted messages...done")
1286 (narrow-to-region (- (buffer-size) omin
) (- (buffer-size) omax
)))
1288 (if (zerop rmail-current-message
) 1 nil
))
1289 (forward-char opoint
))))
1291 ;;;; *** Rmail Mailing Commands ***
1293 (defun rmail-mail ()
1294 "Send mail in another window. While composing the message, use
1295 \\[mail-yank-original] to yank the original message into it."
1297 (mail-other-window nil nil nil nil nil
(current-buffer)))
1299 (defun rmail-continue ()
1300 "Continue composing outgoing message previously being composed."
1302 (mail-other-window t
))
1304 (defun rmail-reply (just-sender)
1305 "Reply to the current message.
1306 Normally include CC: to all other recipients of original message;
1307 prefix argument means ignore them. While composing the reply,
1308 use \\[mail-yank-original] to yank the original message into it."
1310 (let (from reply-to cc subject date to message-id resent-reply-to
)
1314 (goto-char (rmail-msgbeg rmail-current-message
))
1316 (if (= (following-char) ?
0)
1318 (progn (forward-line 2)
1320 (progn (search-forward "\n\n" (rmail-msgend rmail-current-message
)
1323 (narrow-to-region (point)
1324 (progn (search-forward "\n*** EOOH ***\n")
1325 (beginning-of-line) (point))))
1326 (setq resent-reply-to
(mail-fetch-field "resent-reply-to" t
)
1327 from
(mail-fetch-field "from")
1328 reply-to
(or resent-reply-to
1329 (mail-fetch-field "reply-to" nil t
)
1331 cc
(cond (just-sender nil
)
1332 (resent-reply-to (mail-fetch-field "resent-cc" t
))
1333 (t (mail-fetch-field "cc" nil t
)))
1334 subject
(or (and resent-reply-to
1335 (mail-fetch-field "resent-subject" t
))
1336 (mail-fetch-field "subject"))
1337 date
(cond (resent-reply-to
1338 (mail-fetch-field "resent-date" t
))
1339 ((mail-fetch-field "date")))
1340 to
(cond (resent-reply-to
1341 (mail-fetch-field "resent-to" t
))
1342 ((mail-fetch-field "to" nil t
))
1343 ;((mail-fetch-field "apparently-to")) ack gag barf
1345 message-id
(cond (resent-reply-to
1346 (mail-fetch-field "resent-message-id" t
))
1347 ((mail-fetch-field "message-id"))))))
1349 (string-match "\\`Re: " subject
)
1350 (setq subject
(substring subject
4)))
1351 (mail-other-window nil
1352 (mail-strip-quoted-names reply-to
)
1354 (rmail-make-in-reply-to-field from date message-id
)
1357 (let* ((cc-list (rmail-dont-reply-to
1358 (mail-strip-quoted-names
1359 (if (null cc
) to
(concat to
", " cc
))))))
1360 (if (string= cc-list
"") nil cc-list
)))
1362 (list (list '(lambda (buf msgnum
)
1365 (rmail-set-attribute "answered" t msgnum
)))
1366 (current-buffer) rmail-current-message
)))))
1368 (defun rmail-make-in-reply-to-field (from date message-id
)
1375 (let ((tem (car (rfc822-addresses from
))))
1378 (regexp-quote (if (string-match "@[^@]*\\'" tem
)
1379 (substring tem
0 (match-beginning 0))
1382 ;; Message-ID is sufficiently informative
1384 (concat message-id
" (" tem
")"))
1385 ;; Use prin1 to fake RFC822 quoting
1386 (let ((field (prin1-to-string tem
)))
1388 (concat field
"'s message of " date
)
1390 ((let* ((foo "[^][\000-\037\177-\377()<>@,;:\\\" ]+")
1391 (bar "[^][\000-\037\177-\377()<>@,;:\\\"]+"))
1392 ;; Can't use format because format loses on \000 (unix *^&%*^&%$!!)
1393 (or (string-match (concat "\\`[ \t]*\\(" bar
1394 "\\)\\(<" foo
"@" foo
">\\)?[ \t]*\\'")
1395 ;; "Unix Loser <Foo@bar.edu>" => "Unix Loser"
1397 (string-match (concat "\\`[ \t]*<" foo
"@" foo
">[ \t]*(\\("
1398 bar
"\\))[ \t]*\\'")
1399 ;; "<Bugs@bar.edu>" (Losing Unix) => "Losing Unix"
1401 (let ((start (match-beginning 1))
1402 (end (match-end 1)))
1403 ;; Trim whitespace which above regexp match allows
1404 (while (and (< start end
)
1405 (memq (aref from start
) '(?
\t ?\
)))
1406 (setq start
(1+ start
)))
1407 (while (and (< start end
)
1408 (memq (aref from
(1- end
)) '(?
\t ?\
)))
1409 (setq end
(1- end
)))
1410 (let ((field (substring from start end
)))
1411 (if date
(setq field
(concat "message from " field
" on " date
)))
1413 ;; "<AA259@bar.edu> (message from Unix Loser on 1-Apr-89)"
1414 (concat message-id
" (" field
")")
1417 ;; If we can't kludge it simply, do it correctly
1418 (let ((mail-use-rfc822 t
))
1419 (rmail-make-in-reply-to-field from date message-id
)))))
1421 (defun rmail-forward ()
1422 "Forward the current message to another user."
1424 (let ((forward-buffer (current-buffer))
1425 (subject (concat "["
1426 (mail-strip-quoted-names (mail-fetch-field "From"))
1427 ": " (or (mail-fetch-field "Subject") "") "]")))
1428 ;; If only one window, use it for the mail buffer.
1429 ;; Otherwise, use another window for the mail buffer
1430 ;; so that the Rmail buffer remains visible
1431 ;; and sending the mail will get back to it.
1432 (if (funcall (if (one-window-p t
)
1434 (function mail-other-window
))
1435 nil nil subject nil nil nil
1436 (list (list (function (lambda (buf msgnum
)
1439 (rmail-set-attribute "forwarded" t msgnum
))))
1441 rmail-current-message
)))
1443 (goto-char (point-max))
1445 (insert-buffer forward-buffer
)))))
1447 (defun rmail-resend (address &optional from comment mail-alias-file
)
1448 "Resend current message to ADDRESSES.
1449 ADDRESSES should be a single address, a a string consisting of several
1450 addresses separated by commas, or a list of addresses.
1452 Optional FROM is the address to resend the message from, and
1453 defaults to the username of the person redistributing the message.
1454 Optional COMMENT is a string that will be inserted as a comment in the
1456 Optional ALIAS-FILE is alternate aliases file to be used by sendmail,
1457 typically for purposes of moderating a list."
1458 (interactive "sResend to: ")
1459 (if (not from
) (setq from
(user-login-name)))
1460 (let ((tembuf (generate-new-buffer " sendmail temp"))
1461 (mail-header-separator "")
1462 (case-fold-search nil
)
1463 (mailbuf (current-buffer)))
1466 ;;>> Copy message into temp buffer
1468 (insert-buffer-substring mailbuf
)
1469 (goto-char (point-min))
1470 ;;>> Insert resent-from:
1471 (insert "Resent-From: " from
"\n")
1472 (insert "Resent-Date: " (current-time-string) "\n")
1473 ;;>> Insert resent-to: and bcc if need be.
1474 (let ((before (point)))
1475 (insert "Resent-To: " (if (stringp address
)
1477 (mapconcat 'identity address
",\n\t"))
1479 (expand-mail-aliases before
(point)))
1480 ;;>> Set up comment, if any.
1481 (if (and (sequencep comment
) (not (zerop (length comment
))))
1482 (let ((before (point))
1485 (or (eolp) (insert "\n"))
1486 (setq after
(point))
1488 (while (< (point) after
)
1489 (insert "Resent-Comment: ")
1491 ;; Don't expand aliases in the destination fields
1492 ;; of the original message.
1494 (sendmail-send-it)))
1495 (kill-buffer tembuf
))))
1497 (defvar mail-unsent-separator
"^ ----- Unsent message follows -----$")
1499 (defun rmail-retry-failure ()
1500 "Edit a mail message which is based on the contents of the current message.
1501 For a message rejected by the mail system, extract the interesting headers and
1502 the body of the original message; otherwise copy the current message."
1504 (require 'mail-utils
)
1505 (let (to subj irp2 cc orig-message
)
1507 ;; Narrow down to just the quoted original message
1508 (rmail-beginning-of-message)
1509 (or (re-search-forward mail-unsent-separator nil t
)
1510 (error "Cannot parse this as a failure message"))
1512 (narrow-to-region (point) (point-max))
1513 ;; Now mail-fetch-field will get from headers of the original message,
1514 ;; not from the headers of the rejection.
1515 (setq to
(mail-fetch-field "To")
1516 subj
(mail-fetch-field "Subject")
1517 irp2
(mail-fetch-field "In-reply-to")
1518 cc
(mail-fetch-field "Cc"))
1519 ;; Get the entire text (not headers) of the original message.
1522 (progn (search-forward "\n\n") (point))
1524 ;; Start sending a new message; default header fields from the original.
1525 (if (mail-other-window nil to subj irp2 cc
(current-buffer))
1526 ;; Insert original text as initial text of new draft message.
1528 (goto-char (point-max))
1529 (insert orig-message
)
1530 (goto-char (point-min))
1533 ;;;; *** Rmail Specify Inbox Files ***
1535 (autoload 'set-rmail-inbox-list
"rmailmsc"
1536 "Set the inbox list of the current RMAIL file to FILE-NAME.
1537 This may be a list of file names separated by commas.
1538 If FILE-NAME is empty, remove any inbox list."
1541 ;;;; *** Rmail Commands for Labels ***
1543 (autoload 'rmail-add-label
"rmailkwd"
1544 "Add LABEL to labels associated with current RMAIL message.
1545 Completion is performed over known labels when reading."
1548 (autoload 'rmail-kill-label
"rmailkwd"
1549 "Remove LABEL from labels associated with current RMAIL message.
1550 Completion is performed over known labels when reading."
1553 (autoload 'rmail-next-labeled-message
"rmailkwd"
1554 "Show next message with LABEL. Defaults to last label used.
1555 With prefix argument N moves forward N messages with this label."
1558 (autoload 'rmail-previous-labeled-message
"rmailkwd"
1559 "Show previous message with LABEL. Defaults to last label used.
1560 With prefix argument N moves backward N messages with this label."
1563 ;;;; *** Rmail Edit Mode ***
1565 (autoload 'rmail-edit-current-message
"rmailedit"
1566 "Edit the contents of the current message"
1569 ;;;; *** Rmail Summary Mode ***
1571 (autoload 'rmail-summary
"rmailsum"
1572 "Display a summary of all messages, one line per message."
1575 (autoload 'rmail-summary-by-labels
"rmailsum"
1576 "Display a summary of all messages with one or more LABELS.
1577 LABELS should be a string containing the desired labels, separated by commas."
1580 (autoload 'rmail-summary-by-recipients
"rmailsum"
1581 "Display a summary of all messages with the given RECIPIENTS.
1582 Normally checks the To, From and Cc fields of headers; but if PRIMARY-ONLY
1583 is non-nil (prefix arg given), only look in the To and From fields.
1584 RECIPIENTS is a string of names separated by commas."
1587 ;;;; *** Rmail output messages to files ***
1589 (autoload 'rmail-output-to-rmail-file
"rmailout"
1590 "Append the current message to an Rmail file named FILE-NAME.
1591 If the file does not exist, ask if it should be created.
1592 If file is being visited, the message is appended to the Emacs
1593 buffer visiting that file."
1596 (autoload 'rmail-output
"rmailout"
1597 "Append this message to Unix mail file named FILE-NAME."
1600 ;;;; *** Rmail undigestification ***
1602 (autoload 'undigestify-rmail-message
"undigest"
1603 "Break up a digest message into its constituent messages.
1604 Leaves original message, deleted, before the undigestified messages."