annotate lisp/vm/vm-save.el @ 24:4103f0995bd7 r19-15b95

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