annotate lisp/rmail/rmailout.el @ 70:131b0175ea99 r20-0b30

Import from CVS: tag r20-0b30
author cvs
date Mon, 13 Aug 2007 09:02:59 +0200
parents 0293115a14e9
children 364816949b59
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; rmailout.el --- "RMAIL" mail reader for Emacs: output message to a file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1985, 1987, 1993 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Maintainer: FSF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Keywords: mail
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
21 ;; along with XEmacs; see the file COPYING. If not, write to the
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
23 ;; Boston, MA 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;; Temporary until Emacs always has this variable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 (defvar rmail-delete-after-output nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 "*Non-nil means automatically delete a message that is copied to a file.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 (defvar rmail-output-file-alist nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 "*Alist matching regexps to suggested output Rmail files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 This is a list of elements of the form (REGEXP . NAME-EXP).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 The suggestion is taken if REGEXP matches anywhere in the message buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 NAME-EXP may be a string constant giving the file name to use,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 or more generally it may be any kind of expression that returns
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 a file name as a string.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;;; There are functions elsewhere in Emacs that use this function; check
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;;; them out before you change the calling method.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (defun rmail-output-to-rmail-file (file-name &optional count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 "Append the current message to an Rmail file named FILE-NAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 If the file does not exist, ask if it should be created.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 If file is being visited, the message is appended to the Emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 buffer visiting that file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 If the file exists and is not an Rmail file,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 the message is appended in inbox format.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 A prefix argument N says to output N consecutive messages
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 starting with the current one. Deleted messages are skipped and don't count."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (let ((default-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (let (answer tail)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (setq tail rmail-output-file-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;; Suggest a file based on a pattern match.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (while (and tail (not answer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (if (re-search-forward (car (car tail)) nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (setq answer (eval (cdr (car tail)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (setq tail (cdr tail))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ;; If not suggestions, use same file as last time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (or answer rmail-last-rmail-file))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (list (setq rmail-last-rmail-file
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
65 (read-file-name
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
66 (concat "Output message to Rmail file: (default "
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
67 (file-name-nondirectory default-file)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
68 ") ")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
69 (file-name-directory default-file)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
70 default-file))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (prefix-numeric-value current-prefix-arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (or count (setq count 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (setq file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (expand-file-name file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (file-name-directory rmail-last-rmail-file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (if (and (file-readable-p file-name) (not (rmail-file-p file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (rmail-output file-name count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (rmail-maybe-set-message-counters)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (setq file-name (abbreviate-file-name file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (or (get-file-buffer file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (file-exists-p file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (if (yes-or-no-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (concat "\"" file-name "\" does not exist, create it? "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (let ((file-buffer (create-file-buffer file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (set-buffer file-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (rmail-insert-rmail-file-header)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (let ((require-final-newline nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (write-region (point-min) (point-max) file-name t 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (kill-buffer file-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (error "Output file does not exist")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (while (> count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (let (redelete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (if (rmail-message-deleted-p rmail-current-message)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (progn (setq redelete t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (rmail-set-attribute "deleted" nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 ;; Decide whether to append to a file or to an Emacs buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (let ((buf (get-file-buffer file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (cur (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (beg (1+ (rmail-msgbeg rmail-current-message)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (end (1+ (rmail-msgend rmail-current-message))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (if (not buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (append-to-file beg end file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (if (eq buf (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (error "Can't output message to same file it's already in"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 ;; File has been visited, in buffer BUF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (let ((buffer-read-only nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (msg (and (boundp 'rmail-current-message)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 rmail-current-message)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 ;; If MSG is non-nil, buffer is in RMAIL mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (if msg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (rmail-maybe-set-message-counters)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (narrow-to-region (point-max) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (insert-buffer-substring cur beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (search-backward "\n\^_")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (narrow-to-region (point) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (rmail-count-new-messages t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (rmail-show-message msg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 ;; Output file not in rmail mode => just insert at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 ;; the end.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (narrow-to-region (point-min) (1+ (buffer-size)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (insert-buffer-substring cur beg end)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (rmail-set-attribute "filed" t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (if redelete (rmail-set-attribute "deleted" t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (setq count (1- count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (if rmail-delete-after-output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (rmail-delete-forward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (if (> count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (rmail-next-undeleted-message 1))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 ;; Returns t if file FILE is an Rmail file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (defun rmail-file-p (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (let ((buf (generate-new-buffer " *rmail-file-p*")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (insert-file-contents file nil 0 100)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (looking-at "BABYL OPTIONS:"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (kill-buffer buf))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 ;;; There are functions elsewhere in Emacs that use this function; check
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 ;;; them out before you change the calling method.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 ;;; ####Boy, FROM-GNUS, what wonderful abstraction. You loser.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (defun rmail-output (file-name &optional count noattribute from-gnus)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 "Append this message to Unix mail file named FILE-NAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 A prefix argument N says to output N consecutive messages
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 starting with the current one. Deleted messages are skipped and don't count.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 When called from lisp code, N may be omitted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 If the pruned message header is shown on the current message, then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 messages will be appended with pruned headers; otherwise, messages
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 will be appended with their original headers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 The optional third argument NOATTRIBUTE, if non-nil, says not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 to set the `filed' attribute, and not to display a message.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 The optional fourth argument FROM-GNUS is set when called from GNUS."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (list (setq rmail-last-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (read-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (concat "Output message to Unix mail file"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (if rmail-last-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (concat " (default "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (file-name-nondirectory rmail-last-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 "): " )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 ": "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (and rmail-last-file (file-name-directory rmail-last-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 rmail-last-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (prefix-numeric-value current-prefix-arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (or count (setq count 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (setq file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (expand-file-name file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (and rmail-last-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (file-name-directory rmail-last-file))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (if (and (file-readable-p file-name) (rmail-file-p file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (rmail-output-to-rmail-file file-name count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (let ((orig-count count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (rmailbuf (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (case-fold-search t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (tembuf (get-buffer-create " rmail-output"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (original-headers-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (and (not from-gnus)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (narrow-to-region (rmail-msgbeg rmail-current-message) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (= (following-char) ?0)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 header-beginning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 mail-from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (while (> count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (or from-gnus
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (setq mail-from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (goto-char (rmail-msgbeg rmail-current-message))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (setq header-beginning (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (search-forward "\n*** EOOH ***\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (narrow-to-region header-beginning (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (mail-fetch-field "Mail-From")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (set-buffer tembuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (insert-buffer-substring rmailbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (insert "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (if mail-from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (insert mail-from "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (insert "From "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (mail-strip-quoted-names (or (mail-fetch-field "from")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (mail-fetch-field "really-from")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (mail-fetch-field "sender")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 "unknown"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 " " (current-time-string) "\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 ;; ``Quote'' "\nFrom " as "\n>From "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 ;; (note that this isn't really quoting, as there is no requirement
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 ;; that "\n[>]+From " be quoted in the same transparent way.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (while (search-forward "\nFrom " nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (forward-char -5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (insert ?>))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (write-region (point-min) (point-max) file-name t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (if noattribute 'nomsg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (or noattribute
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (if (equal major-mode 'rmail-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (rmail-set-attribute "filed" t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (setq count (1- count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (or from-gnus
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (let ((next-message-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (if rmail-delete-after-output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (rmail-delete-forward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (if (> count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (rmail-next-undeleted-message 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (num-appended (- orig-count count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (if (and next-message-p original-headers-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (rmail-toggle-header))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (if (and (> count 0) (not next-message-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (set-buffer rmailbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (format "Only %d message%s appended" num-appended
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (if (= num-appended 1) "" "s"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (setq count 0))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (kill-buffer tembuf))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 ;;; rmailout.el ends here