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