6365
|
1 ;;; mh-funcs --- mh-e functions not everyone will use right away
|
|
2 ;; Time-stamp: <94/03/08 16:00:54 gildea>
|
|
3
|
|
4 ;; Copyright 1993 Free Software Foundation, Inc.
|
|
5
|
|
6 ;; This file is part of mh-e.
|
|
7
|
|
8 ;; mh-e is free software; you can redistribute it and/or modify
|
|
9 ;; it under the terms of the GNU General Public License as published by
|
|
10 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
11 ;; any later version.
|
|
12
|
|
13 ;; mh-e is distributed in the hope that it will be useful,
|
|
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16 ;; GNU General Public License for more details.
|
|
17
|
|
18 ;; You should have received a copy of the GNU General Public License
|
|
19 ;; along with mh-e; see the file COPYING. If not, write to
|
|
20 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
21
|
|
22 ;;; Commentary:
|
|
23
|
|
24 ;;; Internal support for mh-e package.
|
|
25 ;;; Putting these functions in a separate file lets mh-e start up faster,
|
|
26 ;;; since less Lisp code needs to be loaded all at once.
|
|
27
|
|
28 ;;; Code:
|
|
29
|
|
30 (provide 'mh-funcs)
|
|
31 (require 'mh-e)
|
|
32
|
|
33 (defvar mh-sortm-args nil
|
|
34 "Extra arguments to have \\[mh-sort-folder] pass to the \"sortm\" command.
|
|
35 For example, '(\"-nolimit\" \"-textfield\" \"subject\") is a useful setting.")
|
|
36
|
|
37 (defun mh-burst-digest ()
|
|
38 "Burst apart the current message, which should be a digest.
|
|
39 The message is replaced by its table of contents and the letters from the
|
|
40 digest are inserted into the folder after that message."
|
|
41 (interactive)
|
|
42 (let ((digest (mh-get-msg-num t)))
|
|
43 (mh-process-or-undo-commands mh-current-folder)
|
|
44 (mh-set-folder-modified-p t) ; lock folder while bursting
|
|
45 (message "Bursting digest...")
|
|
46 (mh-exec-cmd "burst" mh-current-folder digest "-inplace")
|
|
47 (mh-scan-folder mh-current-folder (format "%d-last" mh-first-msg-num))
|
|
48 (message "Bursting digest...done")))
|
|
49
|
|
50
|
|
51 (defun mh-copy-msg (dest msg-or-seq)
|
|
52 "Copy to another FOLDER the specified MESSAGE(s) without deleting them.
|
|
53 Default is the displayed message. If optional prefix argument is
|
|
54 provided, then prompt for the message sequence."
|
|
55 (interactive (list (mh-prompt-for-folder "Copy to" "" t)
|
|
56 (if current-prefix-arg
|
|
57 (mh-read-seq-default "Copy" t)
|
|
58 (mh-get-msg-num t))))
|
|
59 (mh-exec-cmd "refile" msg-or-seq "-link" "-src" mh-current-folder dest)
|
|
60 (if (numberp msg-or-seq)
|
|
61 (mh-notate msg-or-seq ?C mh-cmd-note)
|
|
62 (mh-notate-seq msg-or-seq ?C mh-cmd-note)))
|
|
63
|
|
64 (defun mh-kill-folder ()
|
|
65 "Remove the current folder."
|
|
66 (interactive)
|
|
67 (if (or mh-do-not-confirm
|
|
68 (yes-or-no-p (format "Remove folder %s? " mh-current-folder)))
|
|
69 (let ((folder mh-current-folder))
|
|
70 (if (null mh-folder-list)
|
|
71 (mh-set-folder-list))
|
|
72 (mh-set-folder-modified-p t) ; lock folder to kill it
|
|
73 (mh-exec-cmd-daemon "rmf" folder)
|
|
74 (setq mh-folder-list
|
|
75 (delq (assoc folder mh-folder-list) mh-folder-list))
|
|
76 (message "Folder %s removed" folder)
|
|
77 (mh-set-folder-modified-p nil) ; so kill-buffer doesn't complain
|
|
78 (if (get-buffer mh-show-buffer)
|
|
79 (kill-buffer mh-show-buffer))
|
|
80 (kill-buffer folder))
|
|
81 (message "Folder not removed")))
|
|
82
|
|
83
|
|
84 (defun mh-list-folders ()
|
|
85 "List mail folders."
|
|
86 (interactive)
|
|
87 (with-output-to-temp-buffer " *mh-temp*"
|
|
88 (save-excursion
|
|
89 (switch-to-buffer " *mh-temp*")
|
|
90 (erase-buffer)
|
|
91 (message "Listing folders...")
|
|
92 (mh-exec-cmd-output "folders" t (if mh-recursive-folders
|
|
93 "-recurse"
|
|
94 "-norecurse"))
|
|
95 (goto-char (point-min))
|
|
96 (message "Listing folders...done"))))
|
|
97
|
|
98
|
|
99 (defun mh-pack-folder (range)
|
|
100 "Renumber the messages of a folder to be 1..n.
|
|
101 First, offer to execute any outstanding commands for the current folder.
|
|
102 If optional prefix argument provided, prompt for the range of messages
|
|
103 to display after packing. Otherwise, show the entire folder."
|
|
104 (interactive (list (if current-prefix-arg
|
|
105 (mh-read-msg-range
|
|
106 "Range to scan after packing [all]? ")
|
|
107 "all")))
|
|
108 (mh-pack-folder-1 range)
|
|
109 (mh-goto-cur-msg)
|
|
110 (message "Packing folder...done"))
|
|
111
|
|
112
|
|
113 (defun mh-pack-folder-1 (range)
|
|
114 ;; Close and pack the current folder.
|
|
115 (mh-process-or-undo-commands mh-current-folder)
|
|
116 (message "Packing folder...")
|
|
117 (mh-set-folder-modified-p t) ; lock folder while packing
|
|
118 (save-excursion
|
|
119 (mh-exec-cmd-quiet t "folder" mh-current-folder "-pack"))
|
|
120 (mh-regenerate-headers range))
|
|
121
|
|
122
|
|
123 (defun mh-pipe-msg (command include-headers)
|
|
124 "Pipe the current message through the given shell COMMAND.
|
|
125 If INCLUDE-HEADERS (prefix argument) is provided, send the entire message.
|
|
126 Otherwise just send the message's body without the headers."
|
|
127 (interactive
|
|
128 (list (read-string "Shell command on message: ") current-prefix-arg))
|
|
129 (let ((file-name (mh-msg-filename (mh-get-msg-num t))))
|
|
130 (save-excursion
|
|
131 (set-buffer (get-buffer-create " *mh-temp*"))
|
|
132 (erase-buffer)
|
|
133 (insert-file-contents file-name)
|
|
134 (goto-char (point-min))
|
|
135 (if (not include-headers) (search-forward "\n\n"))
|
|
136 (shell-command-on-region (point) (point-max) command nil))))
|
|
137
|
|
138
|
|
139 (defun mh-page-digest ()
|
|
140 "Advance displayed message to next digested message."
|
|
141 (interactive)
|
|
142 (mh-in-show-buffer (mh-show-buffer)
|
|
143 ;; Go to top of screen (in case user moved point).
|
|
144 (move-to-window-line 0)
|
|
145 (let ((case-fold-search nil))
|
|
146 ;; Search for blank line and then for From:
|
|
147 (or (and (search-forward "\n\n" nil t)
|
|
148 (search-forward "From:" nil t))
|
|
149 (error "No more messages in digest")))
|
|
150 ;; Go back to previous blank line, then forward to the first non-blank.
|
|
151 (search-backward "\n\n" nil t)
|
|
152 (forward-line 2)
|
|
153 (mh-recenter 0)))
|
|
154
|
|
155
|
|
156 (defun mh-page-digest-backwards ()
|
|
157 "Back up displayed message to previous digested message."
|
|
158 (interactive)
|
|
159 (mh-in-show-buffer (mh-show-buffer)
|
|
160 ;; Go to top of screen (in case user moved point).
|
|
161 (move-to-window-line 0)
|
|
162 (let ((case-fold-search nil))
|
|
163 (beginning-of-line)
|
|
164 (or (and (search-backward "\n\n" nil t)
|
|
165 (search-backward "From:" nil t))
|
|
166 (error "No previous message in digest")))
|
|
167 ;; Go back to previous blank line, then forward to the first non-blank.
|
|
168 (if (search-backward "\n\n" nil t)
|
|
169 (forward-line 2))
|
|
170 (mh-recenter 0)))
|
|
171
|
|
172
|
|
173 (defun mh-print-msg (msg-or-seq)
|
|
174 "Print MESSAGE(s) (default: displayed message) on printer.
|
|
175 If optional prefix argument provided, then prompt for the message sequence.
|
|
176 The variable mh-lpr-command-format is used to generate the print command.
|
|
177 The messages are formatted by mhl. See the variable mhl-formfile."
|
|
178 (interactive (list (if current-prefix-arg
|
|
179 (reverse (mh-seq-to-msgs
|
|
180 (mh-read-seq-default "Print" t)))
|
|
181 (mh-get-msg-num t))))
|
|
182 (if (numberp msg-or-seq)
|
|
183 (message "Printing message...")
|
|
184 (message "Printing sequence..."))
|
|
185 (let ((print-command
|
|
186 (if (numberp msg-or-seq)
|
|
187 (format "%s -nobell -clear %s %s | %s"
|
|
188 (expand-file-name "mhl" mh-lib)
|
|
189 (mh-msg-filename msg-or-seq)
|
|
190 (if (stringp mhl-formfile)
|
|
191 (format "-form %s" mhl-formfile)
|
|
192 "")
|
|
193 (format mh-lpr-command-format
|
|
194 (if (numberp msg-or-seq)
|
|
195 (format "%s/%d" mh-current-folder
|
|
196 msg-or-seq)
|
|
197 (format "Sequence from %s" mh-current-folder))))
|
|
198 (format "(scan -clear %s ; %s -nobell -clear %s %s) | %s"
|
|
199 (mapconcat (function (lambda (msg) msg)) msg-or-seq " ")
|
|
200 (expand-file-name "mhl" mh-lib)
|
|
201 (if (stringp mhl-formfile)
|
|
202 (format "-form %s" mhl-formfile)
|
|
203 "")
|
|
204 (mh-msg-filenames msg-or-seq)
|
|
205 (format mh-lpr-command-format
|
|
206 (if (numberp msg-or-seq)
|
|
207 (format "%s/%d" mh-current-folder
|
|
208 msg-or-seq)
|
|
209 (format "Sequence from %s"
|
|
210 mh-current-folder)))))))
|
|
211 (if mh-print-background
|
|
212 (mh-exec-cmd-daemon shell-file-name "-c" print-command)
|
|
213 (call-process shell-file-name nil nil nil "-c" print-command))
|
|
214 (if (numberp msg-or-seq)
|
|
215 (mh-notate msg-or-seq ?P mh-cmd-note)
|
|
216 (mh-notate-seq msg-or-seq ?P mh-cmd-note))
|
|
217 (mh-add-msgs-to-seq msg-or-seq 'printed t)
|
|
218 (if (numberp msg-or-seq)
|
|
219 (message "Printing message...done")
|
|
220 (message "Printing sequence...done"))))
|
|
221
|
|
222
|
|
223 (defun mh-msg-filenames (msgs &optional folder)
|
|
224 ;; Return a list of file names for MSGS in FOLDER (default current folder).
|
|
225 (mapconcat (function (lambda (msg) (mh-msg-filename msg folder))) msgs " "))
|
|
226
|
|
227
|
|
228 (defun mh-sort-folder (&optional no-args)
|
|
229 "Sort the messages in the current folder by date.
|
|
230 Calls the MH program sortm to do the work.
|
|
231 The arguments in the list mh-sortm-args are passed to sortm
|
|
232 unless this function is passed an argument."
|
|
233 (interactive "P")
|
|
234 (mh-process-or-undo-commands mh-current-folder)
|
|
235 (setq mh-next-direction 'forward)
|
|
236 (mh-set-folder-modified-p t) ; lock folder while sorting
|
|
237 (message "Sorting folder...")
|
|
238 (mh-exec-cmd "sortm" mh-current-folder (if (not no-args) mh-sortm-args))
|
|
239 (message "Sorting folder...done")
|
|
240 (mh-scan-folder mh-current-folder "all"))
|
|
241
|
|
242
|
|
243 (defun mh-undo-folder (&rest ignore)
|
|
244 "Undo all commands in current folder."
|
|
245 (interactive)
|
|
246 (cond ((or mh-do-not-confirm
|
|
247 (yes-or-no-p "Undo all commands in folder? "))
|
|
248 (setq mh-delete-list nil
|
|
249 mh-refile-list nil
|
|
250 mh-seq-list nil
|
|
251 mh-next-direction 'forward)
|
|
252 (with-mh-folder-updating (nil)
|
|
253 (mh-unmark-all-headers t)))
|
|
254 (t
|
|
255 (message "Commands not undone.")
|
|
256 (sit-for 2))))
|
|
257
|
|
258
|
|
259 (defun mh-store-msg (dir)
|
|
260 "Store the file(s) contained in the current message into DIRECTORY.
|
|
261 The message can contain a shar file or uuencoded file.
|
|
262 Default directory is the last directory used, or initially the value of
|
|
263 mh-store-default-directory or the current directory."
|
|
264 (interactive (list (let ((udir (or mh-store-default-directory default-directory)))
|
|
265 (read-file-name "Store message in directory: "
|
|
266 udir udir nil))))
|
|
267 (let ((file-name (mh-msg-filename (mh-get-msg-num t))))
|
|
268 (save-excursion
|
|
269 (set-buffer (get-buffer-create " *mh-temp*"))
|
|
270 (erase-buffer)
|
|
271 (insert-file-contents file-name)
|
|
272 (mh-store-buffer dir))))
|
|
273
|
|
274 (defun mh-store-buffer (dir)
|
|
275 "Store the file(s) contained in the current buffer into DIRECTORY.
|
|
276 The buffer can contain a shar file or uuencoded file.
|
|
277 Default directory is the last directory used, or initially the value of
|
|
278 `mh-store-default-directory' or the current directory."
|
|
279 (interactive (list (let ((udir (or mh-store-default-directory default-directory)))
|
|
280 (read-file-name "Store buffer in directory: "
|
|
281 udir udir nil))))
|
|
282 (let ((store-directory (expand-file-name dir))
|
|
283 (start (save-excursion
|
|
284 (goto-char (point-min))
|
|
285 (if (or (re-search-forward "^#![ \t]*/bin/sh" nil t)
|
|
286 (and (re-search-forward "^[^a-z0-9\"]*cut here\\b" nil t)
|
|
287 (forward-line 1))
|
|
288 (re-search-forward "^#" nil t)
|
|
289 (re-search-forward "^: " nil t))
|
|
290 (progn (beginning-of-line) (point)))))
|
|
291 (log-buffer (get-buffer-create "*Store Output*"))
|
|
292 (command "sh"))
|
|
293 (save-excursion
|
|
294 (set-buffer log-buffer)
|
|
295 (erase-buffer)
|
|
296 (if (not (file-directory-p store-directory))
|
|
297 (progn
|
|
298 (insert "mkdir " dir "\n")
|
|
299 (call-process "mkdir" nil log-buffer t store-directory)))
|
|
300 (insert "cd " dir "\n")
|
|
301 (if (not start)
|
|
302 (progn
|
|
303 (setq command "uudecode")
|
|
304 (insert "uudecoding...\n"))))
|
|
305 (set-window-start (display-buffer log-buffer) 0) ;watch progress
|
|
306 (let ((default-directory (file-name-as-directory store-directory)))
|
|
307 (call-process-region start (point-max) command nil log-buffer t))
|
|
308 (setq mh-store-default-directory dir)
|
|
309 (set-buffer log-buffer)
|
|
310 (insert "\n(mh-store finished)\n")))
|
|
311
|