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