6365
|
1 ;;; mh-funcs --- mh-e functions not everyone will use right away
|
11332
|
2 ;; Time-stamp: <95/01/25 16:35:24 gildea>
|
6365
|
3
|
11332
|
4 ;; Copyright (C) 1993, 1995 Free Software Foundation, Inc.
|
6365
|
5
|
11333
|
6 ;; This file is part of GNU Emacs.
|
6365
|
7
|
11333
|
8 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
6365
|
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
|
11333
|
13 ;; GNU Emacs is distributed in the hope that it will be useful,
|
6365
|
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
|
11333
|
19 ;; along with GNU Emacs; see the file COPYING. If not, write to
|
6365
|
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
|
11332
|
28 ;;; Change Log:
|
|
29
|
11333
|
30 ;; $Id: mh-funcs.el,v 1.2 1995/04/09 22:30:49 kwzh Exp kwzh $
|
11332
|
31
|
6365
|
32 ;;; Code:
|
|
33
|
|
34 (provide 'mh-funcs)
|
|
35 (require 'mh-e)
|
|
36
|
11332
|
37 ;;; customization
|
|
38
|
6365
|
39 (defvar mh-sortm-args nil
|
|
40 "Extra arguments to have \\[mh-sort-folder] pass to the \"sortm\" command.
|
11332
|
41 The arguments are passed to sortm if \\[mh-sort-folder] is given a
|
|
42 prefix argument. Normally default arguments to sortm are specified in the
|
|
43 MH profile.
|
6365
|
44 For example, '(\"-nolimit\" \"-textfield\" \"subject\") is a useful setting.")
|
|
45
|
11332
|
46 (defvar mh-note-copied "C"
|
|
47 "String whose first character is used to notate copied messages.")
|
|
48
|
|
49 (defvar mh-note-printed "P"
|
|
50 "String whose first character is used to notate printed messages.")
|
|
51
|
|
52 ;;; functions
|
|
53
|
6365
|
54 (defun mh-burst-digest ()
|
|
55 "Burst apart the current message, which should be a digest.
|
11332
|
56 The message is replaced by its table of contents and the messages from the
|
6365
|
57 digest are inserted into the folder after that message."
|
|
58 (interactive)
|
|
59 (let ((digest (mh-get-msg-num t)))
|
|
60 (mh-process-or-undo-commands mh-current-folder)
|
|
61 (mh-set-folder-modified-p t) ; lock folder while bursting
|
|
62 (message "Bursting digest...")
|
|
63 (mh-exec-cmd "burst" mh-current-folder digest "-inplace")
|
11332
|
64 (with-mh-folder-updating (t)
|
|
65 (beginning-of-line)
|
|
66 (delete-region (point) (point-max)))
|
|
67 (mh-regenerate-headers (format "%d-last" digest) t)
|
|
68 (mh-goto-cur-msg)
|
6365
|
69 (message "Bursting digest...done")))
|
|
70
|
|
71
|
11332
|
72 (defun mh-copy-msg (msg-or-seq folder)
|
|
73 "Copy the specified MESSAGE(s) to another FOLDER without deleting them.
|
6365
|
74 Default is the displayed message. If optional prefix argument is
|
|
75 provided, then prompt for the message sequence."
|
11332
|
76 (interactive (list (if current-prefix-arg
|
6365
|
77 (mh-read-seq-default "Copy" t)
|
11332
|
78 (mh-get-msg-num t))
|
|
79 (mh-prompt-for-folder "Copy to" "" t)))
|
|
80 (mh-exec-cmd "refile" msg-or-seq "-link" "-src" mh-current-folder folder)
|
6365
|
81 (if (numberp msg-or-seq)
|
11332
|
82 (mh-notate msg-or-seq mh-note-copied mh-cmd-note)
|
|
83 (mh-notate-seq msg-or-seq mh-note-copied mh-cmd-note)))
|
6365
|
84
|
|
85 (defun mh-kill-folder ()
|
|
86 "Remove the current folder."
|
|
87 (interactive)
|
|
88 (if (or mh-do-not-confirm
|
|
89 (yes-or-no-p (format "Remove folder %s? " mh-current-folder)))
|
|
90 (let ((folder mh-current-folder))
|
|
91 (if (null mh-folder-list)
|
|
92 (mh-set-folder-list))
|
|
93 (mh-set-folder-modified-p t) ; lock folder to kill it
|
|
94 (mh-exec-cmd-daemon "rmf" folder)
|
|
95 (setq mh-folder-list
|
|
96 (delq (assoc folder mh-folder-list) mh-folder-list))
|
11332
|
97 (run-hooks 'mh-folder-list-change-hook)
|
6365
|
98 (message "Folder %s removed" folder)
|
|
99 (mh-set-folder-modified-p nil) ; so kill-buffer doesn't complain
|
|
100 (if (get-buffer mh-show-buffer)
|
|
101 (kill-buffer mh-show-buffer))
|
|
102 (kill-buffer folder))
|
|
103 (message "Folder not removed")))
|
|
104
|
|
105
|
|
106 (defun mh-list-folders ()
|
|
107 "List mail folders."
|
|
108 (interactive)
|
11332
|
109 (with-output-to-temp-buffer mh-temp-buffer
|
6365
|
110 (save-excursion
|
11332
|
111 (switch-to-buffer mh-temp-buffer)
|
6365
|
112 (erase-buffer)
|
|
113 (message "Listing folders...")
|
|
114 (mh-exec-cmd-output "folders" t (if mh-recursive-folders
|
|
115 "-recurse"
|
|
116 "-norecurse"))
|
|
117 (goto-char (point-min))
|
|
118 (message "Listing folders...done"))))
|
|
119
|
|
120
|
|
121 (defun mh-pack-folder (range)
|
|
122 "Renumber the messages of a folder to be 1..n.
|
|
123 First, offer to execute any outstanding commands for the current folder.
|
11332
|
124 If optional prefix argument provided, prompt for the RANGE of messages
|
6365
|
125 to display after packing. Otherwise, show the entire folder."
|
|
126 (interactive (list (if current-prefix-arg
|
|
127 (mh-read-msg-range
|
|
128 "Range to scan after packing [all]? ")
|
|
129 "all")))
|
|
130 (mh-pack-folder-1 range)
|
|
131 (mh-goto-cur-msg)
|
|
132 (message "Packing folder...done"))
|
|
133
|
|
134
|
|
135 (defun mh-pack-folder-1 (range)
|
|
136 ;; Close and pack the current folder.
|
|
137 (mh-process-or-undo-commands mh-current-folder)
|
|
138 (message "Packing folder...")
|
|
139 (mh-set-folder-modified-p t) ; lock folder while packing
|
|
140 (save-excursion
|
11332
|
141 (mh-exec-cmd-quiet t "folder" mh-current-folder "-pack"
|
|
142 "-norecurse" "-fast"))
|
6365
|
143 (mh-regenerate-headers range))
|
|
144
|
|
145
|
|
146 (defun mh-pipe-msg (command include-headers)
|
|
147 "Pipe the current message through the given shell COMMAND.
|
|
148 If INCLUDE-HEADERS (prefix argument) is provided, send the entire message.
|
|
149 Otherwise just send the message's body without the headers."
|
|
150 (interactive
|
|
151 (list (read-string "Shell command on message: ") current-prefix-arg))
|
11332
|
152 (let ((msg-file-to-pipe (mh-msg-filename (mh-get-msg-num t)))
|
|
153 (message-directory default-directory))
|
6365
|
154 (save-excursion
|
11332
|
155 (set-buffer (get-buffer-create mh-temp-buffer))
|
6365
|
156 (erase-buffer)
|
11332
|
157 (insert-file-contents msg-file-to-pipe)
|
6365
|
158 (goto-char (point-min))
|
|
159 (if (not include-headers) (search-forward "\n\n"))
|
11332
|
160 (let ((default-directory message-directory))
|
|
161 (shell-command-on-region (point) (point-max) command nil)))))
|
6365
|
162
|
|
163
|
|
164 (defun mh-page-digest ()
|
|
165 "Advance displayed message to next digested message."
|
|
166 (interactive)
|
|
167 (mh-in-show-buffer (mh-show-buffer)
|
|
168 ;; Go to top of screen (in case user moved point).
|
|
169 (move-to-window-line 0)
|
|
170 (let ((case-fold-search nil))
|
|
171 ;; Search for blank line and then for From:
|
|
172 (or (and (search-forward "\n\n" nil t)
|
11332
|
173 (re-search-forward "^From:" nil t))
|
6365
|
174 (error "No more messages in digest")))
|
|
175 ;; Go back to previous blank line, then forward to the first non-blank.
|
|
176 (search-backward "\n\n" nil t)
|
|
177 (forward-line 2)
|
|
178 (mh-recenter 0)))
|
|
179
|
|
180
|
|
181 (defun mh-page-digest-backwards ()
|
|
182 "Back up displayed message to previous digested message."
|
|
183 (interactive)
|
|
184 (mh-in-show-buffer (mh-show-buffer)
|
|
185 ;; Go to top of screen (in case user moved point).
|
|
186 (move-to-window-line 0)
|
|
187 (let ((case-fold-search nil))
|
|
188 (beginning-of-line)
|
|
189 (or (and (search-backward "\n\n" nil t)
|
11332
|
190 (re-search-backward "^From:" nil t))
|
6365
|
191 (error "No previous message in digest")))
|
|
192 ;; Go back to previous blank line, then forward to the first non-blank.
|
|
193 (if (search-backward "\n\n" nil t)
|
|
194 (forward-line 2))
|
|
195 (mh-recenter 0)))
|
|
196
|
|
197
|
|
198 (defun mh-print-msg (msg-or-seq)
|
|
199 "Print MESSAGE(s) (default: displayed message) on printer.
|
|
200 If optional prefix argument provided, then prompt for the message sequence.
|
|
201 The variable mh-lpr-command-format is used to generate the print command.
|
|
202 The messages are formatted by mhl. See the variable mhl-formfile."
|
|
203 (interactive (list (if current-prefix-arg
|
|
204 (reverse (mh-seq-to-msgs
|
|
205 (mh-read-seq-default "Print" t)))
|
|
206 (mh-get-msg-num t))))
|
|
207 (if (numberp msg-or-seq)
|
|
208 (message "Printing message...")
|
|
209 (message "Printing sequence..."))
|
|
210 (let ((print-command
|
|
211 (if (numberp msg-or-seq)
|
|
212 (format "%s -nobell -clear %s %s | %s"
|
|
213 (expand-file-name "mhl" mh-lib)
|
|
214 (mh-msg-filename msg-or-seq)
|
|
215 (if (stringp mhl-formfile)
|
|
216 (format "-form %s" mhl-formfile)
|
|
217 "")
|
|
218 (format mh-lpr-command-format
|
|
219 (if (numberp msg-or-seq)
|
|
220 (format "%s/%d" mh-current-folder
|
|
221 msg-or-seq)
|
|
222 (format "Sequence from %s" mh-current-folder))))
|
|
223 (format "(scan -clear %s ; %s -nobell -clear %s %s) | %s"
|
|
224 (mapconcat (function (lambda (msg) msg)) msg-or-seq " ")
|
|
225 (expand-file-name "mhl" mh-lib)
|
|
226 (if (stringp mhl-formfile)
|
|
227 (format "-form %s" mhl-formfile)
|
|
228 "")
|
|
229 (mh-msg-filenames msg-or-seq)
|
|
230 (format mh-lpr-command-format
|
|
231 (if (numberp msg-or-seq)
|
|
232 (format "%s/%d" mh-current-folder
|
|
233 msg-or-seq)
|
|
234 (format "Sequence from %s"
|
|
235 mh-current-folder)))))))
|
|
236 (if mh-print-background
|
|
237 (mh-exec-cmd-daemon shell-file-name "-c" print-command)
|
|
238 (call-process shell-file-name nil nil nil "-c" print-command))
|
|
239 (if (numberp msg-or-seq)
|
11332
|
240 (mh-notate msg-or-seq mh-note-printed mh-cmd-note)
|
|
241 (mh-notate-seq msg-or-seq mh-note-printed mh-cmd-note))
|
6365
|
242 (mh-add-msgs-to-seq msg-or-seq 'printed t)
|
|
243 (if (numberp msg-or-seq)
|
|
244 (message "Printing message...done")
|
|
245 (message "Printing sequence...done"))))
|
|
246
|
|
247
|
|
248 (defun mh-msg-filenames (msgs &optional folder)
|
|
249 ;; Return a list of file names for MSGS in FOLDER (default current folder).
|
|
250 (mapconcat (function (lambda (msg) (mh-msg-filename msg folder))) msgs " "))
|
|
251
|
|
252
|
11332
|
253 (defun mh-sort-folder (&optional extra-args)
|
6365
|
254 "Sort the messages in the current folder by date.
|
|
255 Calls the MH program sortm to do the work.
|
|
256 The arguments in the list mh-sortm-args are passed to sortm
|
11332
|
257 if this function is passed an argument."
|
6365
|
258 (interactive "P")
|
|
259 (mh-process-or-undo-commands mh-current-folder)
|
|
260 (setq mh-next-direction 'forward)
|
|
261 (mh-set-folder-modified-p t) ; lock folder while sorting
|
|
262 (message "Sorting folder...")
|
11332
|
263 (mh-exec-cmd "sortm" mh-current-folder (if extra-args mh-sortm-args))
|
6365
|
264 (message "Sorting folder...done")
|
|
265 (mh-scan-folder mh-current-folder "all"))
|
|
266
|
|
267
|
|
268 (defun mh-undo-folder (&rest ignore)
|
11332
|
269 "Undo all pending deletes and refiles in current folder."
|
6365
|
270 (interactive)
|
|
271 (cond ((or mh-do-not-confirm
|
|
272 (yes-or-no-p "Undo all commands in folder? "))
|
|
273 (setq mh-delete-list nil
|
|
274 mh-refile-list nil
|
|
275 mh-seq-list nil
|
|
276 mh-next-direction 'forward)
|
|
277 (with-mh-folder-updating (nil)
|
|
278 (mh-unmark-all-headers t)))
|
|
279 (t
|
|
280 (message "Commands not undone.")
|
|
281 (sit-for 2))))
|
|
282
|
|
283
|
11332
|
284 (defun mh-store-msg (directory)
|
6365
|
285 "Store the file(s) contained in the current message into DIRECTORY.
|
|
286 The message can contain a shar file or uuencoded file.
|
|
287 Default directory is the last directory used, or initially the value of
|
|
288 mh-store-default-directory or the current directory."
|
|
289 (interactive (list (let ((udir (or mh-store-default-directory default-directory)))
|
|
290 (read-file-name "Store message in directory: "
|
|
291 udir udir nil))))
|
11332
|
292 (let ((msg-file-to-store (mh-msg-filename (mh-get-msg-num t))))
|
6365
|
293 (save-excursion
|
11332
|
294 (set-buffer (get-buffer-create mh-temp-buffer))
|
6365
|
295 (erase-buffer)
|
11332
|
296 (insert-file-contents msg-file-to-store)
|
|
297 (mh-store-buffer directory))))
|
6365
|
298
|
11332
|
299 (defun mh-store-buffer (directory)
|
6365
|
300 "Store the file(s) contained in the current buffer into DIRECTORY.
|
|
301 The buffer can contain a shar file or uuencoded file.
|
|
302 Default directory is the last directory used, or initially the value of
|
|
303 `mh-store-default-directory' or the current directory."
|
|
304 (interactive (list (let ((udir (or mh-store-default-directory default-directory)))
|
11332
|
305 (read-file-name "Store buffer in directory: "
|
|
306 udir udir nil))))
|
|
307 (let ((store-directory (expand-file-name directory))
|
|
308 (sh-start (save-excursion
|
|
309 (goto-char (point-min))
|
|
310 (if (re-search-forward
|
|
311 "^#![ \t]*/bin/sh\\|^#\\|^: " nil t)
|
|
312 (progn
|
|
313 ;; The "cut here" pattern was removed from above
|
|
314 ;; because it seemed to hurt more than help.
|
|
315 ;; But keep this to make it easier to put it back.
|
|
316 (if (looking-at "^[^a-z0-9\"]*cut here\\b")
|
6365
|
317 (forward-line 1))
|
11332
|
318 (beginning-of-line)
|
|
319 (if (looking-at "^[#:]....+\n\\( ?\n\\)?end$")
|
|
320 nil ;most likely end of a uuencode
|
|
321 (point))))))
|
6365
|
322 (log-buffer (get-buffer-create "*Store Output*"))
|
11332
|
323 (command "sh")
|
|
324 (uudecode-filename "(unknown filename)"))
|
|
325 (if (not sh-start)
|
|
326 (save-excursion
|
|
327 (goto-char (point-min))
|
|
328 (if (re-search-forward "^begin [0-7]+ " nil t)
|
|
329 (setq uudecode-filename
|
|
330 (buffer-substring (point)
|
|
331 (progn (end-of-line) (point)))))))
|
6365
|
332 (save-excursion
|
|
333 (set-buffer log-buffer)
|
|
334 (erase-buffer)
|
|
335 (if (not (file-directory-p store-directory))
|
|
336 (progn
|
11332
|
337 (insert "mkdir " directory "\n")
|
6365
|
338 (call-process "mkdir" nil log-buffer t store-directory)))
|
11332
|
339 (insert "cd " directory "\n")
|
|
340 (setq mh-store-default-directory directory)
|
|
341 (if (not sh-start)
|
6365
|
342 (progn
|
|
343 (setq command "uudecode")
|
11332
|
344 (insert uudecode-filename " being uudecoded...\n"))))
|
6365
|
345 (set-window-start (display-buffer log-buffer) 0) ;watch progress
|
11332
|
346 (let (value)
|
|
347 (let ((default-directory (file-name-as-directory store-directory)))
|
|
348 (setq value (call-process-region sh-start (point-max) command
|
|
349 nil log-buffer t)))
|
|
350 (set-buffer log-buffer)
|
|
351 (mh-handle-process-error command value))
|
6365
|
352 (insert "\n(mh-store finished)\n")))
|
|
353
|