annotate lisp/vm/vm-save.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children 859a2309aef8
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 ;;; Saving and piping messages under VM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;;; Copyright (C) 1989, 1990, 1993, 1994 Kyle E. Jones
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;;; This program is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;;; it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;;; the Free Software Foundation; either version 1, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;;; This program is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;;; along with this program; if not, write to the Free Software
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 (provide 'vm-save)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; (match-data) returns the match data as MARKERS, often corrupting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; it in the process due to buffer narrowing, and the fact that buffers are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; indexed from 1 while strings are indexed from 0. :-(
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 (defun vm-match-data ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 (let ((index '(9 8 7 6 5 4 3 2 1 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 (list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 (while index
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 (setq list (cons (match-beginning (car index))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 (cons (match-end (car index)) list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 index (cdr index)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 list ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 (defun vm-auto-select-folder (mp auto-folder-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 (condition-case error-data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 (catch 'match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 (let (header alist tuple-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 (setq alist auto-folder-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 (while alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (setq header (vm-get-header-contents (car mp) (car (car alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (if (null header)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (setq tuple-list (cdr (car alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (while tuple-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 (if (let ((case-fold-search vm-auto-folder-case-fold-search))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (string-match (car (car tuple-list)) header))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;; Don't waste time eval'ing an atom.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (if (atom (cdr (car tuple-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (throw 'match (cdr (car tuple-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (let* ((match-data (vm-match-data))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;; allow this buffer to live forever
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (buf (get-buffer-create " *vm-auto-folder*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;; Set up a buffer that matches our cached
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;; match data.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (insert header)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;; It appears that get-buffer-create clobbers the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 ;; match-data.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ;; The match data is off by one because we matched
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;; a string and Emacs indexes strings from 0 and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;; buffers from 1.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ;; Also store-match-data only accepts MARKERS!!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 ;; AUGHGHGH!!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (store-match-data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (function (lambda (n) (and n (vm-marker n))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (function (lambda (n) (and n (1+ n))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 match-data)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (setq result (eval (cdr (car tuple-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (while (consp result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (setq result (vm-auto-select-folder mp result)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (if result
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (throw 'match result))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (setq tuple-list (cdr tuple-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (setq alist (cdr alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 nil ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (error (error "error processing vm-auto-folder-alist: %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (prin1-to-string error-data)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (defun vm-auto-archive-messages (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 "Save all unfiled messages that auto-match a folder via
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 vm-auto-folder-alist to their appropriate folders. Messages that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 are flagged for deletion are not saved.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 Prefix arg means to ask user for confirmation before saving each message.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 When invoked on marked messages (via vm-next-command-uses-marks),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 only marked messages are checked against vm-auto-folder-alist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 The saved messages are flagged as `filed'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (vm-select-folder-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (vm-check-for-killed-summary)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (vm-error-if-folder-empty)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (vm-unsaved-message "Archiving...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (let ((auto-folder)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (archived 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 ;; Need separate (let ...) so vm-message-pointer can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 ;; revert back in time for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 ;; (vm-update-summary-and-mode-line).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 ;; vm-last-save-folder is tucked away here since archives
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 ;; shouldn't affect its value.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (let ((vm-message-pointer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (if (eq last-command 'vm-next-command-uses-marks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (vm-select-marked-or-prefixed-messages 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 vm-message-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (done nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 stop-point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (vm-last-save-folder vm-last-save-folder)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (vm-move-after-deleting nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 ;; mark the place where we should stop. otherwise if any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 ;; messages in this folder are archived to this folder
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 ;; we would file messages into this folder forever.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (setq stop-point (vm-last vm-message-pointer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (while (not done)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (and (not (vm-filed-flag (car vm-message-pointer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 ;; don't archive deleted messages
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (not (vm-deleted-flag (car vm-message-pointer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (setq auto-folder (vm-auto-select-folder
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 vm-message-pointer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 vm-auto-folder-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (or (null arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (y-or-n-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (format "Save message %s in folder %s? "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (vm-number-of (car vm-message-pointer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 auto-folder)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (let ((vm-delete-after-saving vm-delete-after-archiving))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (if (not (string-equal auto-folder "/dev/null"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (vm-save-message auto-folder))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (vm-increment archived)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (vm-unsaved-message "%d archived, still working..."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 archived)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (setq done (eq vm-message-pointer stop-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 vm-message-pointer (cdr vm-message-pointer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 ;; fix mode line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (intern (buffer-name) vm-buffers-needing-display-update)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (vm-update-summary-and-mode-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (if (zerop archived)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (message "No messages archived")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (message "%d message%s archived"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 archived (if (= 1 archived) "" "s")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (defun vm-save-message (folder &optional count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 "Save the current message to a mail folder.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 If the folder already exists, the message will be appended to it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 Prefix arg COUNT means save this message and the next COUNT-1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 messages. A negative COUNT means save this message and the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 previous COUNT-1 messages.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 When invoked on marked messages (via vm-next-command-uses-marks),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 all marked messages in the current folder are saved; other messages are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 ignored.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 The saved messages are flagged as `filed'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 ;; protect value of last-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (let ((last-command last-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (this-command this-command))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (vm-follow-summary-cursor)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (let ((default (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (vm-select-folder-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (vm-check-for-killed-summary)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (vm-error-if-folder-empty)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (or (vm-auto-select-folder vm-message-pointer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 vm-auto-folder-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 vm-last-save-folder)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (dir (or vm-folder-directory default-directory)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (cond ((and default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (let ((default-directory dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (file-directory-p default)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (vm-read-file-name "Save in folder: " dir nil nil default))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (vm-read-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (format "Save in folder: (default %s) " default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 dir default))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (vm-read-file-name "Save in folder: " dir nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (prefix-numeric-value current-prefix-arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (let (unexpanded-folder)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (setq unexpanded-folder folder)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (vm-select-folder-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (vm-check-for-killed-summary)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (vm-error-if-folder-empty)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (vm-display nil nil '(vm-save-message) '(vm-save-message))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (or count (setq count 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 ;; Expand the filename, forcing relative paths to resolve
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 ;; into the folder directory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (let ((default-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (expand-file-name (or vm-folder-directory default-directory))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (setq folder (expand-file-name folder)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 ;; Confirm new folders, if the user requested this.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (if (and vm-confirm-new-folders (interactive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (not (file-exists-p folder))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (or (not vm-visit-when-saving) (not (vm-get-file-buffer folder)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (not (y-or-n-p (format "%s does not exist, save there anyway? "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 folder))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (error "Save aborted"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 ;; Check and see if we are currently visiting the folder
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 ;; that the user wants to save to.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (if (and (not vm-visit-when-saving) (vm-get-file-buffer folder))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (error "Folder %s is being visited, cannot save." folder))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (let ((mlist (vm-select-marked-or-prefixed-messages count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (m nil) (count 0) folder-buffer target-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (cond ((and mlist (eq vm-visit-when-saving t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (setq folder-buffer (or (vm-get-file-buffer folder)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 ;; avoid letter bombs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (let ((inhibit-local-variables t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (enable-local-variables nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (find-file-noselect folder)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 ((and mlist vm-visit-when-saving)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (setq folder-buffer (vm-get-file-buffer folder))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (if (and mlist vm-check-folder-types)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (setq target-type (or (vm-get-folder-type folder)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 vm-default-folder-type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (and mlist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (vm-message-type-of (car mlist)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (if (eq target-type 'unknown)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (error "Folder %s's type is unrecognized" folder))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 ;; if target folder is empty or nonexistent we need to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 ;; write out the folder header first.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (if mlist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (let ((attrs (file-attributes folder)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (if (or (null attrs) (= 0 (nth 7 attrs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (if (null folder-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (vm-write-string folder (vm-folder-header target-type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (vm-write-string folder-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (vm-folder-header target-type))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (while mlist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (setq m (vm-real-message-of (car mlist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (set-buffer (vm-buffer-of m))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (vm-save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 ;; have to stuff the attributes in all cases because
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 ;; the deleted attribute may have been stuffed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 ;; previously and we don't want to save that attribute.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 ;; also we don't want to save out the cached summary entry.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (vm-stuff-attributes m t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (if (null folder-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (if (or (null vm-check-folder-types)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (eq target-type (vm-message-type-of m)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (write-region (vm-start-of m)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (vm-end-of m)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 folder t 'quiet)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (if (null vm-convert-folder-types)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (if (not (vm-virtual-message-p (car mlist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (error "Folder type mismatch: %s, %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (vm-message-type-of m) target-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (error "Message %s type mismatches folder %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (vm-number-of (car mlist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 folder
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (vm-message-type-of m)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 target-type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (vm-write-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 folder
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (vm-leading-message-separator target-type m t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (if (eq target-type 'From_-with-Content-Length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (vm-write-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 folder
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (concat vm-content-length-header " "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (vm-su-byte-count m) "\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (write-region (vm-headers-of m)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (vm-text-end-of m)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 folder t 'quiet)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (vm-write-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 folder
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (vm-trailing-message-separator target-type))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (set-buffer folder-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 ;; if the buffer is a live VM folder
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 ;; honor vm-folder-read-only.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (if vm-folder-read-only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (signal 'folder-read-only (list (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (let ((buffer-read-only nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (vm-save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (if (or (null vm-check-folder-types)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (eq target-type (vm-message-type-of m)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (insert-buffer-substring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (vm-buffer-of m)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (vm-start-of m) (vm-end-of m))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (if (null vm-convert-folder-types)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (if (not (vm-virtual-message-p (car mlist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (error "Folder type mismatch: %s, %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (vm-message-type-of m) target-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (error "Message %s type mismatches folder %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (vm-number-of (car mlist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 folder
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (vm-message-type-of m)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 target-type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (vm-write-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (current-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (vm-leading-message-separator target-type m t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (if (eq target-type 'From_-with-Content-Length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (vm-write-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (current-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (concat vm-content-length-header " "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (vm-su-byte-count m) "\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (insert-buffer-substring (vm-buffer-of m)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (vm-headers-of m)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (vm-text-end-of m))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (vm-write-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (current-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (vm-trailing-message-separator target-type)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 ;; vars should exist and be local
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 ;; but they may have strange values,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 ;; so check the major-mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (cond ((eq major-mode 'vm-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (vm-increment vm-messages-not-on-disk)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (vm-clear-modification-flag-undos)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (if (null (vm-filed-flag m))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (vm-set-filed-flag m t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (vm-increment count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (vm-update-summary-and-mode-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (setq mlist (cdr mlist)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (if m
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (if folder-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (set-buffer folder-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (if (eq major-mode 'vm-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (vm-check-for-killed-summary)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (vm-assimilate-new-messages)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (if (null vm-message-pointer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (progn (setq vm-message-pointer vm-message-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 vm-need-summary-pointer-update t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (intern (buffer-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 vm-buffers-needing-display-update)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (vm-preview-current-message))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (vm-update-summary-and-mode-line)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (if (interactive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (message "%d message%s saved to buffer %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 count
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (if (/= 1 count) "s" "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (buffer-name folder-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (if (interactive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (message "%d message%s saved to %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 count (if (/= 1 count) "s" "") folder)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (setq vm-last-save-folder unexpanded-folder)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (if vm-delete-after-saving
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (vm-delete-message count))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (defun vm-save-message-sans-headers (file &optional count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 "Save the current message to a file, without its header section.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 If the file already exists, the message will be appended to it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 Prefix arg COUNT means save the next COUNT messages. A negative COUNT means
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 save the previous COUNT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 When invoked on marked messages (via vm-next-command-uses-marks),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 all marked messages in the current folder are saved; other messages are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 ignored.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 The saved messages are flagged as `written'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 This command should NOT be used to save message to mail folders; use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 vm-save-message instead (normally bound to `s')."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 ;; protect value of last-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 (let ((last-command last-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 (this-command this-command))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 (vm-follow-summary-cursor)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (vm-select-folder-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (vm-read-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 (if vm-last-written-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (format "Write text to file: (default %s) "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 vm-last-written-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 "Write text to file: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 nil vm-last-written-file nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 (prefix-numeric-value current-prefix-arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 (vm-select-folder-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 (vm-check-for-killed-summary)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 (vm-error-if-folder-empty)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 (vm-display nil nil '(vm-save-message-sans-headers)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 '(vm-save-message-sans-headers))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 (or count (setq count 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (setq file (expand-file-name file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 ;; Check and see if we are currently visiting the file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 ;; that the user wants to save to.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 (if (and (not vm-visit-when-saving) (vm-get-file-buffer file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (error "File %s is being visited, cannot save." file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (let ((mlist (vm-select-marked-or-prefixed-messages count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (m nil) file-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (cond ((and mlist (eq vm-visit-when-saving t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 (setq file-buffer (or (vm-get-file-buffer file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 (find-file-noselect file))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 ((and mlist vm-visit-when-saving)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 (setq file-buffer (vm-get-file-buffer file))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (while mlist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (setq m (vm-real-message-of (car mlist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (set-buffer (vm-buffer-of m))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (vm-save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 (if (null file-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 (write-region (vm-text-of m)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (vm-text-end-of m)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 file t 'quiet)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 (let ((start (vm-text-of m))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (end (vm-text-end-of m)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (set-buffer file-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (let (buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (vm-save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 (insert-buffer-substring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (vm-buffer-of m)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 start end))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (if (null (vm-written-flag m))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 (vm-set-written-flag m t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (vm-update-summary-and-mode-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (setq mlist (cdr mlist)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (if m
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (if file-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (message "Message%s written to buffer %s" (if (/= 1 count) "s" "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 (buffer-name file-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (message "Message%s written to %s" (if (/= 1 count) "s" "") file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 (setq vm-last-written-file file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (defun vm-pipe-message-to-command (command prefix-arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 "Run shell command with the some or all of the current message as input.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 By default the entire message is used.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 With one \\[universal-argument] the text portion of the message is used.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 With two \\[universal-argument]'s the header portion of the message is used.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 With three \\[universal-argument]'s the visible header portion of the message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 plus the text portion is used.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 When invoked on marked messages (via vm-next-command-uses-marks),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 each marked message is successively piped to the shell command,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 one message per command invocation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 Output, if any, is displayed. The message is not altered."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 ;; protect value of last-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (let ((last-command last-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (this-command this-command))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (vm-follow-summary-cursor)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 (vm-select-folder-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 (list (read-string "Pipe to command: " vm-last-pipe-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 current-prefix-arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (vm-select-folder-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 (vm-check-for-killed-summary)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (vm-error-if-folder-empty)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (setq vm-last-pipe-command command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (let ((buffer (get-buffer-create "*Shell Command Output*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 m
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (pop-up-windows (and pop-up-windows (eq vm-mutable-windows t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 ;; prefix arg doesn't have "normal" meaning here, so only call
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 ;; vm-select-marked-or-prefixed-messages if we're using marks.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 (mlist (if (eq last-command 'vm-next-command-uses-marks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 (vm-select-marked-or-prefixed-messages 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (list (car vm-message-pointer)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (while mlist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (setq m (vm-real-message-of (car mlist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 (set-buffer (vm-buffer-of m))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (goto-char (vm-headers-of m))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (cond ((equal prefix-arg nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (narrow-to-region (point) (vm-text-end-of m)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 ((equal prefix-arg '(4))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (narrow-to-region (vm-text-of m)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (vm-text-end-of m)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 ((equal prefix-arg '(16))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (narrow-to-region (point) (vm-text-of m)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 ((equal prefix-arg '(64))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 (narrow-to-region (vm-vheaders-of m) (vm-text-end-of m)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (t (narrow-to-region (point) (vm-text-end-of m))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 (let ((pop-up-windows (and pop-up-windows (eq vm-mutable-windows t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (call-process-region (point-min) (point-max)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 (or shell-file-name "sh")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 nil buffer nil "-c" command)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (setq mlist (cdr mlist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 (if (not (zerop (buffer-size)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 (vm-display buffer t '(vm-pipe-message-to-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 '(vm-pipe-message-to-command))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (vm-display nil nil '(vm-pipe-message-to-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 '(vm-pipe-message-to-command)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 (defun vm-print-message ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 "Print the current message."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (vm-pipe-message-to-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 (mapconcat (function identity)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (nconc (list vm-print-command) vm-print-command-switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 " ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 '(64)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506