Mercurial > emacs
annotate lisp/mail/rmail.el @ 853:224b0d5d1a38
*** empty log message ***
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Wed, 22 Jul 1992 21:20:04 +0000 |
parents | 20674ae6bf52 |
children | b945f592b94d |
rev | line source |
---|---|
658
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
621
diff
changeset
|
1 ;;; rmail.el --- main code of "RMAIL" mail reader for Emacs. |
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
621
diff
changeset
|
2 |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
830
diff
changeset
|
3 ;; Copyright (C) 1985, 1986, 1987, 1988, 1991, 1992 Free Software Foundation, Inc. |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
830
diff
changeset
|
4 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
5 ;; Maintainer: FSF |
814
38b2499cb3e9
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
813
diff
changeset
|
6 ;; Keywords: mail |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
7 |
270 | 8 ;; This file is part of GNU Emacs. |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
12 ;; the Free Software Foundation; either version 2, or (at your option) |
270 | 13 ;; any later version. |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
23 | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
24 ;;; Code: |
270 | 25 |
26 ;; Souped up by shane@mit-ajax based on ideas of rlk@athena.mit.edu | |
27 ;; New features include attribute and keyword support, message | |
28 ;; selection by dispatch table, summary by attributes and keywords, | |
29 ;; expunging by dispatch table, sticky options for file commands. | |
30 | |
31 (require 'mail-utils) | |
32 ; These variables now declared paths.el | |
33 ;(defvar rmail-spool-directory "/usr/spool/mail/" | |
34 ; "This is the name of the directory used by the system mailer for\n\ | |
35 ;delivering new mail. It's name should end with a slash.") | |
36 ;(defvar rmail-file-name | |
37 ; (expand-file-name "~/RMAIL") | |
38 ; "") | |
39 | |
40 ;;;###autoload | |
41 (defvar rmail-dont-reply-to-names nil "\ | |
42 *A regexp specifying names to prune of reply to messages. | |
43 nil means dont reply to yourself.") | |
44 | |
45 ;;;###autoload | |
46 (defvar rmail-default-dont-reply-to-names "info-" "\ | |
47 A regular expression specifying part of the value of the default value of | |
48 the variable `rmail-dont-reply-to-names', for when the user does not set | |
49 `rmail-dont-reply-to-names' explicitly. (The other part of the default | |
50 value is the user's name.) | |
51 It is useful to set this variable in the site customisation file.") | |
52 | |
53 ;;;###autoload | |
54 (defvar rmail-ignored-headers "^via:\\|^mail-from:\\|^origin:\\|^status:\\|^received:\\|^message-id:\\|^summary-line:" "\ | |
55 *Gubbish headers one would rather not see.") | |
56 | |
57 ;;;###autoload | |
58 (defvar rmail-delete-after-output nil "\ | |
59 *Non-nil means automatically delete a message that is copied to a file.") | |
60 | |
61 ;;;###autoload | |
62 (defconst rmail-primary-inbox-list nil "\ | |
63 *List of files which are inboxes for user's primary mail file ~/RMAIL. | |
64 `nil' means the default, which is (\"/usr/spool/mail/$USER\" \"~/mbox\") | |
65 \(the first name varies depending on the operating system, | |
66 and the value of the environment variable MAIL overrides it).") | |
67 | |
68 ;; these may be altered by site-init.el to match the format of mmdf files | |
69 ;; delimitation used on a given host (delim1 and delim2 from the config | |
70 ;; files) | |
71 | |
72 (defvar mmdf-delim1 "^\001\001\001\001\n" | |
73 "Regexp marking the start of an mmdf message") | |
74 (defvar mmdf-delim2 "^\001\001\001\001\n" | |
75 "Regexp marking the end of an mmdf message") | |
76 | |
77 (defvar rmail-message-filter nil | |
78 "If non nil, is a filter function for new headers in RMAIL. | |
79 Called with region narrowed to unformatted header.") | |
80 | |
81 (defvar rmail-mode-map nil) | |
82 | |
83 (defvar rmail-inbox-list nil) | |
84 (defvar rmail-keywords nil) | |
85 | |
86 ;; Message counters and markers. Deleted flags. | |
87 | |
88 (defvar rmail-current-message nil) | |
89 (defvar rmail-total-messages nil) | |
90 (defvar rmail-message-vector nil) | |
91 (defvar rmail-deleted-vector nil) | |
92 | |
93 ;; These are used by autoloaded rmail-summary. | |
94 | |
95 (defvar rmail-summary-buffer nil) | |
96 (defvar rmail-summary-vector nil) | |
97 | |
98 ;; `Sticky' default variables. | |
99 | |
100 ;; Last individual label specified to a or k. | |
101 (defvar rmail-last-label nil) | |
102 ;; Last set of labels specified to C-M-n or C-M-p or C-M-l. | |
103 (defvar rmail-last-multi-labels nil) | |
104 (defvar rmail-last-file nil) | |
105 (defvar rmail-last-rmail-file nil) | |
617 | 106 |
621 | 107 ;;; Regexp matching the delimiter of messages in UNIX mail format |
108 ;;; (UNIX From lines), minus the initial ^. Note that if you change | |
109 ;;; this expression, you must change the code in rmail-nuke-pinhead-header | |
110 ;;; that knows the exact ordering of the \\( \\) subexpressions. | |
617 | 111 (defvar rmail-unix-mail-delimiter |
621 | 112 "From \\([^ \n]*\\(\\|\".*\"[^ \n]*\\)\\) ?\\([^ \n]*\\) \\([^ ]*\\) *\\([0-9]*\\) \\([0-9:]*\\)\\( ?[A-Z]?[A-Z][A-Z]T\\( DST\\)?\\| ?[-+]?[0-9][0-9][0-9][0-9]\\|\\) [0-9][0-9]\\([0-9]*\\) *\\(remote from [^\n]*\\)?\n" nil) |
270 | 113 |
114 ;;;; *** Rmail Mode *** | |
115 | |
116 ;;;###autoload | |
117 (defun rmail (&optional file-name-arg) | |
118 "Read and edit incoming mail. | |
119 Moves messages into file named by rmail-file-name (a babyl format file) | |
120 and edits that file in RMAIL Mode. | |
121 Type \\[describe-mode] once editing that file, for a list of RMAIL commands. | |
122 | |
123 May be called with filename as argument; then performs rmail editing on | |
124 that file, but does not copy any new mail into the file." | |
125 (interactive (if current-prefix-arg | |
126 (list (read-file-name "Run rmail on RMAIL file: " | |
127 nil nil t)))) | |
128 (or rmail-last-file | |
129 (setq rmail-last-file (expand-file-name "~/xmail"))) | |
130 (or rmail-last-rmail-file | |
131 (setq rmail-last-rmail-file (expand-file-name "~/XMAIL"))) | |
132 (let* ((file-name (expand-file-name (or file-name-arg rmail-file-name))) | |
133 (existed (get-file-buffer file-name))) | |
134 ;; Like find-file, but in the case where a buffer existed | |
135 ;; and the file was reverted, recompute the message-data. | |
136 (if (and existed (not (verify-visited-file-modtime existed))) | |
137 (progn | |
138 ;; Don't be confused by apparent local-variables spec | |
139 ;; in the last message in the RMAIL file. | |
140 (let ((inhibit-local-variables t)) | |
141 (find-file file-name)) | |
142 (if (verify-visited-file-modtime existed) | |
143 (progn (rmail-forget-messages) | |
144 (rmail-set-message-counters)))) | |
145 (let ((inhibit-local-variables t)) | |
146 (find-file file-name))) | |
147 (if (and existed (> (buffer-size) 0)) | |
148 ;; Buffer not new and not empty; ensure in proper mode, but that's all. | |
149 (or (eq major-mode 'rmail-mode) | |
150 (rmail-mode-2)) | |
151 (rmail-mode-2) | |
152 ;; Provide default set of inboxes for primary mail file ~/RMAIL. | |
153 (and (null rmail-inbox-list) | |
154 (null file-name-arg) | |
155 (setq rmail-inbox-list | |
156 (or rmail-primary-inbox-list | |
157 (list "~/mbox" | |
158 (or (getenv "MAIL") | |
159 (concat rmail-spool-directory | |
160 (user-original-login-name))))))) | |
161 ;; Convert all or part to Babyl file if possible. | |
162 (rmail-convert-file) | |
163 (goto-char (point-max)) | |
164 (if (null rmail-inbox-list) | |
165 (progn | |
166 (rmail-set-message-counters) | |
167 (rmail-show-message)))) | |
168 (rmail-get-new-mail) | |
169 ;; Show the first unseen message, which might be from a previous session | |
170 ;; or might have been just read in by rmail-get-new-mail. | |
171 (rmail-first-unseen-message))) | |
172 | |
173 ;; Given the value of MAILPATH, return a list of inbox file names. | |
174 ;; This is turned off because it is not clear that the user wants | |
175 ;; all these inboxes to feed into the primary rmail file. | |
176 ; (defun rmail-convert-mailpath (string) | |
177 ; (let (idx list) | |
178 ; (while (setq idx (string-match "[%:]" string)) | |
179 ; (let ((this (substring string 0 idx))) | |
180 ; (setq string (substring string (1+ idx))) | |
181 ; (setq list (cons (if (string-match "%" this) | |
182 ; (substring this 0 (string-match "%" this)) | |
183 ; this) | |
184 ; list)))) | |
185 ; list)) | |
186 | |
187 ; I have checked that adding "-*- rmail -*-" to the BABYL OPTIONS line | |
188 ; will not cause emacs 18.55 problems. | |
189 | |
190 (defun rmail-convert-file () | |
191 (let (convert) | |
192 (widen) | |
193 (goto-char (point-min)) | |
194 ;; If file doesn't start like a Babyl file, | |
195 ;; convert it to one, by adding a header and converting each message. | |
196 (cond ((looking-at "BABYL OPTIONS:")) | |
197 ((looking-at "Version: 5\n") | |
198 ;; Losing babyl file made by old version of Rmail. | |
199 ;; Just fix the babyl file header; don't make a new one, | |
200 ;; so we don't lose the Labels: file attribute, etc. | |
201 (let ((buffer-read-only nil)) | |
202 (insert "BABYL OPTIONS: -*- rmail -*-\n"))) | |
203 (t | |
204 (setq convert t) | |
205 (rmail-insert-rmail-file-header))) | |
206 ;; If file was not a Babyl file or if there are | |
207 ;; Unix format messages added at the end, | |
208 ;; convert file as necessary. | |
209 (if (or convert | |
210 (progn (goto-char (point-max)) | |
211 (search-backward "\^_") | |
212 (forward-char 1) | |
213 (looking-at "\n*From "))) | |
214 (let ((buffer-read-only nil)) | |
215 (message "Converting to Babyl format...") | |
216 (narrow-to-region (point) (point-max)) | |
217 (rmail-convert-to-babyl-format) | |
218 (message "Converting to Babyl format...done"))))) | |
219 | |
220 ; I have checked that adding "-*- rmail -*-" to the BABYL OPTIONS line | |
221 ; will not cause emacs 18.55 problems. | |
222 | |
223 (defun rmail-insert-rmail-file-header () | |
224 (let ((buffer-read-only nil)) | |
225 (insert "BABYL OPTIONS: -*- rmail -*- | |
226 Version: 5 | |
227 Labels: | |
228 Note: This is the header of an rmail file. | |
229 Note: If you are seeing it in rmail, | |
230 Note: it means the file has no messages in it.\n\^_"))) | |
231 | |
232 (if rmail-mode-map | |
233 nil | |
234 (setq rmail-mode-map (make-keymap)) | |
235 (suppress-keymap rmail-mode-map) | |
236 (define-key rmail-mode-map "." 'rmail-beginning-of-message) | |
237 (define-key rmail-mode-map " " 'scroll-up) | |
238 (define-key rmail-mode-map "\177" 'scroll-down) | |
239 (define-key rmail-mode-map "n" 'rmail-next-undeleted-message) | |
240 (define-key rmail-mode-map "p" 'rmail-previous-undeleted-message) | |
241 (define-key rmail-mode-map "\en" 'rmail-next-message) | |
242 (define-key rmail-mode-map "\ep" 'rmail-previous-message) | |
243 (define-key rmail-mode-map "\e\C-n" 'rmail-next-labeled-message) | |
244 (define-key rmail-mode-map "\e\C-p" 'rmail-previous-labeled-message) | |
245 (define-key rmail-mode-map "a" 'rmail-add-label) | |
246 (define-key rmail-mode-map "k" 'rmail-kill-label) | |
247 (define-key rmail-mode-map "d" 'rmail-delete-forward) | |
248 (define-key rmail-mode-map "u" 'rmail-undelete-previous-message) | |
249 (define-key rmail-mode-map "x" 'rmail-expunge) | |
250 (define-key rmail-mode-map "s" 'rmail-expunge-and-save) | |
251 (define-key rmail-mode-map "g" 'rmail-get-new-mail) | |
252 (define-key rmail-mode-map "h" 'rmail-summary) | |
253 (define-key rmail-mode-map "\e\C-h" 'rmail-summary) | |
254 (define-key rmail-mode-map "l" 'rmail-summary-by-labels) | |
255 (define-key rmail-mode-map "\e\C-l" 'rmail-summary-by-labels) | |
256 (define-key rmail-mode-map "\e\C-r" 'rmail-summary-by-recipients) | |
257 (define-key rmail-mode-map "\e\C-s" 'rmail-summary-by-regexp) | |
258 (define-key rmail-mode-map "t" 'rmail-toggle-header) | |
259 (define-key rmail-mode-map "m" 'rmail-mail) | |
260 (define-key rmail-mode-map "r" 'rmail-reply) | |
261 (define-key rmail-mode-map "\e\C-m" 'rmail-retry-failure) | |
262 (define-key rmail-mode-map "c" 'rmail-continue) | |
263 (define-key rmail-mode-map "f" 'rmail-forward) | |
264 (define-key rmail-mode-map "\es" 'rmail-search) | |
265 (define-key rmail-mode-map "<" 'rmail-first-message) | |
266 (define-key rmail-mode-map ">" 'rmail-last-message) | |
267 (define-key rmail-mode-map "j" 'rmail-show-message) | |
268 (define-key rmail-mode-map "o" 'rmail-output-to-rmail-file) | |
269 (define-key rmail-mode-map "\C-o" 'rmail-output) | |
270 (define-key rmail-mode-map "i" 'rmail-input) | |
271 (define-key rmail-mode-map "q" 'rmail-quit) | |
272 (define-key rmail-mode-map "?" 'describe-mode) | |
273 (define-key rmail-mode-map "w" 'rmail-edit-current-message) | |
274 (define-key rmail-mode-map "e" 'rmail-edit-current-message) | |
275 (define-key rmail-mode-map "\C-d" 'rmail-delete-backward)) | |
276 | |
277 ;; Rmail mode is suitable only for specially formatted data. | |
278 (put 'rmail-mode 'mode-class 'special) | |
279 | |
280 (defun rmail-mode () | |
281 "Rmail Mode is used by \\<rmail-mode-map>\\[rmail] for editing Rmail files. | |
282 All normal editing commands are turned off. | |
283 Instead, these commands are available: | |
284 | |
285 \\[rmail-beginning-of-message] Move point to front of this message (same as \\[beginning-of-buffer]). | |
286 \\[scroll-up] Scroll to next screen of this message. | |
287 \\[scroll-down] Scroll to previous screen of this message. | |
288 \\[rmail-next-undeleted-message] Move to Next non-deleted message. | |
289 \\[rmail-previous-undeleted-message] Move to Previous non-deleted message. | |
290 \\[rmail-next-message] Move to Next message whether deleted or not. | |
291 \\[rmail-previous-message] Move to Previous message whether deleted or not. | |
292 \\[rmail-first-message] Move to the first message in Rmail file. | |
293 \\[rmail-last-message] Move to the last message in Rmail file. | |
294 \\[rmail-show-message] Jump to message specified by numeric position in file. | |
295 \\[rmail-search] Search for string and show message it is found in. | |
296 \\[rmail-delete-forward] Delete this message, move to next nondeleted. | |
297 \\[rmail-delete-backward] Delete this message, move to previous nondeleted. | |
298 \\[rmail-undelete-previous-message] Undelete message. Tries current message, then earlier messages | |
299 till a deleted message is found. | |
300 \\[rmail-expunge] Expunge deleted messages. | |
301 \\[rmail-expunge-and-save] Expunge and save the file. | |
302 \\[rmail-quit] Quit Rmail: expunge, save, then switch to another buffer. | |
303 \\[save-buffer] Save without expunging. | |
304 \\[rmail-get-new-mail] Move new mail from system spool directory or mbox into this file. | |
305 \\[rmail-mail] Mail a message (same as \\[mail-other-window]). | |
306 \\[rmail-continue] Continue composing outgoing message started before. | |
307 \\[rmail-reply] Reply to this message. Like m but initializes some fields. | |
308 \\[rmail-retry-failure] Send this message again. Used on a mailer failure message. | |
309 \\[rmail-forward] Forward this message to another user. | |
310 \\[rmail-output-to-rmail-file] Output this message to an Rmail file (append it). | |
311 \\[rmail-output] Output this message to a Unix-format mail file (append it). | |
312 \\[rmail-input] Input Rmail file. Run Rmail on that file. | |
313 \\[rmail-add-label] Add label to message. It will be displayed in the mode line. | |
314 \\[rmail-kill-label] Kill label. Remove a label from current message. | |
315 \\[rmail-next-labeled-message] Move to Next message with specified label | |
316 (label defaults to last one specified). | |
317 Standard labels: filed, unseen, answered, forwarded, deleted. | |
318 Any other label is present only if you add it with `a'. | |
319 \\[rmail-previous-labeled-message] Move to Previous message with specified label | |
320 \\[rmail-summary] Show headers buffer, with a one line summary of each message. | |
321 \\[rmail-summary-by-labels] Like h only just messages with particular label(s) are summarized. | |
322 \\[rmail-summary-by-recipients] Like h only just messages with particular recipient(s) are summarized. | |
323 \\[rmail-toggle-header] Toggle header, show Rmail header if unformatted or vice versa. | |
324 \\[rmail-edit-current-message] Edit the current message. \\[rmail-cease-edit] to return to Rmail." | |
325 (interactive) | |
326 (rmail-mode-2) | |
327 (rmail-set-message-counters) | |
328 (rmail-show-message)) | |
329 | |
330 (defun rmail-mode-2 () | |
331 (kill-all-local-variables) | |
332 (rmail-mode-1) | |
333 (rmail-variables) | |
334 (run-hooks 'rmail-mode-hook)) | |
335 | |
336 (defun rmail-mode-1 () | |
337 (setq major-mode 'rmail-mode) | |
338 (setq mode-name "RMAIL") | |
339 (setq buffer-read-only t) | |
340 ;; No need to auto save RMAIL files. | |
341 (setq buffer-auto-save-file-name nil) | |
342 (if (boundp 'mode-line-modified) | |
343 (setq mode-line-modified "--- ") | |
344 (setq mode-line-format | |
345 (cons "--- " (cdr (default-value 'mode-line-format))))) | |
346 (use-local-map rmail-mode-map) | |
347 (set-syntax-table text-mode-syntax-table) | |
348 (setq local-abbrev-table text-mode-abbrev-table)) | |
349 | |
350 (defun rmail-variables () | |
351 (make-local-variable 'revert-buffer-function) | |
352 (setq revert-buffer-function 'rmail-revert) | |
353 (make-local-variable 'rmail-last-label) | |
354 (make-local-variable 'rmail-deleted-vector) | |
355 (make-local-variable 'rmail-summary-buffer) | |
356 (make-local-variable 'rmail-summary-vector) | |
357 (make-local-variable 'rmail-current-message) | |
358 (make-local-variable 'rmail-total-messages) | |
359 (make-local-variable 'require-final-newline) | |
360 (setq require-final-newline nil) | |
361 (make-local-variable 'version-control) | |
362 (setq version-control 'never) | |
363 (make-local-variable 'file-precious-flag) | |
364 (setq file-precious-flag t) | |
365 (make-local-variable 'rmail-message-vector) | |
366 (make-local-variable 'rmail-last-file) | |
367 (make-local-variable 'rmail-inbox-list) | |
368 (setq rmail-inbox-list (rmail-parse-file-inboxes)) | |
369 (make-local-variable 'rmail-keywords) | |
370 ;; this gets generated as needed | |
280
e6f9ccb230ad
*** empty log message ***
Michael I. Bushnell <mib@gnu.org>
parents:
270
diff
changeset
|
371 (setq rmail-keywords nil)) |
270 | 372 |
373 ;; Handle M-x revert-buffer done in an rmail-mode buffer. | |
374 (defun rmail-revert (arg noconfirm) | |
375 (let (revert-buffer-function) | |
376 ;; Call our caller again, but this time it does the default thing. | |
377 (if (revert-buffer arg noconfirm) | |
378 ;; If the user said "yes", and we changed something, | |
379 ;; reparse the messages. | |
380 (progn | |
381 (rmail-convert-file) | |
382 (goto-char (point-max)) | |
383 (rmail-set-message-counters) | |
384 (rmail-show-message))))) | |
385 | |
386 ;; Return a list of files from this buffer's Mail: option. | |
387 ;; Does not assume that messages have been parsed. | |
388 ;; Just returns nil if buffer does not look like Babyl format. | |
389 (defun rmail-parse-file-inboxes () | |
390 (save-excursion | |
391 (save-restriction | |
392 (widen) | |
393 (goto-char 1) | |
394 (cond ((looking-at "BABYL OPTIONS:") | |
395 (search-forward "\n\^_" nil 'move) | |
396 (narrow-to-region 1 (point)) | |
397 (goto-char 1) | |
398 (if (search-forward "\nMail:" nil t) | |
399 (progn | |
400 (narrow-to-region (point) (progn (end-of-line) (point))) | |
401 (goto-char (point-min)) | |
402 (mail-parse-comma-list)))))))) | |
403 | |
404 (defun rmail-expunge-and-save () | |
405 "Expunge and save RMAIL file." | |
406 (interactive) | |
407 (rmail-expunge) | |
408 (save-buffer)) | |
409 | |
410 (defun rmail-quit () | |
411 "Quit out of RMAIL." | |
412 (interactive) | |
413 (rmail-expunge-and-save) | |
414 ;; Don't switch to the summary buffer even if it was recently visible. | |
415 (if rmail-summary-buffer | |
416 (bury-buffer rmail-summary-buffer)) | |
417 (let ((obuf (current-buffer))) | |
418 (switch-to-buffer (other-buffer)) | |
419 (bury-buffer obuf))) | |
420 | |
421 ;;;###autoload | |
422 (defun rmail-input (filename) | |
423 "Run RMAIL on file FILENAME." | |
424 (interactive "FRun rmail on RMAIL file: ") | |
425 (rmail filename)) | |
426 | |
427 | |
428 ;;;; *** Rmail input *** | |
429 | |
430 ;; RLK feature not added in this version: | |
431 ;; argument specifies inbox file or files in various ways. | |
432 | |
433 (defun rmail-get-new-mail (&optional file-name) | |
434 "Move any new mail from this RMAIL file's inbox files. | |
435 The inbox files can be specified with the file's Mail: option. The | |
436 variable `rmail-primary-inbox-list' specifies the inboxes for your | |
437 primary RMAIL file if it has no Mail: option. These are normally your | |
438 ~/mbox and your /usr/spool/mail/$USER. | |
439 | |
440 You can also specify the file to get new mail from. In this case, the | |
441 file of new mail is not changed or deleted. Noninteractively, you can | |
442 pass the inbox file name as an argument. Interactively, a prefix | |
443 argument causes us to read a file name and use that file as the inbox." | |
444 (interactive | |
445 (list (if current-prefix-arg | |
446 (read-file-name "Get new mail from file: ")))) | |
447 (or (verify-visited-file-modtime (current-buffer)) | |
448 (progn | |
449 (find-file (buffer-file-name)) | |
450 (if (verify-visited-file-modtime (current-buffer)) | |
451 (rmail-forget-messages)))) | |
452 (rmail-maybe-set-message-counters) | |
453 (widen) | |
454 ;; Get rid of all undo records for this buffer. | |
455 (or (eq buffer-undo-list t) | |
456 (setq buffer-undo-list nil)) | |
457 (unwind-protect | |
458 (let ((opoint (point)) | |
459 (new-messages 0) | |
460 (delete-files ()) | |
461 ;; If buffer has not changed yet, and has not been saved yet, | |
462 ;; don't replace the old backup file now. | |
463 (make-backup-files (and make-backup-files (buffer-modified-p))) | |
464 (buffer-read-only nil) | |
465 ;; Don't make undo records for what we do in getting mail. | |
466 (buffer-undo-list t)) | |
467 (goto-char (point-max)) | |
468 (skip-chars-backward " \t\n") ; just in case of brain damage | |
469 (delete-region (point) (point-max)) ; caused by require-final-newline | |
470 (save-excursion | |
471 (save-restriction | |
472 (narrow-to-region (point) (point)) | |
473 ;; Read in the contents of the inbox files, | |
474 ;; renaming them as necessary, | |
475 ;; and adding to the list of files to delete eventually. | |
476 (if file-name | |
477 (rmail-insert-inbox-text (list file-name) nil) | |
478 (setq delete-files (rmail-insert-inbox-text rmail-inbox-list t))) | |
479 ;; Scan the new text and convert each message to babyl format. | |
480 (goto-char (point-min)) | |
481 (save-excursion | |
482 (setq new-messages (rmail-convert-to-babyl-format))) | |
483 (or (zerop new-messages) | |
484 (let (success) | |
485 (widen) | |
486 (search-backward "\n\^_") | |
487 (narrow-to-region (point) (point-max)) | |
488 (goto-char (1+ (point-min))) | |
489 (rmail-count-new-messages) | |
490 (save-buffer))) | |
491 ;; Delete the old files, now that babyl file is saved. | |
492 (while delete-files | |
493 (condition-case () | |
494 (delete-file (car delete-files)) | |
495 (file-error nil)) | |
496 (setq delete-files (cdr delete-files))))) | |
497 (if (= new-messages 0) | |
498 (progn (goto-char opoint) | |
499 (if (or file-name rmail-inbox-list) | |
500 (message "(No new mail has arrived)"))) | |
501 (message "%d new message%s read" | |
502 new-messages (if (= 1 new-messages) "" "s")) | |
503 (and (boundp 'display-time-string) | |
504 (string-match " Mail" display-time-string) | |
505 (setq display-time-string | |
506 (concat | |
507 (substring display-time-string 0 (match-beginning 0)) | |
508 (substring display-time-string (match-end 0)))) | |
509 (force-mode-line-update 'all)))) | |
510 ;; Don't leave the buffer screwed up if we get a disk-full error. | |
511 (rmail-show-message))) | |
512 | |
513 (defun rmail-insert-inbox-text (files renamep) | |
514 (let (file tofile delete-files movemail) | |
515 (while files | |
516 (setq file (expand-file-name (substitute-in-file-name (car files))) | |
517 ;;>> un*x specific << | |
813 | 518 ;; The "+" used to be "~", which is an extremely poor choice; |
519 ;; it might accidentally be deleted when space is low | |
520 ;; (as happened to me!). | |
521 tofile (concat file "+")) | |
270 | 522 ;; If getting from mail spool directory, |
523 ;; use movemail to move rather than just renaming, | |
524 ;; so as to interlock with the mailer. | |
525 (setq movemail (equal (file-name-directory file) rmail-spool-directory)) | |
526 (if movemail | |
527 (progn | |
528 (setq tofile (expand-file-name | |
529 ;; Generate name to move to from inbox name, | |
530 ;; in case of multiple inboxes that need moving. | |
531 (concat ".newmail-" (file-name-nondirectory file)) | |
532 (file-name-directory | |
533 (expand-file-name rmail-file-name)))) | |
534 ;; On some systems, /usr/spool/mail/foo is a directory | |
535 ;; and the actual inbox is /usr/spool/mail/foo/foo. | |
536 (if (file-directory-p file) | |
537 (setq file (expand-file-name (user-original-login-name) | |
538 file))))) | |
539 (if (or (file-exists-p tofile) (file-exists-p file)) | |
540 (message "Getting mail from %s..." file)) | |
541 ;; Set TOFILE if have not already done so, and | |
542 ;; rename or copy the file FILE to TOFILE if and as appropriate. | |
543 (cond ((not renamep) | |
544 (setq tofile file)) | |
545 ((or (file-exists-p tofile) (not (file-exists-p file))) | |
546 nil) | |
547 ((not movemail) | |
548 (rename-file file tofile nil)) | |
549 (t | |
550 (let ((errors nil)) | |
551 (unwind-protect | |
552 (save-excursion | |
553 (setq errors (generate-new-buffer " *rmail loss*")) | |
554 (buffer-disable-undo errors) | |
555 (call-process | |
556 (expand-file-name "movemail" exec-directory) | |
557 nil errors nil file tofile) | |
558 (if (not (buffer-modified-p errors)) | |
559 ;; No output => movemail won | |
560 nil | |
561 (set-buffer errors) | |
562 (subst-char-in-region (point-min) (point-max) | |
563 ?\n ?\ ) | |
564 (goto-char (point-max)) | |
565 (skip-chars-backward " \t") | |
566 (delete-region (point) (point-max)) | |
567 (goto-char (point-min)) | |
568 (if (looking-at "movemail: ") | |
569 (delete-region (point-min) (match-end 0))) | |
570 (beep t) | |
571 (message (concat "movemail: " | |
572 (buffer-substring (point-min) | |
573 (point-max)))) | |
574 (sit-for 3) | |
575 nil)) | |
576 (if errors (kill-buffer errors)))))) | |
577 ;; At this point, TOFILE contains the name to read: | |
578 ;; Either the alternate name (if we renamed) | |
579 ;; or the actual inbox (if not renaming). | |
580 (if (file-exists-p tofile) | |
581 (let (size) | |
582 (goto-char (point-max)) | |
583 (setq size (nth 1 (insert-file-contents tofile))) | |
584 (goto-char (point-max)) | |
585 (or (= (preceding-char) ?\n) | |
586 (zerop size) | |
587 (insert ?\n)) | |
588 (setq delete-files (cons tofile delete-files)))) | |
589 (message "") | |
590 (setq files (cdr files))) | |
591 delete-files)) | |
592 | |
593 ;; the rmail-break-forwarded-messages feature is not implemented | |
594 (defun rmail-convert-to-babyl-format () | |
595 (let ((count 0) start | |
402
14485c6a56aa
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
346
diff
changeset
|
596 (case-fold-search nil) |
14485c6a56aa
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
346
diff
changeset
|
597 (invalid-input-resync |
14485c6a56aa
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
346
diff
changeset
|
598 (function (lambda () |
14485c6a56aa
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
346
diff
changeset
|
599 (message "Invalid Babyl format in inbox!") |
14485c6a56aa
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
346
diff
changeset
|
600 (sit-for 1) |
14485c6a56aa
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
346
diff
changeset
|
601 ;; Try to get back in sync with a real message. |
14485c6a56aa
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
346
diff
changeset
|
602 (if (re-search-forward |
14485c6a56aa
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
346
diff
changeset
|
603 (concat mmdf-delim1 "\\|^From") nil t) |
14485c6a56aa
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
346
diff
changeset
|
604 (beginning-of-line) |
14485c6a56aa
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
346
diff
changeset
|
605 (goto-char (point-max))))))) |
270 | 606 (goto-char (point-min)) |
607 (save-restriction | |
608 (while (not (eobp)) | |
609 (cond ((looking-at "BABYL OPTIONS:");Babyl header | |
402
14485c6a56aa
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
346
diff
changeset
|
610 (if (search-forward "\n\^_" nil t) |
14485c6a56aa
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
346
diff
changeset
|
611 ;; If we find the proper terminator, delete through there. |
14485c6a56aa
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
346
diff
changeset
|
612 (delete-region (point-min) (point)) |
14485c6a56aa
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
346
diff
changeset
|
613 (funcall invalid-input-resync) |
405
698d5d6e8f8b
*** empty log message ***
Michael I. Bushnell <mib@gnu.org>
parents:
403
diff
changeset
|
614 (delete-region (point-min) (point)))) |
270 | 615 ;; Babyl format message |
616 ((looking-at "\^L") | |
617 (or (search-forward "\n\^_" nil t) | |
402
14485c6a56aa
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
346
diff
changeset
|
618 (funcall invalid-input-resync)) |
270 | 619 (setq count (1+ count)) |
620 ;; Make sure there is no extra white space after the ^_ | |
621 ;; at the end of the message. | |
622 ;; Narrowing will make sure that whatever follows the junk | |
623 ;; will be treated properly. | |
624 (delete-region (point) | |
625 (save-excursion | |
626 (skip-chars-forward " \t\n") | |
627 (point))) | |
628 (narrow-to-region (point) (point-max))) | |
629 ;;*** MMDF format | |
630 ((let ((case-fold-search t)) | |
631 (looking-at mmdf-delim1)) | |
632 (let ((case-fold-search t)) | |
633 (replace-match "\^L\n0, unseen,,\n*** EOOH ***\n") | |
634 (setq start (point)) | |
635 (re-search-forward mmdf-delim2 nil t) | |
636 (replace-match "\^_")) | |
637 (save-excursion | |
638 (save-restriction | |
639 (narrow-to-region start (1- (point))) | |
640 (goto-char (point-min)) | |
641 (while (search-forward "\n\^_" nil t); single char "\^_" | |
642 (replace-match "\n^_")))); 2 chars: "^" and "_" | |
643 (narrow-to-region (point) (point-max)) | |
644 (setq count (1+ count))) | |
645 ;;*** Mail format | |
646 ((looking-at "^From ") | |
647 (setq start (point)) | |
648 (insert "\^L\n0, unseen,,\n*** EOOH ***\n") | |
649 (rmail-nuke-pinhead-header) | |
650 (if (re-search-forward | |
651 (concat "^[\^_]?\\(" | |
617 | 652 rmail-unix-mail-delimiter |
653 "\\|" | |
270 | 654 mmdf-delim1 "\\|" |
655 "^BABYL OPTIONS:\\|" | |
656 "\^L\n[01],\\)") nil t) | |
657 (goto-char (match-beginning 1)) | |
658 (goto-char (point-max))) | |
659 (setq count (1+ count)) | |
660 (save-excursion | |
661 (save-restriction | |
662 (narrow-to-region start (point)) | |
663 (goto-char (point-min)) | |
664 (while (search-forward "\n\^_" nil t); single char | |
665 (replace-match "\n^_")))); 2 chars: "^" and "_" | |
666 (insert ?\^_) | |
667 (narrow-to-region (point) (point-max))) | |
668 ;; | |
669 ;;This is a kludge, in case we're wrong about mmdf not | |
670 ;;allowing anything in between. If it loses, we'll have | |
671 ;;to look for something else | |
405
698d5d6e8f8b
*** empty log message ***
Michael I. Bushnell <mib@gnu.org>
parents:
403
diff
changeset
|
672 (t (error "Cannot convert to babyl format"))))) |
270 | 673 count)) |
674 | |
675 ;; Delete the "From ..." line, creating various other headers with | |
676 ;; information from it if they don't already exist. Now puts the | |
677 ;; original line into a mail-from: header line for debugging. | |
678 (defun rmail-nuke-pinhead-header () | |
679 (save-excursion | |
680 (save-restriction | |
681 (let ((start (point)) | |
682 (end (progn | |
683 (condition-case () | |
684 (search-forward "\n\n") | |
685 (error | |
686 (goto-char (point-max)) | |
687 (insert "\n\n"))) | |
688 (point))) | |
689 has-from has-date) | |
690 (narrow-to-region start end) | |
691 (let ((case-fold-search t)) | |
692 (goto-char start) | |
693 (setq has-from (search-forward "\nFrom:" nil t)) | |
694 (goto-char start) | |
695 (setq has-date (and (search-forward "\nDate:" nil t) (point))) | |
696 (goto-char start)) | |
697 (let ((case-fold-search nil)) | |
617 | 698 (if (re-search-forward (concat "^" rmail-unix-mail-delimiter) nil t) |
270 | 699 (replace-match |
700 (concat | |
701 "Mail-from: \\&" | |
702 ;; Keep and reformat the date if we don't | |
703 ;; have a Date: field. | |
704 (if has-date | |
705 "" | |
706 ;; If no time zone specified, assume est. | |
707 (if (= (match-beginning 7) (match-end 7)) | |
617 | 708 "Date: \\3, \\5 \\4 \\9 \\6 EST\n" |
709 "Date: \\3, \\5 \\4 \\9 \\6\\7\n")) | |
270 | 710 ;; Keep and reformat the sender if we don't |
711 ;; have a From: field. | |
712 (if has-from | |
713 "" | |
714 "From: \\1\n"))))))))) | |
715 | |
716 ;;;; *** Rmail Message Formatting and Header Manipulation *** | |
717 | |
718 (defun rmail-reformat-message (beg end) | |
719 (goto-char beg) | |
720 (forward-line 1) | |
721 (if (/= (following-char) ?0) | |
722 (error "Bad format in RMAIL file.")) | |
723 (let ((buffer-read-only nil) | |
724 (delta (- (buffer-size) end))) | |
725 (delete-char 1) | |
726 (insert ?1) | |
727 (forward-line 1) | |
728 (if (looking-at "Summary-line: ") | |
729 (forward-line 1)) | |
730 (if (looking-at "\\*\\*\\* EOOH \\*\\*\\*\n") | |
731 (delete-region (point) | |
732 (progn (forward-line 1) (point)))) | |
733 (let ((str (buffer-substring (point) | |
734 (save-excursion (search-forward "\n\n" end 'move) | |
735 (point))))) | |
736 (insert str "*** EOOH ***\n") | |
737 (narrow-to-region (point) (- (buffer-size) delta))) | |
738 (goto-char (point-min)) | |
739 (if rmail-ignored-headers (rmail-clear-headers)) | |
740 (if rmail-message-filter (funcall rmail-message-filter)))) | |
741 | |
742 (defun rmail-clear-headers () | |
743 (if (search-forward "\n\n" nil t) | |
744 (save-restriction | |
745 (narrow-to-region (point-min) (point)) | |
746 (let ((buffer-read-only nil)) | |
747 (while (let ((case-fold-search t)) | |
748 (goto-char (point-min)) | |
749 (re-search-forward rmail-ignored-headers nil t)) | |
750 (beginning-of-line) | |
751 (delete-region (point) | |
752 (progn (re-search-forward "\n[^ \t]") | |
753 (forward-char -1) | |
754 (point)))))))) | |
755 | |
756 (defun rmail-toggle-header () | |
757 "Show original message header if pruned header currently shown, or vice versa." | |
758 (interactive) | |
759 (rmail-maybe-set-message-counters) | |
760 (narrow-to-region (rmail-msgbeg rmail-current-message) (point-max)) | |
761 (let ((buffer-read-only nil)) | |
762 (goto-char (point-min)) | |
763 (forward-line 1) | |
764 (if (= (following-char) ?1) | |
765 (progn (delete-char 1) | |
766 (insert ?0) | |
767 (forward-line 1) | |
768 (if (looking-at "Summary-Line:") | |
769 (forward-line 1)) | |
770 (insert "*** EOOH ***\n") | |
771 (forward-char -1) | |
772 (search-forward "\n*** EOOH ***\n") | |
773 (forward-line -1) | |
774 (let ((temp (point))) | |
775 (and (search-forward "\n\n" nil t) | |
776 (delete-region temp (point)))) | |
777 (goto-char (point-min)) | |
778 (search-forward "\n*** EOOH ***\n") | |
779 (narrow-to-region (point) (point-max))) | |
780 (rmail-reformat-message (point-min) (point-max))))) | |
781 | |
782 ;;;; *** Rmail Attributes and Keywords *** | |
783 | |
784 ;; Make a string describing current message's attributes and keywords | |
785 ;; and set it up as the name of a minor mode | |
786 ;; so it will appear in the mode line. | |
787 (defun rmail-display-labels () | |
788 (let ((blurb "") (beg (point-min-marker)) (end (point-max-marker))) | |
789 (save-excursion | |
790 (unwind-protect | |
791 (progn | |
792 (widen) | |
793 (goto-char (rmail-msgbeg rmail-current-message)) | |
794 (forward-line 1) | |
795 (if (looking-at "[01],") | |
796 (progn | |
797 (narrow-to-region (point) (progn (end-of-line) (point))) | |
798 ;; Truly valid BABYL format requires a space before each | |
799 ;; attribute or keyword name. Put them in if missing. | |
800 (let (buffer-read-only) | |
801 (goto-char (point-min)) | |
802 (while (search-forward "," nil t) | |
803 (or (looking-at "[ ,]") (eobp) | |
804 (insert " ")))) | |
805 (goto-char (point-max)) | |
806 (if (search-backward ",," nil 'move) | |
807 (progn | |
808 (if (> (point) (1+ (point-min))) | |
809 (setq blurb (buffer-substring (+ 1 (point-min)) (point)))) | |
810 (if (> (- (point-max) (point)) 2) | |
811 (setq blurb | |
812 (concat blurb | |
813 ";" | |
814 (buffer-substring (+ (point) 3) | |
815 (1- (point-max))))))))))) | |
816 ;; Note: we don't use save-restriction because that does not work right | |
817 ;; if changes are made outside the saved restriction | |
818 ;; before that restriction is restored. | |
819 (narrow-to-region beg end) | |
820 (set-marker beg nil) | |
821 (set-marker end nil))) | |
822 (while (string-match " +," blurb) | |
823 (setq blurb (concat (substring blurb 0 (match-beginning 0)) "," | |
824 (substring blurb (match-end 0))))) | |
825 (while (string-match ", +" blurb) | |
826 (setq blurb (concat (substring blurb 0 (match-beginning 0)) "," | |
827 (substring blurb (match-end 0))))) | |
828 (setq mode-line-process | |
829 (concat " " rmail-current-message "/" rmail-total-messages | |
830 blurb)))) | |
831 | |
832 ;; Turn an attribute of a message on or off according to STATE. | |
833 ;; ATTR is the name of the attribute, as a string. | |
834 ;; MSGNUM is message number to change; nil means current message. | |
835 (defun rmail-set-attribute (attr state &optional msgnum) | |
836 (let ((omax (point-max-marker)) | |
837 (omin (point-min-marker)) | |
838 (buffer-read-only nil)) | |
839 (or msgnum (setq msgnum rmail-current-message)) | |
840 (unwind-protect | |
841 (save-excursion | |
842 (widen) | |
843 (goto-char (+ 3 (rmail-msgbeg msgnum))) | |
844 (let ((curstate | |
845 (not | |
846 (null (search-backward (concat ", " attr ",") | |
847 (prog1 (point) (end-of-line)) t))))) | |
848 (or (eq curstate (not (not state))) | |
849 (if curstate | |
850 (delete-region (point) (1- (match-end 0))) | |
851 (beginning-of-line) | |
852 (forward-char 2) | |
853 (insert " " attr ",")))) | |
854 (if (string= attr "deleted") | |
855 (rmail-set-message-deleted-p msgnum state))) | |
856 ;; Note: we don't use save-restriction because that does not work right | |
857 ;; if changes are made outside the saved restriction | |
858 ;; before that restriction is restored. | |
859 (narrow-to-region omin omax) | |
860 (set-marker omin nil) | |
861 (set-marker omax nil) | |
862 (if (= msgnum rmail-current-message) | |
863 (rmail-display-labels))))) | |
864 | |
865 ;; Return t if the attributes/keywords line of msg number MSG | |
866 ;; contains a match for the regexp LABELS. | |
867 (defun rmail-message-labels-p (msg labels) | |
868 (save-excursion | |
869 (save-restriction | |
870 (widen) | |
871 (goto-char (rmail-msgbeg msg)) | |
872 (forward-char 3) | |
873 (re-search-backward labels (prog1 (point) (end-of-line)) t)))) | |
874 | |
875 ;;;; *** Rmail Message Selection And Support *** | |
876 | |
877 (defun rmail-msgend (n) | |
878 (marker-position (aref rmail-message-vector (1+ n)))) | |
879 | |
880 (defun rmail-msgbeg (n) | |
881 (marker-position (aref rmail-message-vector n))) | |
882 | |
883 (defun rmail-widen-to-current-msgbeg (function) | |
884 "Call FUNCTION with point at start of internal data of current message. | |
885 Assumes that bounds were previously narrowed to display the message in Rmail. | |
886 The bounds are widened enough to move point where desired, then narrowed | |
887 again afterward. | |
888 | |
889 FUNCTION may not change the visible text of the message, but it may | |
890 change the invisible header text." | |
891 (save-excursion | |
344 | 892 (let ((obeg (- (point-max) (point-min)))) |
270 | 893 (unwind-protect |
894 (progn | |
895 (narrow-to-region (rmail-msgbeg rmail-current-message) | |
896 (point-max)) | |
897 (goto-char (point-min)) | |
898 (funcall function)) | |
899 ;; Note: we don't use save-restriction because that does not work right | |
900 ;; if changes are made outside the saved restriction | |
901 ;; before that restriction is restored. | |
902 ;; Here we assume that changes made by FUNCTION | |
903 ;; occur before the visible region of the message. | |
344 | 904 (narrow-to-region (- (point-max) obeg) (point-max)))))) |
270 | 905 |
906 (defun rmail-forget-messages () | |
907 (unwind-protect | |
908 (if (vectorp rmail-message-vector) | |
909 (let* ((i 0) | |
910 (v rmail-message-vector) | |
911 (n (length v))) | |
912 (while (< i n) | |
913 (move-marker (aref v i) nil) | |
914 (setq i (1+ i))))) | |
915 (setq rmail-message-vector nil) | |
916 (setq rmail-deleted-vector nil))) | |
917 | |
918 (defun rmail-maybe-set-message-counters () | |
919 (if (not (and rmail-deleted-vector | |
920 rmail-message-vector | |
921 rmail-current-message | |
922 rmail-total-messages)) | |
923 (rmail-set-message-counters))) | |
924 | |
925 (defun rmail-count-new-messages (&optional nomsg) | |
926 (let* ((case-fold-search nil) | |
927 (total-messages 0) | |
928 (messages-head nil) | |
929 (deleted-head nil)) | |
930 (or nomsg (message "Counting new messages...")) | |
931 (goto-char (point-max)) | |
932 ;; Put at the end of messages-head | |
933 ;; the entry for message N+1, which marks | |
934 ;; the end of message N. (N = number of messages). | |
935 (search-backward "\n\^_") | |
936 (forward-char 1) | |
937 (setq messages-head (list (point-marker))) | |
938 (rmail-set-message-counters-counter (point-min)) | |
939 (setq rmail-current-message (1+ rmail-total-messages)) | |
940 (setq rmail-total-messages | |
941 (+ rmail-total-messages total-messages)) | |
942 (setq rmail-message-vector | |
943 (vconcat rmail-message-vector (cdr messages-head))) | |
944 (aset rmail-message-vector | |
945 rmail-current-message (car messages-head)) | |
946 (setq rmail-deleted-vector | |
947 (concat rmail-deleted-vector deleted-head)) | |
948 (setq rmail-summary-vector | |
949 (vconcat rmail-summary-vector (make-vector total-messages nil))) | |
950 (goto-char (point-min)) | |
951 (or nomsg (message "Counting new messages...done (%d)" total-messages)))) | |
952 | |
953 (defun rmail-set-message-counters () | |
954 (rmail-forget-messages) | |
955 (save-excursion | |
956 (save-restriction | |
957 (widen) | |
958 (let* ((point-save (point)) | |
959 (total-messages 0) | |
960 (messages-after-point) | |
961 (case-fold-search nil) | |
962 (messages-head nil) | |
963 (deleted-head nil)) | |
964 (message "Counting messages...") | |
965 (goto-char (point-max)) | |
966 ;; Put at the end of messages-head | |
967 ;; the entry for message N+1, which marks | |
968 ;; the end of message N. (N = number of messages). | |
969 (search-backward "\n\^_") | |
970 (forward-char 1) | |
971 (setq messages-head (list (point-marker))) | |
972 (rmail-set-message-counters-counter (min (point) point-save)) | |
973 (setq messages-after-point total-messages) | |
974 (rmail-set-message-counters-counter) | |
975 (setq rmail-total-messages total-messages) | |
976 (setq rmail-current-message | |
977 (min total-messages | |
978 (max 1 (- total-messages messages-after-point)))) | |
979 (setq rmail-message-vector | |
980 (apply 'vector (cons (point-min-marker) messages-head)) | |
981 rmail-deleted-vector (concat "D" deleted-head) | |
982 rmail-summary-vector (make-vector rmail-total-messages nil)) | |
983 (message "Counting messages...done"))))) | |
984 | |
985 (defun rmail-set-message-counters-counter (&optional stop) | |
986 (while (search-backward "\n\^_\^L\n" stop t) | |
987 (forward-char 1) | |
988 (setq messages-head (cons (point-marker) messages-head)) | |
989 (save-excursion | |
990 (setq deleted-head | |
991 (cons (if (search-backward ", deleted," | |
992 (prog1 (point) | |
993 (forward-line 2)) | |
994 t) | |
995 ?D ?\ ) | |
996 deleted-head))) | |
997 (if (zerop (% (setq total-messages (1+ total-messages)) 20)) | |
998 (message "Counting messages...%d" total-messages)))) | |
999 | |
1000 (defun rmail-beginning-of-message () | |
1001 "Show current message starting from the beginning." | |
1002 (interactive) | |
1003 (rmail-show-message rmail-current-message)) | |
1004 | |
1005 (defun rmail-show-message (&optional n) | |
1006 "Show message number N (prefix argument), counting from start of file." | |
1007 (interactive "p") | |
1008 (rmail-maybe-set-message-counters) | |
1009 (widen) | |
1010 (if (zerop rmail-total-messages) | |
1011 (progn (narrow-to-region (point-min) (1- (point-max))) | |
1012 (goto-char (point-min)) | |
1013 (setq mode-line-process nil)) | |
1014 (let (blurb) | |
1015 (if (not n) | |
1016 (setq n rmail-current-message) | |
1017 (cond ((<= n 0) | |
1018 (setq n 1 | |
1019 rmail-current-message 1 | |
1020 blurb "No previous message")) | |
1021 ((> n rmail-total-messages) | |
1022 (setq n rmail-total-messages | |
1023 rmail-current-message rmail-total-messages | |
1024 blurb "No following message")) | |
1025 (t | |
1026 (setq rmail-current-message n)))) | |
1027 (let ((beg (rmail-msgbeg n)) | |
1028 (end (rmail-msgend n))) | |
1029 (goto-char beg) | |
1030 (forward-line 1) | |
1031 (if (= (following-char) ?0) | |
1032 (progn | |
1033 (rmail-reformat-message beg end) | |
1034 (rmail-set-attribute "unseen" nil)) | |
1035 (search-forward "\n*** EOOH ***\n" end t) | |
1036 (narrow-to-region (point) end)) | |
1037 (goto-char (point-min)) | |
1038 (rmail-display-labels) | |
1039 (run-hooks 'rmail-show-message-hook) | |
1040 (if blurb | |
1041 (message blurb)))))) | |
1042 | |
1043 (defun rmail-next-message (n) | |
1044 "Show following message whether deleted or not. | |
1045 With prefix arg N, moves forward N messages, or backward if N is negative." | |
1046 (interactive "p") | |
1047 (rmail-maybe-set-message-counters) | |
1048 (rmail-show-message (+ rmail-current-message n))) | |
1049 | |
1050 (defun rmail-previous-message (n) | |
1051 "Show previous message whether deleted or not. | |
1052 With prefix arg N, moves backward N messages, or forward if N is negative." | |
1053 (interactive "p") | |
1054 (rmail-next-message (- n))) | |
1055 | |
1056 (defun rmail-next-undeleted-message (n) | |
1057 "Show following non-deleted message. | |
1058 With prefix arg N, moves forward N non-deleted messages, | |
1059 or backward if N is negative." | |
1060 (interactive "p") | |
1061 (rmail-maybe-set-message-counters) | |
1062 (let ((lastwin rmail-current-message) | |
1063 (current rmail-current-message)) | |
1064 (while (and (> n 0) (< current rmail-total-messages)) | |
1065 (setq current (1+ current)) | |
1066 (if (not (rmail-message-deleted-p current)) | |
1067 (setq lastwin current n (1- n)))) | |
1068 (while (and (< n 0) (> current 1)) | |
1069 (setq current (1- current)) | |
1070 (if (not (rmail-message-deleted-p current)) | |
1071 (setq lastwin current n (1+ n)))) | |
1072 (if (/= lastwin rmail-current-message) | |
1073 (rmail-show-message lastwin)) | |
1074 (if (< n 0) | |
1075 (error "No previous nondeleted message")) | |
1076 (if (> n 0) | |
1077 (error "No following nondeleted message")))) | |
1078 | |
1079 (defun rmail-previous-undeleted-message (n) | |
1080 "Show previous non-deleted message. | |
1081 With prefix argument N, moves backward N non-deleted messages, | |
1082 or forward if N is negative." | |
1083 (interactive "p") | |
1084 (rmail-next-undeleted-message (- n))) | |
1085 | |
1086 (defun rmail-first-message () | |
1087 "Show first message in file." | |
1088 (interactive) | |
1089 (rmail-maybe-set-message-counters) | |
1090 (rmail-show-message 1)) | |
1091 | |
1092 (defun rmail-last-message () | |
1093 "Show last message in file." | |
1094 (interactive) | |
1095 (rmail-maybe-set-message-counters) | |
1096 (rmail-show-message rmail-total-messages)) | |
1097 | |
1098 (defun rmail-what-message () | |
1099 (let ((where (point)) | |
1100 (low 1) | |
1101 (high rmail-total-messages) | |
1102 (mid (/ rmail-total-messages 2))) | |
1103 (while (> (- high low) 1) | |
1104 (if (>= where (rmail-msgbeg mid)) | |
1105 (setq low mid) | |
1106 (setq high mid)) | |
1107 (setq mid (+ low (/ (- high low) 2)))) | |
1108 (if (>= where (rmail-msgbeg high)) high low))) | |
1109 | |
1110 (defvar rmail-search-last-regexp nil) | |
1111 (defun rmail-search (regexp &optional reversep) | |
1112 "Show message containing next match for REGEXP. | |
1113 Search in reverse (earlier messages) with non-nil second arg REVERSEP. | |
1114 Interactively, empty argument means use same regexp used last time, | |
1115 and reverse search is specified by a negative numeric arg." | |
1116 (interactive | |
1117 (let* ((reversep (< (prefix-numeric-value current-prefix-arg) 0)) | |
1118 (prompt | |
1119 (concat (if reversep "Reverse " "") "Rmail search (regexp): ")) | |
1120 regexp) | |
1121 (if rmail-search-last-regexp | |
1122 (setq prompt (concat prompt | |
1123 "(default " | |
1124 rmail-search-last-regexp | |
1125 ") "))) | |
1126 (setq regexp (read-string prompt)) | |
1127 (cond ((not (equal regexp "")) | |
1128 (setq rmail-search-last-regexp regexp)) | |
1129 ((not rmail-search-last-regexp) | |
1130 (error "No previous Rmail search string"))) | |
1131 (list rmail-search-last-regexp reversep))) | |
1132 (message "%sRmail search for %s..." | |
1133 (if reversep "Reverse " "") | |
1134 regexp) | |
1135 (rmail-maybe-set-message-counters) | |
1136 (let ((omin (point-min)) | |
1137 (omax (point-max)) | |
1138 (opoint (point)) | |
1139 win | |
1140 (msg rmail-current-message)) | |
1141 (unwind-protect | |
1142 (progn | |
1143 (widen) | |
1144 ;; Check messages one by one, advancing message number up or down | |
1145 ;; but searching forward through each message. | |
1146 (if reversep | |
1147 (while (and (null win) (> msg 1)) | |
1148 (goto-char (rmail-msgbeg (setq msg (1- msg)))) | |
1149 (setq win (re-search-forward | |
1150 regexp (rmail-msgend msg) t))) | |
1151 (while (and (null win) (< msg rmail-total-messages)) | |
1152 (goto-char (rmail-msgbeg (setq msg (1+ msg)))) | |
1153 (setq win (re-search-forward regexp (rmail-msgend msg) t))))) | |
1154 (if win | |
1155 (progn | |
1156 ;; If this is a reverse search and we found a message, | |
1157 ;; search backward thru this message to position point. | |
1158 (if reversep | |
1159 (progn | |
1160 (goto-char (rmail-msgend msg)) | |
1161 (re-search-backward | |
1162 regexp (rmail-msgbeg msg) t))) | |
1163 (setq win (point)) | |
1164 (rmail-show-message msg) | |
1165 (message "%sRmail search for %s...done" | |
1166 (if reversep "Reverse " "") | |
1167 regexp) | |
1168 (goto-char win)) | |
1169 (goto-char opoint) | |
1170 (narrow-to-region omin omax) | |
1171 (ding) | |
1172 (message "Search failed: %s" regexp))))) | |
1173 | |
1174 ;; Show the first message which has the `unseen' attribute. | |
1175 (defun rmail-first-unseen-message () | |
1176 (let ((current 1) | |
1177 found) | |
1178 (save-restriction | |
1179 (widen) | |
1180 (while (and (not found) (< current rmail-total-messages)) | |
1181 (if (rmail-message-labels-p current ", ?\\(unseen\\),") | |
346 | 1182 (setq found current)) |
1183 (setq current (1+ current)))) | |
270 | 1184 (if found |
1185 (rmail-show-message found)))) | |
1186 | |
1187 ;;;; *** Rmail Message Deletion Commands *** | |
1188 | |
1189 (defun rmail-message-deleted-p (n) | |
1190 (= (aref rmail-deleted-vector n) ?D)) | |
1191 | |
1192 (defun rmail-set-message-deleted-p (n state) | |
1193 (aset rmail-deleted-vector n (if state ?D ?\ ))) | |
1194 | |
1195 (defun rmail-delete-message () | |
1196 "Delete this message and stay on it." | |
1197 (interactive) | |
1198 (rmail-set-attribute "deleted" t)) | |
1199 | |
1200 (defun rmail-undelete-previous-message () | |
1201 "Back up to deleted message, select it, and undelete it." | |
1202 (interactive) | |
1203 (let ((msg rmail-current-message)) | |
1204 (while (and (> msg 0) | |
1205 (not (rmail-message-deleted-p msg))) | |
1206 (setq msg (1- msg))) | |
1207 (if (= msg 0) | |
1208 (error "No previous deleted message") | |
1209 (if (/= msg rmail-current-message) | |
1210 (rmail-show-message msg)) | |
1211 (rmail-set-attribute "deleted" nil)))) | |
1212 | |
1213 (defun rmail-delete-forward (&optional backward) | |
1214 "Delete this message and move to next nondeleted one. | |
1215 Deleted messages stay in the file until the \\[rmail-expunge] command is given. | |
819
5bbabfcef929
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
814
diff
changeset
|
1216 With prefix argument, delete and move backward." |
270 | 1217 (interactive "P") |
1218 (rmail-set-attribute "deleted" t) | |
830
d7f1e2db9faf
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
819
diff
changeset
|
1219 (rmail-next-undeleted-message (if backward -1 1))) |
270 | 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 |