Mercurial > emacs
annotate lisp/mail/rmailout.el @ 1636:c2bea3f2f8cb
(vc-next-action): Undo previous change.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Fri, 20 Nov 1992 19:33:38 +0000 |
parents | e60eef93a18f |
children | a712cff3b6e7 |
rev | line source |
---|---|
658
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
202
diff
changeset
|
1 ;;; rmailout.el --- "RMAIL" mail reader for Emacs: output message to a file. |
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
202
diff
changeset
|
2 |
845 | 3 ;; Copyright (C) 1985, 1987 Free Software Foundation, Inc. |
4 | |
788
c8d4eb38ebfc
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
713
diff
changeset
|
5 ;; Maintainer: FSF |
814
38b2499cb3e9
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
807
diff
changeset
|
6 ;; Keywords: mail |
788
c8d4eb38ebfc
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
713
diff
changeset
|
7 |
63 | 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:
788
diff
changeset
|
12 ;; the Free Software Foundation; either version 2, or (at your option) |
63 | 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 | |
788
c8d4eb38ebfc
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
713
diff
changeset
|
24 ;;; Code: |
63 | 25 |
26 ;; Temporary until Emacs always has this variable. | |
27 (defvar rmail-delete-after-output nil | |
28 "*Non-nil means automatically delete a message that is copied to a file.") | |
29 | |
145 | 30 (defvar rmail-output-file-alist nil |
31 "*Alist matching regexps to suggested output Rmail files. | |
32 This is a list of elements of the form (REGEXP . FILENAME).") | |
33 | |
63 | 34 (defun rmail-output-to-rmail-file (count file-name) |
35 "Append the current message to an Rmail file named FILE-NAME. | |
36 If the file does not exist, ask if it should be created. | |
37 If file is being visited, the message is appended to the Emacs | |
38 buffer visiting that file. | |
39 A prefix argument N says to output N consecutive messages | |
40 starting with the current one. Deleted messages are skipped and don't count." | |
41 (interactive (list (prefix-numeric-value current-prefix-arg) | |
42 (read-file-name | |
43 (concat "Output message to Rmail file: (default " | |
44 (file-name-nondirectory rmail-last-rmail-file) | |
45 ") ") | |
46 (file-name-directory rmail-last-rmail-file) | |
145 | 47 (let (answer tail) |
48 (setq tail rmail-output-file-alist) | |
49 ;; Suggest a file based on a pattern match. | |
50 (while (and tail (not answer)) | |
51 (save-excursion | |
52 (goto-char (point-min)) | |
53 (if (re-search-forward (car (car tail)) nil t) | |
54 (setq answer (cdr (car tail)))) | |
55 (setq tail (cdr tail)))) | |
56 ;; If not suggestions, use same file as last time. | |
57 (or answer rmail-last-rmail-file))))) | |
202 | 58 (setq file-name |
59 (expand-file-name file-name | |
60 (file-name-directory rmail-last-rmail-file))) | |
63 | 61 (setq rmail-last-rmail-file file-name) |
62 (rmail-maybe-set-message-counters) | |
1460
e60eef93a18f
(rmail-output-to-rmail-file): Call abbreviate-file-name.
Richard M. Stallman <rms@gnu.org>
parents:
845
diff
changeset
|
63 (setq file-name (abbreviate-file-name file-name)) |
63 | 64 (or (get-file-buffer file-name) |
65 (file-exists-p file-name) | |
66 (if (yes-or-no-p | |
67 (concat "\"" file-name "\" does not exist, create it? ")) | |
68 (let ((file-buffer (create-file-buffer file-name))) | |
69 (save-excursion | |
70 (set-buffer file-buffer) | |
71 (rmail-insert-rmail-file-header) | |
72 (let ((require-final-newline nil)) | |
73 (write-region (point-min) (point-max) file-name t 1))) | |
74 (kill-buffer file-buffer)) | |
75 (error "Output file does not exist"))) | |
76 (while (> count 0) | |
77 (let (redelete) | |
78 (unwind-protect | |
79 (progn | |
80 (save-restriction | |
81 (widen) | |
82 (if (rmail-message-deleted-p rmail-current-message) | |
83 (progn (setq redelete t) | |
84 (rmail-set-attribute "deleted" nil))) | |
85 ;; Decide whether to append to a file or to an Emacs buffer. | |
86 (save-excursion | |
87 (let ((buf (get-file-buffer file-name)) | |
88 (cur (current-buffer)) | |
89 (beg (1+ (rmail-msgbeg rmail-current-message))) | |
90 (end (1+ (rmail-msgend rmail-current-message)))) | |
91 (if (not buf) | |
92 (append-to-file beg end file-name) | |
93 (if (eq buf (current-buffer)) | |
94 (error "Can't output message to same file it's already in")) | |
95 ;; File has been visited, in buffer BUF. | |
96 (set-buffer buf) | |
97 (let ((buffer-read-only nil) | |
98 (msg (and (boundp 'rmail-current-message) | |
99 rmail-current-message))) | |
100 ;; If MSG is non-nil, buffer is in RMAIL mode. | |
101 (if msg | |
102 (progn | |
103 (rmail-maybe-set-message-counters) | |
104 (widen) | |
105 (narrow-to-region (point-max) (point-max)) | |
106 (insert-buffer-substring cur beg end) | |
107 (goto-char (point-min)) | |
108 (widen) | |
109 (search-backward "\n\^_") | |
110 (narrow-to-region (point) (point-max)) | |
111 (rmail-count-new-messages t) | |
112 (rmail-show-message msg)) | |
113 ;; Output file not in rmail mode => just insert at the end. | |
114 (narrow-to-region (point-min) (1+ (buffer-size))) | |
115 (goto-char (point-max)) | |
116 (insert-buffer-substring cur beg end))))))) | |
117 (rmail-set-attribute "filed" t)) | |
118 (if redelete (rmail-set-attribute "deleted" t)))) | |
119 (setq count (1- count)) | |
120 (if rmail-delete-after-output | |
121 (rmail-delete-forward) | |
122 (if (> count 0) | |
123 (rmail-next-undeleted-message 1))))) | |
124 | |
125 (defun rmail-output (count file-name) | |
126 "Append this message to Unix mail file named FILE-NAME. | |
127 A prefix argument N says to output N consecutive messages | |
128 starting with the current one. Deleted messages are skipped and don't count." | |
129 (interactive | |
130 (list (prefix-numeric-value current-prefix-arg) | |
131 (read-file-name | |
132 (concat "Output message to Unix mail file" | |
133 (if rmail-last-file | |
134 (concat " (default " | |
135 (file-name-nondirectory rmail-last-file) | |
136 "): " ) | |
137 ": ")) | |
138 (and rmail-last-file (file-name-directory rmail-last-file)) | |
139 rmail-last-file))) | |
202 | 140 (setq file-name |
141 (expand-file-name file-name | |
142 (and rmail-last-file | |
143 (file-name-directory rmail-last-file)))) | |
63 | 144 (setq rmail-last-file file-name) |
145 (while (> count 0) | |
146 (let ((rmailbuf (current-buffer)) | |
147 (tembuf (get-buffer-create " rmail-output")) | |
148 (case-fold-search t)) | |
149 (save-excursion | |
150 (set-buffer tembuf) | |
151 (erase-buffer) | |
152 ;; If we can do it, read a little of the file | |
153 ;; to check whether it is an RMAIL file. | |
154 ;; If it is, don't mess it up. | |
155 (if (fboundp 'insert-partial-file-contents) | |
156 (progn | |
157 (insert-partial-file-contents file-name 0 20) | |
158 (if (looking-at "BABYL OPTIONS:\n") | |
159 (error (save-excursion | |
160 (set-buffer rmailbuf) | |
161 (substitute-command-keys | |
162 "File %s is an RMAIL file; use the \\[rmail-output-to-rmail-file] command")) | |
163 file-name)) | |
164 (erase-buffer))) | |
165 (insert-buffer-substring rmailbuf) | |
166 (insert "\n") | |
167 (goto-char (point-min)) | |
168 (insert "From " | |
169 (mail-strip-quoted-names (or (mail-fetch-field "from") | |
170 (mail-fetch-field "really-from") | |
171 (mail-fetch-field "sender") | |
172 "unknown")) | |
713
9d04c281a9bd
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
658
diff
changeset
|
173 " " (or (mail-fetch-field "date") (current-time-string)) "\n") |
63 | 174 ;; ``Quote'' "\nFrom " as "\n>From " |
175 ;; (note that this isn't really quoting, as there is no requirement | |
176 ;; that "\n[>]+From " be quoted in the same transparent way.) | |
177 (while (search-forward "\nFrom " nil t) | |
178 (forward-char -5) | |
179 (insert ?>)) | |
180 (append-to-file (point-min) (point-max) file-name)) | |
181 (kill-buffer tembuf)) | |
182 (if (equal major-mode 'rmail-mode) | |
183 (rmail-set-attribute "filed" t)) | |
184 (setq count (1- count)) | |
185 (if rmail-delete-after-output | |
186 (rmail-delete-forward) | |
187 (if (> count 0) | |
188 (rmail-next-undeleted-message 1))))) | |
658
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
202
diff
changeset
|
189 |
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
202
diff
changeset
|
190 ;;; rmailout.el ends here |