Mercurial > emacs
annotate lisp/=mh-e.el @ 3283:e2a40a3baa4b
(Ficonify_frame, Fmake_frame_invisible):
Select some other frame. Move minibuffer off this frame.
(Fhandle_switch_frame): Don't call Ffocus_frame.
(Fredirect_frame_focus): Call Ffocus_frame here.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 30 May 1993 02:44:11 +0000 |
parents | 77a302be84da |
children | e533aed58919 |
rev | line source |
---|---|
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1 ;;; mh-e.el --- GNU Emacs interface to the MH mail system |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
2 |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
3 ;;; Copyright (C) 1985, 86, 87, 88, 90, 92, 93 Free Software Foundation |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
4 |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
5 (defconst mh-e-time-stamp "Time-stamp: <93/05/27 18:02:50 gildea>") |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
6 |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
7 ;; Maintainer: Stephen Gildea <gildea@lcs.mit.edu> |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
8 ;; Version: 3.8.1 |
811
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
804
diff
changeset
|
9 ;; Keywords: mail |
731 | 10 |
11 ;; GNU Emacs is distributed in the hope that it will be useful, | |
12 ;; but without any warranty. No author or distributor | |
13 ;; accepts responsibility to anyone for the consequences of using it | |
14 ;; or for whether it serves any particular purpose or works at all, | |
15 ;; unless he says so in writing. | |
16 | |
17 ;; Everyone is granted permission to copy, modify and redistribute | |
18 ;; GNU Emacs, but only under the conditions described in the | |
19 ;; document "GNU Emacs copying permission notice". An exact copy | |
20 ;; of the document is supposed to have been given to you along with | |
21 ;; GNU Emacs so that you can know how you may redistribute it all. | |
22 ;; It should be in a file named COPYING. Among other things, the | |
23 ;; copyright notice and this notice must be preserved on all copies. | |
24 | |
790
47ec7c4c42bc
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
731
diff
changeset
|
25 ;;; Commentary: |
47ec7c4c42bc
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
731
diff
changeset
|
26 |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
27 ;;; mh-e works with Emacs 18 or 19, and MH 5 or 6. |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
28 |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
29 ;;; HOW TO USE: |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
30 ;;; M-x mh-rmail to read mail. Type C-h m there for a list of commands. |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
31 ;;; C-u M-x mh-rmail to visit any folder. |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
32 ;;; M-x mh-smail to send mail. From within the mail reader, "m" works, too. |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
33 ;;; Your .emacs might benefit from these bindings: |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
34 ;;; (global-set-key "\C-xm" 'mh-smail) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
35 ;;; (global-set-key "\C-x4m" 'mh-smail-other-window) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
36 ;;; (global-set-key "\C-cr" 'mh-rmail) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
37 |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
38 ;;; MH (Message Handler) is a powerful mail reader. The MH newsgroup |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
39 ;;; is comp.mail.mh; the mailing list is mh-users@ics.uci.edu (send to |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
40 ;;; mh-users-request to be added). See the monthly Frequently Asked |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
41 ;;; Questions posting there for information on getting MH. |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
42 |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
43 ;;; NB. MH must have been compiled with the MHE compiler flag or several |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
44 ;;; features necessary mh-e will be missing from MH commands, specifically |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
45 ;;; the -build switch to repl and forw. |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
46 |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
47 ;;; Original version for Gosling emacs by Brian Reid, Stanford, 1982. |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
48 ;;; Modified by James Larus, BBN, July 1984 and UCB, 1984 & 1985. |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
49 ;;; Rewritten for GNU Emacs, James Larus 1985. larus@ginger.berkeley.edu |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
50 ;;; Modified by Stephen Gildea 1988. gildea@bbn.com |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
51 (defconst mh-e-RCS-id "$Header: mh-e.el,v 3.9 93/01/11 11:49:18 gildea Exp $") |
731 | 52 |
790
47ec7c4c42bc
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
731
diff
changeset
|
53 ;;; Code: |
47ec7c4c42bc
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
731
diff
changeset
|
54 |
731 | 55 |
56 | |
57 ;;; Constants: | |
58 | |
59 ;;; Set for local environment: | |
60 ;;;* These are now in paths.el. | |
61 ;;;(defvar mh-progs "/usr/new/mh/" "Directory containing MH commands.") | |
62 ;;;(defvar mh-lib "/usr/new/lib/mh/" "Directory of MH library.") | |
63 | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
64 (defvar mh-redist-full-contents nil |
731 | 65 "Non-nil if the `dist' command needs whole letter for redistribution. |
66 This is the case when `send' is compiled with the BERK option.") | |
67 | |
68 | |
69 ;;; Hooks: | |
70 | |
71 (defvar mh-folder-mode-hook nil | |
72 "Invoked in `mh-folder mode' on a new folder.") | |
73 | |
74 (defvar mh-letter-mode-hook nil | |
75 "Invoked in `mh-letter-mode' on a new letter.") | |
76 | |
77 (defvar mh-compose-letter-function nil | |
78 "Invoked in `mh-compose-and-send-mail' on a draft letter. | |
79 It is passed three arguments: TO recipients, SUBJECT, and CC recipients.") | |
80 | |
81 (defvar mh-before-send-letter-hook nil | |
82 "Invoked at the beginning of the \\[mh-send-letter] command.") | |
83 | |
84 (defvar mh-inc-folder-hook nil | |
85 "Invoked after incorporating mail into a folder with \\[mh-inc-folder].") | |
86 | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
87 (defvar mh-before-quit-hook nil |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
88 "Invoked by \\[mh-quit] before quitting mh-e. See also mh-quit-hook") |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
89 |
731 | 90 (defvar mh-quit-hook nil |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
91 "Invoked after quitting mh-e by \\[mh-quit]. See also mh-before-quit-hook") |
731 | 92 |
93 | |
94 (defvar mh-ins-string nil | |
95 "Temporarily set by `mh-insert-prefix' prior to running `mh-yank-hooks'.") | |
96 | |
97 (defvar mh-yank-hooks | |
98 '(lambda () | |
99 (save-excursion | |
100 (goto-char (point)) | |
101 (or (bolp) (forward-line 1)) | |
102 (while (< (point) (mark)) | |
103 (insert mh-ins-string) | |
104 (forward-line 1)))) | |
105 "Hook to run citation function. | |
106 Expects POINT and MARK to be set to the region to cite.") | |
107 | |
108 | |
109 ;;; Personal preferences: | |
110 | |
111 (defvar mh-clean-message-header nil | |
112 "*Non-nil means clean headers of messages that are displayed or inserted. | |
113 The variables `mh-visible-headers' and `mh-invisible-headers' control what | |
114 is removed.") | |
115 | |
116 (defvar mh-visible-headers nil | |
117 "*If non-nil, contains a regexp specifying the headers to keep when cleaning. | |
118 Only used if `mh-clean-message-header' is non-nil. Setting this variable | |
119 overrides `mh-invisible-headers'.") | |
120 | |
121 (defvar mhl-formfile nil | |
122 "*Name of format file to be used by mhl to show messages. | |
123 A value of T means use the default format file. | |
124 Nil means don't use mhl to format messages.") | |
125 | |
126 (defvar mh-lpr-command-format "lpr -p -J '%s'" | |
127 "*Format for Unix command that prints a message. | |
128 The string should be a Unix command line, with the string '%s' where | |
129 the job's name (folder and message number) should appear. The message text | |
130 is piped to this command.") | |
131 | |
132 (defvar mh-print-background nil | |
133 "*Print messages in the background if non-nil. | |
134 WARNING: do not delete the messages until printing is finished; | |
135 otherwise, your output may be truncated.") | |
136 | |
137 (defvar mh-summary-height 4 | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
138 "*Number of lines in summary window (including the mode line).") |
731 | 139 |
140 (defvar mh-recenter-summary-p nil | |
141 "*Recenter summary window when the show window is toggled off if non-nil.") | |
142 | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
143 (defvar mh-ins-buf-prefix "> " |
731 | 144 "*String to put before each non-blank line of a yanked or inserted message. |
145 Used when the message is inserted in an outgoing letter.") | |
146 | |
147 (defvar mh-do-not-confirm nil | |
148 "*Non-nil means do not prompt for confirmation before some commands. | |
149 Only affects certain innocuous commands.") | |
150 | |
151 (defvar mh-bury-show-buffer t | |
152 "*Non-nil means that the displayed show buffer for a folder is buried.") | |
153 | |
154 (defvar mh-delete-yanked-msg-window nil | |
155 "*Controls window display when a message is yanked by \\[mh-yank-cur-msg]. | |
156 If non-nil, yanking the current message into a draft letter deletes any | |
157 windows displaying the message.") | |
158 | |
159 (defvar mh-yank-from-start-of-msg t | |
160 "*Controls which part of a message is yanked by \\[mh-yank-cur-msg]. | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
161 If non-nil, include the entire message. If the symbol `body', then yank the |
731 | 162 message minus the header. If nil, yank only the portion of the message |
163 following the point. If the show buffer has a region, this variable is | |
164 ignored.") | |
165 | |
166 (defvar mh-reply-default-reply-to nil | |
167 "*Sets the person or persons to whom a reply will be sent. | |
168 If nil, prompt for recipient. If non-nil, then \\[mh-reply] will use this | |
169 value and it should be one of \"from\", \"to\", or \"cc\".") | |
170 | |
171 (defvar mh-recursive-folders nil | |
172 "*If non-nil, then commands which operate on folders do so recursively.") | |
173 | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
174 (defvar mh-unshar-default-directory "" |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
175 "*Default for directory name prompted for by mh-unshar-msg.") |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
176 |
731 | 177 |
178 ;;; Parameterize mh-e to work with different scan formats. The defaults work | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
179 ;;; with the standard MH scan listings. |
731 | 180 |
181 (defvar mh-cmd-note 4 | |
182 "Offset to insert notation.") | |
183 | |
184 (defvar mh-note-repl "-" | |
185 "String whose first character is used to notate replied to messages.") | |
186 | |
187 (defvar mh-note-forw "F" | |
188 "String whose first character is used to notate forwarded messages.") | |
189 | |
190 (defvar mh-note-dist "R" | |
191 "String whose first character is used to notate redistributed messages.") | |
192 | |
193 (defvar mh-good-msg-regexp "^....[^D^]" | |
194 "Regexp specifiying the scan lines that are 'good' messages.") | |
195 | |
196 (defvar mh-deleted-msg-regexp "^....D" | |
197 "Regexp matching scan lines of deleted messages.") | |
198 | |
199 (defvar mh-refiled-msg-regexp "^....\\^" | |
200 "Regexp matching scan lines of refiled messages.") | |
201 | |
202 (defvar mh-valid-scan-line "^ *[0-9]" | |
203 "Regexp matching scan lines for messages (not error messages).") | |
204 | |
205 (defvar mh-msg-number-regexp "^ *\\([0-9]+\\)" | |
206 "Regexp to find the number of a message in a scan line. | |
207 The message's number must be surrounded with \\( \\)") | |
208 | |
209 (defvar mh-msg-search-regexp "^[^0-9]*%d[^0-9]" | |
210 "Format string containing a regexp matching the scan listing for a message. | |
211 The desired message's number will be an argument to format.") | |
212 | |
213 (defvar mh-flagged-scan-msg-regexp "^....\\D\\|^....\\^\\|^....\\+\\|^.....%" | |
214 "Regexp matching flagged scan lines. | |
215 Matches lines marked as deleted, refiled, in a sequence, or the cur message.") | |
216 | |
217 (defvar mh-cur-scan-msg-regexp "^....\\+" | |
218 "Regexp matching scan line for the cur message.") | |
219 | |
220 (defvar mh-show-buffer-mode-line-buffer-id "{%%b} %s/%d" | |
221 "Format string to produce `mode-line-buffer-id' for show buffers. | |
222 First argument is folder name. Second is message number.") | |
223 | |
224 (defvar mh-partial-folder-mode-line-annotation "select" | |
225 "Annotation when displaying part of a folder. | |
226 The string is displayed after the folder's name. NIL for no annotation.") | |
227 | |
228 | |
229 ;;; Real constants: | |
230 | |
231 (defvar mh-invisible-headers | |
232 "^Received: \\|^Message-Id: \\|^Remailed-\\|^Via: \\|^Mail-from: \\|^Return-Path: \\|^In-Reply-To: \\|^Resent-" | |
233 "Regexp matching lines in a message header that are not to be shown. | |
234 If `mh-visible-headers' is non-nil, it is used instead to specify what | |
235 to keep.") | |
236 | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
237 (defvar mh-rejected-letter-start |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
238 (concat "^ ----- Unsent message follows -----$" ;from mail system |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
239 "\\|^------- Unsent Draft$" ;from MH itself |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
240 "\\|^ --- The unsent message follows ---$") ;from AIX mail system |
731 | 241 "Regexp specifying the beginning of the wrapper around a returned letter. |
242 This wrapper is generated by the mail system when rejecting a letter.") | |
243 | |
244 (defvar mh-to-field-choices '((?t . "To:") (?s . "Subject:") (?c . "Cc:") | |
245 (?b . "Bcc:") (?f . "Fcc:")) | |
246 "A-list of (character . field name) strings for mh-to-field.") | |
247 | |
248 | |
249 ;;; Global variables: | |
250 | |
251 (defvar mh-user-path "" | |
252 "User's mail folder.") | |
253 | |
254 (defvar mh-last-destination nil | |
255 "Destination of last refile or write command.") | |
256 | |
257 (defvar mh-folder-mode-map (make-keymap) | |
258 "Keymap for MH folders.") | |
259 | |
260 (defvar mh-letter-mode-map (copy-keymap text-mode-map) | |
261 "Keymap for composing mail.") | |
262 | |
263 (defvar mh-pick-mode-map (make-sparse-keymap) | |
264 "Keymap for searching folder.") | |
265 | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
266 (defvar mh-searching-folder nil |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
267 "Folder this pick is searching.") |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
268 |
731 | 269 (defvar mh-letter-mode-syntax-table nil |
270 "Syntax table used while in mh-e letter mode.") | |
271 | |
272 (if mh-letter-mode-syntax-table | |
273 () | |
274 (setq mh-letter-mode-syntax-table | |
275 (make-syntax-table text-mode-syntax-table)) | |
276 (set-syntax-table mh-letter-mode-syntax-table) | |
277 (modify-syntax-entry ?% "." mh-letter-mode-syntax-table)) | |
278 | |
279 (defvar mh-folder-list nil | |
280 "List of folder names for completion.") | |
281 | |
282 (defvar mh-draft-folder nil | |
283 "Name of folder containing draft messages. | |
284 NIL means do not use draft folder.") | |
285 | |
286 (defvar mh-unseen-seq nil | |
287 "Name of the unseen sequence.") | |
288 | |
289 (defvar mh-previous-window-config nil | |
290 "Window configuration before mh-e command.") | |
291 | |
292 (defvar mh-previous-seq nil | |
293 "Name of the sequence to which a message was last added.") | |
294 | |
295 | |
296 ;;; Macros and generic functions: | |
297 | |
298 (defmacro mh-push (v l) | |
299 (list 'setq l (list 'cons v l))) | |
300 | |
301 | |
302 (defmacro mh-when (pred &rest body) | |
303 (list 'cond (cons pred body))) | |
304 | |
305 | |
306 (defmacro with-mh-folder-updating (save-modification-flag-p &rest body) | |
307 ;; Format is (with-mh-folder-updating (SAVE-MODIFICATION-FLAG-P) &body BODY). | |
308 ;; Execute BODY, which can modify the folder buffer without having to | |
309 ;; worry about file locking or the read-only flag, and return its result. | |
310 ;; If SAVE-MODIFICATION-FLAG-P is non-nil, the buffer's modification | |
311 ;; flag is unchanged, otherwise it is cleared. | |
312 (setq save-modification-flag-p (car save-modification-flag-p)) ; CL style | |
313 (` (let ((folder-updating-mod-flag (buffer-modified-p))) | |
314 (prog1 | |
315 (let ((buffer-read-only nil) | |
316 (buffer-file-name nil)) ; don't let the buffer get locked | |
317 (,@ body)) | |
318 (, (if save-modification-flag-p | |
319 '(mh-set-folder-modified-p folder-updating-mod-flag) | |
320 '(mh-set-folder-modified-p nil))))))) | |
321 | |
322 | |
323 (defun mh-mapc (func list) | |
324 (while list | |
325 (funcall func (car list)) | |
326 (setq list (cdr list)))) | |
327 | |
328 | |
329 | |
330 ;;; Entry points: | |
331 | |
332 ;;;###autoload | |
333 (defun mh-rmail (&optional arg) | |
334 "Inc(orporate) new mail (no arg) or scan a MH mail box (arg given). | |
335 This front end uses the MH mail system, which uses different conventions | |
336 from the usual mail system." | |
337 (interactive "P") | |
338 (mh-find-path) | |
339 (if arg | |
340 (call-interactively 'mh-visit-folder) | |
341 (mh-inc-folder))) | |
342 | |
343 | |
344 ;;;###autoload | |
345 (defun mh-smail () | |
346 "Compose and send mail with the MH mail system." | |
347 (interactive) | |
348 (mh-find-path) | |
349 (call-interactively 'mh-send)) | |
350 | |
351 | |
352 (defun mh-smail-other-window () | |
353 "Compose and send mail in other window with the MH mail system." | |
354 (interactive) | |
355 (mh-find-path) | |
356 (call-interactively 'mh-send-other-window)) | |
357 | |
358 | |
359 | |
360 ;;; User executable mh-e commands: | |
361 | |
362 (defun mh-burst-digest () | |
363 "Burst apart the current message, which should be a digest. | |
364 The message is replaced by its table of contents and the letters from the | |
365 digest are inserted into the folder after that message." | |
366 (interactive) | |
367 (let ((digest (mh-get-msg-num t))) | |
368 (mh-process-or-undo-commands mh-current-folder) | |
369 (mh-set-folder-modified-p t) ; lock folder while bursting | |
370 (message "Bursting digest...") | |
371 (mh-exec-cmd "burst" mh-current-folder digest "-inplace") | |
372 (mh-scan-folder mh-current-folder (format "%d-last" mh-first-msg-num)) | |
373 (message "Bursting digest...done"))) | |
374 | |
375 | |
376 (defun mh-copy-msg (prefix-provided msg-or-seq dest) | |
377 "Copy specified MESSAGE(s) to another FOLDER without deleting them. | |
378 Default is the displayed message. If optional prefix argument is | |
379 provided, then prompt for the message sequence." | |
380 (interactive (list current-prefix-arg | |
381 (if current-prefix-arg | |
382 (mh-read-seq-default "Copy" t) | |
383 (mh-get-msg-num t)) | |
384 (mh-prompt-for-folder "Copy to" "" t))) | |
385 (mh-exec-cmd "refile" msg-or-seq "-link" "-src" mh-current-folder dest) | |
386 (if prefix-provided | |
387 (mh-notate-seq msg-or-seq ?C mh-cmd-note) | |
388 (mh-notate msg-or-seq ?C mh-cmd-note))) | |
389 | |
390 | |
391 (defun mh-delete-msg (msg-or-seq) | |
392 "Mark the specified MESSAGE(s) for subsequent deletion and move to the next. | |
393 Default is the displayed message. If optional prefix argument is | |
394 given then prompt for the message sequence." | |
395 (interactive (list (if current-prefix-arg | |
396 (mh-read-seq-default "Delete" t) | |
397 (mh-get-msg-num t)))) | |
398 (if (numberp msg-or-seq) | |
399 (mh-delete-a-msg msg-or-seq) | |
400 (mh-map-to-seq-msgs 'mh-delete-a-msg msg-or-seq)) | |
401 (mh-next-msg)) | |
402 | |
403 | |
404 (defun mh-delete-msg-no-motion (msg-or-seq) | |
405 "Mark the specified MESSAGE(s) for subsequent deletion. | |
406 Default is the displayed message. If optional prefix argument is | |
407 provided, then prompt for the message sequence." | |
408 (interactive (list (if current-prefix-arg | |
409 (mh-read-seq-default "Delete" t) | |
410 (mh-get-msg-num t)))) | |
411 (if (numberp msg-or-seq) | |
412 (mh-delete-a-msg msg-or-seq) | |
413 (mh-map-to-seq-msgs 'mh-delete-a-msg msg-or-seq))) | |
414 | |
415 | |
416 (defun mh-delete-msg-from-seq (prefix-provided msg-or-seq &optional from-seq) | |
417 "Delete MESSAGE (default: displayed message) from SEQUENCE. | |
418 If optional prefix argument provided, then delete all messages | |
419 from a sequence." | |
420 (interactive (let ((argp current-prefix-arg)) | |
421 (list argp | |
422 (if argp | |
423 (mh-read-seq-default "Delete" t) | |
424 (mh-get-msg-num t)) | |
425 (if (not argp) | |
426 (mh-read-seq-default "Delete from" t))))) | |
427 (if prefix-provided | |
428 (mh-remove-seq msg-or-seq) | |
429 (mh-remove-msg-from-seq msg-or-seq from-seq))) | |
430 | |
431 | |
432 (defun mh-edit-again (msg) | |
433 "Clean-up a draft or a message previously sent and make it resendable." | |
434 (interactive (list (mh-get-msg-num t))) | |
435 (let* ((from-folder mh-current-folder) | |
436 (config (current-window-configuration)) | |
437 (draft | |
438 (cond ((and mh-draft-folder (equal from-folder mh-draft-folder)) | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
439 (pop-to-buffer (find-file-noselect (mh-msg-filename msg)) t) |
731 | 440 (rename-buffer (format "draft-%d" msg)) |
441 (buffer-name)) | |
442 (t | |
443 (mh-read-draft "clean-up" (mh-msg-filename msg) nil))))) | |
444 (mh-clean-msg-header (point-min) | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
445 "^Date:\\|^Received:\\|^Message-Id:\\|^From:\\|^Delivery-Date:" |
731 | 446 nil) |
447 (goto-char (point-min)) | |
448 (set-buffer-modified-p nil) | |
449 (mh-compose-and-send-mail draft "" from-folder nil nil nil nil nil nil | |
450 config))) | |
451 | |
452 | |
453 (defun mh-execute-commands () | |
454 "Process outstanding delete and refile requests." | |
455 (interactive) | |
456 (if mh-narrowed-to-seq (mh-widen)) | |
457 (mh-process-commands mh-current-folder) | |
458 (mh-set-scan-mode) | |
459 (mh-goto-cur-msg) ; after mh-set-scan-mode for efficiency | |
460 (mh-make-folder-mode-line) | |
461 t) ; return t for write-file-hooks | |
462 | |
463 | |
464 (defun mh-extract-rejected-mail (msg) | |
465 "Extract a letter returned by the mail system and make it resendable. | |
466 Default is the displayed message." | |
467 (interactive (list (mh-get-msg-num t))) | |
468 (let ((from-folder mh-current-folder) | |
469 (config (current-window-configuration)) | |
470 (draft (mh-read-draft "extraction" (mh-msg-filename msg) nil))) | |
471 (goto-char (point-min)) | |
472 (cond ((re-search-forward mh-rejected-letter-start nil t) | |
473 (forward-char 1) | |
474 (delete-region (point-min) (point)) | |
475 (mh-clean-msg-header (point-min) | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
476 "^Date:\\|^Received:\\|^Message-Id:\\|^From:\\|^Sender:\\|^Return-Path:" |
731 | 477 nil)) |
478 (t | |
479 (message "Does not appear to be a rejected letter."))) | |
480 (goto-char (point-min)) | |
481 (set-buffer-modified-p nil) | |
482 (mh-compose-and-send-mail draft "" from-folder msg (mh-get-field "To") | |
483 (mh-get-field "From") (mh-get-field "cc") | |
484 nil nil config))) | |
485 | |
486 | |
487 (defun mh-first-msg () | |
488 "Move to the first message." | |
489 (interactive) | |
490 (goto-char (point-min))) | |
491 | |
492 | |
493 (defun mh-forward (prefix-provided msg-or-seq to cc) | |
494 "Forward MESSAGE(s) (default: displayed message). | |
495 If optional prefix argument provided, then prompt for the message sequence." | |
496 (interactive (list current-prefix-arg | |
497 (if current-prefix-arg | |
498 (mh-read-seq-default "Forward" t) | |
499 (mh-get-msg-num t)) | |
500 (read-string "To: ") | |
501 (read-string "Cc: "))) | |
502 (let* ((folder mh-current-folder) | |
503 (config (current-window-configuration)) | |
504 ;; forw always leaves file in "draft" since it doesn't have -draft | |
505 (draft-name (expand-file-name "draft" mh-user-path)) | |
506 (draft (cond ((or (not (file-exists-p draft-name)) | |
507 (y-or-n-p "The file 'draft' exists. Discard it? ")) | |
508 (mh-exec-cmd "forw" | |
509 "-build" mh-current-folder msg-or-seq) | |
510 (prog1 | |
511 (mh-read-draft "" draft-name t) | |
512 (mh-insert-fields "To:" to "Cc:" cc) | |
513 (set-buffer-modified-p nil))) | |
514 (t | |
515 (mh-read-draft "" draft-name nil))))) | |
516 (goto-char (point-min)) | |
517 (re-search-forward "^------- Forwarded Message") | |
518 (forward-line -1) | |
519 (narrow-to-region (point) (point-max)) | |
520 (let* ((subject (save-excursion (mh-get-field "From:"))) | |
521 (trim (string-match "<" subject)) | |
522 (forw-subject (save-excursion (mh-get-field "Subject:")))) | |
523 (if trim | |
524 (setq subject (substring subject 0 (1- trim)))) | |
525 (widen) | |
526 (save-excursion | |
527 (mh-insert-fields "Subject:" (format "[%s: %s]" subject forw-subject))) | |
528 (delete-other-windows) | |
529 (if prefix-provided | |
530 (mh-add-msgs-to-seq (mh-seq-to-msgs msg-or-seq) 'forwarded t) | |
531 (mh-add-msgs-to-seq msg-or-seq 'forwarded t)) | |
532 (mh-compose-and-send-mail draft "" folder msg-or-seq | |
533 to subject cc | |
534 mh-note-forw "Forwarded:" | |
535 config)))) | |
536 | |
537 | |
538 (defun mh-goto-msg (number &optional no-error-if-no-message dont-show) | |
539 "Position the cursor at message NUMBER. | |
540 Non-nil second argument means do not signal an error if message does not exist. | |
541 Non-nil third argument means not to show the message. | |
542 Return non-nil if cursor is at message." | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
543 (interactive "NGoto message: ") |
731 | 544 (let ((cur-msg (mh-get-msg-num nil)) |
545 (starting-place (point)) | |
546 (msg-pattern (mh-msg-search-pat number))) | |
547 (cond ((cond ((and cur-msg (= cur-msg number)) t) | |
548 ((and cur-msg | |
549 (< cur-msg number) | |
550 (re-search-forward msg-pattern nil t)) t) | |
551 ((and cur-msg | |
552 (> cur-msg number) | |
553 (re-search-backward msg-pattern nil t)) t) | |
554 (t ; Do thorough search of buffer | |
555 (goto-char (point-max)) | |
556 (re-search-backward msg-pattern nil t))) | |
557 (beginning-of-line) | |
558 (if (not dont-show) (mh-maybe-show number)) | |
559 t) | |
560 (t | |
561 (goto-char starting-place) | |
562 (if (not no-error-if-no-message) | |
563 (error "No message %d" number)) | |
564 nil)))) | |
565 | |
566 | |
567 (defun mh-inc-folder (&optional maildrop-name) | |
568 "Inc(orporate) new mail into +inbox. | |
569 Optional prefix argument specifies an alternate maildrop from the default. | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
570 If this is given, incorporate mail into the current folder, rather |
731 | 571 than +inbox. Run `mh-inc-folder-hook' after incorporating new mail." |
572 (interactive (list (if current-prefix-arg | |
573 (expand-file-name | |
574 (read-file-name "inc mail from file: " | |
575 mh-user-path))))) | |
576 (let ((config (current-window-configuration))) | |
577 (if (not maildrop-name) | |
578 (cond ((not (get-buffer "+inbox")) | |
579 (mh-make-folder "+inbox") | |
580 (setq mh-previous-window-config config)) | |
581 ((not (eq (current-buffer) (get-buffer "+inbox"))) | |
582 (switch-to-buffer "+inbox") | |
583 (setq mh-previous-window-config config))))) | |
584 (mh-get-new-mail maildrop-name) | |
585 (run-hooks 'mh-inc-folder-hook)) | |
586 | |
587 | |
588 (defun mh-kill-folder () | |
589 "Remove the current folder." | |
590 (interactive) | |
591 (if (or mh-do-not-confirm | |
592 (yes-or-no-p (format "Remove folder %s? " mh-current-folder))) | |
593 (let ((folder mh-current-folder)) | |
594 (mh-set-folder-modified-p t) ; lock folder to kill it | |
595 (mh-exec-cmd-daemon "rmf" folder) | |
596 (mh-remove-folder-from-folder-list folder) | |
597 (message "Folder %s removed" folder) | |
598 (mh-set-folder-modified-p nil) ; so kill-buffer doesn't complain | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
599 (if (get-buffer mh-show-buffer) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
600 (kill-buffer mh-show-buffer)) |
731 | 601 (kill-buffer folder)) |
602 (message "Folder not removed"))) | |
603 | |
604 | |
605 (defun mh-last-msg () | |
606 "Move to the last message." | |
607 (interactive) | |
608 (goto-char (point-max)) | |
609 (while (and (not (bobp)) (looking-at "^$")) | |
610 (forward-line -1))) | |
611 | |
612 | |
613 (defun mh-list-folders () | |
614 "List mail folders." | |
615 (interactive) | |
616 (with-output-to-temp-buffer " *mh-temp*" | |
617 (save-excursion | |
618 (switch-to-buffer " *mh-temp*") | |
619 (erase-buffer) | |
620 (message "Listing folders...") | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
621 (mh-exec-cmd-output "folders" t (if mh-recursive-folders |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
622 "-recurse" |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
623 "-norecurse")) |
731 | 624 (goto-char (point-min)) |
625 (message "Listing folders...done")))) | |
626 | |
627 | |
628 (defun mh-msg-is-in-seq (msg) | |
629 "Display the sequences that contain MESSAGE (default: displayed message)." | |
630 (interactive (list (mh-get-msg-num t))) | |
631 (message "Message %d is in sequences: %s" | |
632 msg | |
633 (mapconcat 'concat | |
634 (mh-list-to-string (mh-seq-containing-msg msg)) | |
635 " "))) | |
636 | |
637 | |
638 (defun mh-narrow-to-seq (seq) | |
639 "Restrict display of this folder to just messages in a sequence. | |
640 Reads which sequence. Use \\[mh-widen] to undo this command." | |
641 (interactive (list (mh-read-seq "Narrow to" t))) | |
642 (let ((eob (point-max))) | |
643 (with-mh-folder-updating (t) | |
644 (cond ((mh-seq-to-msgs seq) | |
645 (mh-copy-seq-to-point seq eob) | |
646 (narrow-to-region eob (point-max)) | |
647 (mh-make-folder-mode-line (symbol-name seq)) | |
648 (mh-recenter nil) | |
649 (setq mh-narrowed-to-seq seq)) | |
650 (t | |
651 (error "No messages in sequence `%s'" (symbol-name seq))))))) | |
652 | |
653 | |
654 (defun mh-next-undeleted-msg (&optional arg) | |
655 "Move to next undeleted message in window." | |
656 (interactive "P") | |
657 (forward-line (prefix-numeric-value arg)) | |
658 (setq mh-next-direction 'forward) | |
659 (cond ((re-search-forward mh-good-msg-regexp nil 0 arg) | |
660 (beginning-of-line) | |
661 (mh-maybe-show)) | |
662 (t | |
663 (forward-line -1) | |
664 (if (get-buffer mh-show-buffer) | |
665 (delete-windows-on mh-show-buffer))))) | |
666 | |
667 | |
668 (defun mh-pack-folder (range) | |
669 "Renumber the messages of a folder to be 1..n. | |
670 First, offer to execute any outstanding commands for the current folder. | |
671 If optional prefix argument provided, prompt for the range of messages | |
672 to display after packing. Otherwise, show the entire folder." | |
673 (interactive (list (if current-prefix-arg | |
674 (mh-read-msg-range | |
675 "Range to scan after packing [all]? ") | |
676 "all"))) | |
677 (mh-pack-folder-1 range) | |
678 (mh-goto-cur-msg) | |
679 (message "Packing folder...done")) | |
680 | |
681 | |
682 (defun mh-pipe-msg (prefix-provided command) | |
683 "Pipe the current message through the given shell COMMAND. | |
684 If optional prefix argument is provided, send the entire message. | |
685 Otherwise just send the message's body." | |
686 (interactive | |
687 (list current-prefix-arg (read-string "Shell command on message: "))) | |
688 (save-excursion | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
689 (mh-display-msg (mh-get-msg-num t) mh-current-folder) ;update show buffer |
731 | 690 (goto-char (point-min)) |
691 (if (not prefix-provided) (search-forward "\n\n")) | |
692 (shell-command-on-region (point) (point-max) command nil))) | |
693 | |
694 | |
695 (defun mh-refile-msg (prefix-provided msg-or-seq dest) | |
696 "Refile MESSAGE(s) (default: displayed message) in FOLDER. | |
697 If optional prefix argument provided, then prompt for message sequence." | |
698 (interactive | |
699 (list current-prefix-arg | |
700 (if current-prefix-arg | |
701 (mh-read-seq-default "Refile" t) | |
702 (mh-get-msg-num t)) | |
703 (intern | |
704 (mh-prompt-for-folder "Destination" | |
705 (if (eq 'refile (car mh-last-destination)) | |
706 (symbol-name (cdr mh-last-destination)) | |
707 "") | |
708 t)))) | |
709 (setq mh-last-destination (cons 'refile dest)) | |
710 (if prefix-provided | |
711 (mh-map-to-seq-msgs 'mh-refile-a-msg msg-or-seq dest) | |
712 (mh-refile-a-msg msg-or-seq dest)) | |
713 (mh-next-msg)) | |
714 | |
715 | |
716 (defun mh-refile-or-write-again (msg) | |
717 "Re-execute the last refile or write command on the given MESSAGE. | |
718 Default is the displayed message. Use the same folder or file as the | |
719 previous refile or write command." | |
720 (interactive (list (mh-get-msg-num t))) | |
721 (if (null mh-last-destination) | |
722 (error "No previous refile or write")) | |
723 (cond ((eq (car mh-last-destination) 'refile) | |
724 (mh-refile-a-msg msg (cdr mh-last-destination)) | |
725 (message "Destination folder: %s" (cdr mh-last-destination))) | |
726 (t | |
727 (mh-write-msg-to-file msg (cdr mh-last-destination)) | |
728 (message "Destination: %s" (cdr mh-last-destination)))) | |
729 (mh-next-msg)) | |
730 | |
731 | |
732 (defun mh-reply (prefix-provided msg) | |
733 "Reply to a MESSAGE (default: displayed message). | |
734 If optional prefix argument provided, then include the message in the reply | |
735 using filter mhl.reply in your MH directory." | |
736 (interactive (list current-prefix-arg (mh-get-msg-num t))) | |
737 (let ((minibuffer-help-form | |
738 "from => Sender only\nto => Sender and primary recipients\ncc or all => Sender and all recipients")) | |
739 (let ((reply-to (or mh-reply-default-reply-to | |
740 (completing-read "Reply to whom: " | |
741 '(("from") ("to") ("cc") ("all")) | |
742 nil | |
743 t))) | |
744 (folder mh-current-folder) | |
745 (show-buffer mh-show-buffer) | |
746 (config (current-window-configuration))) | |
747 (message "Composing a reply...") | |
748 (cond ((or (equal reply-to "from") (equal reply-to "")) | |
749 (apply 'mh-exec-cmd | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
750 "repl" "-build" "-noquery" |
731 | 751 "-nodraftfolder" mh-current-folder |
752 msg | |
753 "-nocc" "all" | |
754 (if prefix-provided | |
755 (list "-filter" "mhl.reply")))) | |
756 ((equal reply-to "to") | |
757 (apply 'mh-exec-cmd | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
758 "repl" "-build" "-noquery" |
731 | 759 "-nodraftfolder" mh-current-folder |
760 msg | |
761 "-cc" "to" | |
762 (if prefix-provided | |
763 (list "-filter" "mhl.reply")))) | |
764 ((or (equal reply-to "cc") (equal reply-to "all")) | |
765 (apply 'mh-exec-cmd | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
766 "repl" "-build" "-noquery" |
731 | 767 "-nodraftfolder" mh-current-folder |
768 msg | |
769 "-cc" "all" "-nocc" "me" | |
770 (if prefix-provided | |
771 (list "-filter" "mhl.reply"))))) | |
772 | |
773 (let ((draft (mh-read-draft "reply" | |
774 (expand-file-name "reply" mh-user-path) | |
775 t))) | |
776 (delete-other-windows) | |
777 (set-buffer-modified-p nil) | |
778 | |
779 (let ((to (mh-get-field "To:")) | |
780 (subject (mh-get-field "Subject:")) | |
781 (cc (mh-get-field "Cc:"))) | |
782 (goto-char (point-min)) | |
783 (mh-goto-header-end 1) | |
784 (if (not prefix-provided) | |
785 (mh-display-msg msg folder)) | |
786 (mh-add-msgs-to-seq msg 'answered t) | |
787 (message "Composing a reply...done") | |
788 (mh-compose-and-send-mail draft "" folder msg to subject cc | |
789 mh-note-repl "Replied:" config)))))) | |
790 | |
791 | |
792 (defun mh-quit () | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
793 "Quit mh-e. |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
794 Start by running mh-before-quit-hook. Restore the previous window |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
795 configuration, if one exists. Finish by running mh-quit-hook." |
731 | 796 (interactive) |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
797 (run-hooks 'mh-before-quit-hook) |
731 | 798 (if mh-previous-window-config |
799 (set-window-configuration mh-previous-window-config)) | |
800 (run-hooks 'mh-quit-hook)) | |
801 | |
802 | |
803 (defun mh-page-digest () | |
804 "Advance displayed message to next digested message." | |
805 (interactive) | |
806 (save-excursion | |
807 (mh-show-message-in-other-window) | |
808 ;; Go to top of screen (in case user moved point). | |
809 (move-to-window-line 0) | |
810 (let ((case-fold-search nil)) | |
811 ;; Search for blank line and then for From: | |
812 (mh-when (not (and (search-forward "\n\n" nil t) | |
813 (search-forward "From:" nil t))) | |
814 (other-window -1) | |
815 (error "No more messages"))) | |
816 ;; Go back to previous blank line, then forward to the first non-blank. | |
817 (search-backward "\n\n" nil t) | |
818 (forward-line 2) | |
819 (mh-recenter 0) | |
820 (other-window -1))) | |
821 | |
822 | |
823 (defun mh-page-digest-backwards () | |
824 "Back up displayed message to previous digested message." | |
825 (interactive) | |
826 (save-excursion | |
827 (mh-show-message-in-other-window) | |
828 ;; Go to top of screen (in case user moved point). | |
829 (move-to-window-line 0) | |
830 (let ((case-fold-search nil)) | |
831 (beginning-of-line) | |
832 (mh-when (not (and (search-backward "\n\n" nil t) | |
833 (search-backward "From:" nil t))) | |
834 (other-window -1) | |
835 (error "No more messages"))) | |
836 ;; Go back to previous blank line, then forward to the first non-blank. | |
837 (search-backward "\n\n" nil t) | |
838 (forward-line 2) | |
839 (mh-recenter 0) | |
840 (other-window -1))) | |
841 | |
842 | |
843 (defun mh-page-msg (&optional arg) | |
844 "Page the displayed message forwards. | |
845 Scrolls ARG lines or a full screen if no argument is supplied." | |
846 (interactive "P") | |
847 (scroll-other-window arg)) | |
848 | |
849 | |
850 (defun mh-previous-page (&optional arg) | |
851 "Page the displayed message backwards. | |
852 Scrolls ARG lines or a full screen if no argument is supplied." | |
853 (interactive "P") | |
854 (save-excursion | |
855 (mh-show-message-in-other-window) | |
856 (unwind-protect | |
857 (scroll-down arg) | |
858 (other-window -1)))) | |
859 | |
860 | |
861 (defun mh-previous-undeleted-msg (&optional arg) | |
862 "Move to previous undeleted message in window." | |
863 (interactive "p") | |
864 (setq mh-next-direction 'backward) | |
865 (beginning-of-line) | |
866 (cond ((re-search-backward mh-good-msg-regexp nil 0 arg) | |
867 (mh-maybe-show)) | |
868 (t | |
869 (if (get-buffer mh-show-buffer) | |
870 (delete-windows-on mh-show-buffer))))) | |
871 | |
872 | |
873 (defun mh-print-msg (prefix-provided msg-or-seq) | |
874 "Print MESSAGE(s) (default: displayed message) on a line printer. | |
875 If optional prefix argument provided, then prompt for the message sequence." | |
876 (interactive (list current-prefix-arg | |
877 (if current-prefix-arg | |
878 (reverse (mh-seq-to-msgs | |
879 (mh-read-seq-default "Print" t))) | |
880 (mh-get-msg-num t)))) | |
881 (if prefix-provided | |
882 (message "Printing sequence...") | |
883 (message "Printing message...")) | |
884 (let ((print-command | |
885 (if prefix-provided | |
886 (format "(scan -clear %s ; %s -nobell -clear %s %s) | %s" | |
887 (mapconcat (function (lambda (msg) msg)) msg-or-seq " ") | |
888 (expand-file-name "mhl" mh-lib) | |
889 (if (stringp mhl-formfile) | |
890 (format "-form %s" mhl-formfile) | |
891 "") | |
892 (mh-msg-filenames msg-or-seq) | |
893 (format mh-lpr-command-format | |
894 (if prefix-provided | |
895 (format "Sequence from %s" mh-current-folder) | |
896 (format "%s/%d" mh-current-folder | |
897 msg-or-seq)))) | |
898 (format "%s -nobell -clear %s %s | %s" | |
899 (expand-file-name "mhl" mh-lib) | |
900 (mh-msg-filename msg-or-seq) | |
901 (if (stringp mhl-formfile) | |
902 (format "-form %s" mhl-formfile) | |
903 "") | |
904 (format mh-lpr-command-format | |
905 (if prefix-provided | |
906 (format "Sequence from %s" mh-current-folder) | |
907 (format "%s/%d" mh-current-folder | |
908 msg-or-seq))))))) | |
909 (if mh-print-background | |
910 (mh-exec-cmd-daemon shell-file-name "-c" print-command) | |
911 (call-process shell-file-name nil nil nil "-c" print-command)) | |
912 (if prefix-provided | |
913 (mh-notate-seq msg-or-seq ?P mh-cmd-note) | |
914 (mh-notate msg-or-seq ?P mh-cmd-note)) | |
915 (mh-add-msgs-to-seq msg-or-seq 'printed t) | |
916 (if prefix-provided | |
917 (message "Printing sequence...done") | |
918 (message "Printing message...done")))) | |
919 | |
920 | |
921 (defun mh-put-msg-in-seq (prefix-provided from to) | |
922 "Add MESSAGE(s) (default: displayed message) to SEQUENCE. | |
923 If optional prefix argument provided, then prompt for the message sequence." | |
924 (interactive (list current-prefix-arg | |
925 (if current-prefix-arg | |
926 (mh-seq-to-msgs | |
927 (mh-read-seq-default "Add messages from" t)) | |
928 (mh-get-msg-num t)) | |
929 (mh-read-seq-default "Add to" nil))) | |
930 (setq mh-previous-seq to) | |
931 (mh-add-msgs-to-seq from to)) | |
932 | |
933 | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
934 (defun mh-rescan-folder (&optional range) |
731 | 935 "Rescan a folder after optionally processing the outstanding commands. |
936 If optional prefix argument is provided, prompt for the range of | |
937 messages to display. Otherwise show the entire folder." | |
938 (interactive (list (if current-prefix-arg | |
939 (mh-read-msg-range "Range to scan [all]? ") | |
940 nil))) | |
941 (setq mh-next-direction 'forward) | |
942 (mh-scan-folder mh-current-folder (or range "all"))) | |
943 | |
944 | |
945 (defun mh-redistribute (to cc msg) | |
946 "Redistribute a letter. | |
947 Depending on how your copy of MH was compiled, you may need to change the | |
948 setting of the variable mh-redist-full-contents. See its documentation." | |
949 (interactive (list (read-string "Redist-To: ") | |
950 (read-string "Redist-Cc: ") | |
951 (mh-get-msg-num t))) | |
952 (save-window-excursion | |
953 (let ((folder mh-current-folder) | |
954 (draft (mh-read-draft "redistribution" | |
955 (if mh-redist-full-contents | |
956 (mh-msg-filename msg) | |
957 nil) | |
958 nil))) | |
959 (mh-goto-header-end 0) | |
960 (insert "Resent-To: " to "\n") | |
961 (if (not (equal cc "")) (insert "Resent-cc: " cc "\n")) | |
962 (mh-clean-msg-header (point-min) | |
963 "^Message-Id:\\|^Received:\\|^Return-Path:\\|^Sender:\\|^Date:\\|^From:" | |
964 nil) | |
965 (save-buffer) | |
966 (message "Redistributing...") | |
967 (if mh-redist-full-contents | |
968 (call-process "/bin/sh" nil 0 nil "-c" | |
969 (format "mhdist=1 mhaltmsg=%s %s -push %s" | |
970 (buffer-file-name) | |
971 (expand-file-name "send" mh-progs) | |
972 (buffer-file-name))) | |
973 (call-process "/bin/sh" nil 0 nil "-c" | |
974 (format "mhdist=1 mhaltmsg=%s mhannotate=1 %s -push %s" | |
975 (mh-msg-filename msg folder) | |
976 (expand-file-name "send" mh-progs) | |
977 (buffer-file-name)))) | |
978 (mh-annotate-msg msg folder mh-note-dist | |
979 "-component" "Resent:" | |
980 "-text" (format "\"%s %s\"" to cc)) | |
981 (kill-buffer draft) | |
982 (message "Redistributing...done")))) | |
983 | |
984 | |
985 (defun mh-write-msg-to-file (msg file) | |
986 "Append MESSAGE to the end of a FILE." | |
987 (interactive | |
988 (list (mh-get-msg-num t) | |
989 (let ((default-dir (if (eq 'write (car mh-last-destination)) | |
990 (file-name-directory (cdr mh-last-destination)) | |
991 default-directory))) | |
992 (read-file-name "Save message in file: " default-dir | |
993 (expand-file-name "mail.out" default-dir))))) | |
994 (let ((file-name (mh-msg-filename msg)) | |
995 (output-file (mh-expand-file-name file))) | |
996 (setq mh-last-destination (cons 'write file)) | |
997 (save-excursion | |
998 (set-buffer (get-buffer-create " *mh-temp*")) | |
999 (erase-buffer) | |
1000 (insert-file-contents file-name) | |
1001 (append-to-file (point-min) (point-max) output-file)))) | |
1002 | |
1003 | |
1004 (defun mh-search-folder (folder) | |
1005 "Search FOLDER for messages matching a pattern." | |
1006 (interactive (list (mh-prompt-for-folder "Search" | |
1007 mh-current-folder | |
1008 t))) | |
1009 (switch-to-buffer-other-window "pick-pattern") | |
1010 (if (or (zerop (buffer-size)) | |
1011 (not (y-or-n-p "Reuse pattern? "))) | |
1012 (mh-make-pick-template) | |
1013 (message "")) | |
1014 (setq mh-searching-folder folder)) | |
1015 | |
1016 | |
1017 (defun mh-send (to cc subject) | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1018 "Compose and send a letter. |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1019 The letter is composed in mh-letter-mode; see its documentation for more |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1020 details. If `mh-compose-letter-function' is defined, it is called on the |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1021 draft and passed three arguments: to, subject, and cc." |
731 | 1022 (interactive "sTo: \nsCc: \nsSubject: ") |
1023 (let ((config (current-window-configuration))) | |
1024 (delete-other-windows) | |
1025 (mh-send-sub to cc subject config))) | |
1026 | |
1027 | |
1028 (defun mh-send-other-window (to cc subject) | |
1029 "Compose and send a letter in another window.." | |
1030 (interactive "sTo: \nsCc: \nsSubject: ") | |
1031 (let ((pop-up-windows t)) | |
1032 (mh-send-sub to cc subject (current-window-configuration)))) | |
1033 | |
1034 | |
1035 (defun mh-send-sub (to cc subject config) | |
1036 "Do the real work of composing and sending a letter. | |
1037 Expects the TO, CC, and SUBJECT fields as arguments. | |
1038 CONFIG is the window configuration before sending mail." | |
1039 (let ((folder mh-current-folder) | |
1040 (msg-num (mh-get-msg-num nil))) | |
1041 (message "Composing a message...") | |
1042 (let ((draft (mh-read-draft | |
1043 "message" | |
1044 (if (file-exists-p | |
1045 (expand-file-name "components" mh-user-path)) | |
1046 (expand-file-name "components" mh-user-path) | |
1047 (if (file-exists-p | |
1048 (expand-file-name "components" mh-lib)) | |
1049 (expand-file-name "components" mh-lib) | |
1050 (error "Can't find components file"))) | |
1051 nil))) | |
1052 (mh-insert-fields "To:" to "Subject:" subject "Cc:" cc) | |
1053 (set-buffer-modified-p nil) | |
1054 (goto-char (point-max)) | |
1055 (message "Composing a message...done") | |
1056 (mh-compose-and-send-mail draft "" folder msg-num | |
1057 to subject cc | |
1058 nil nil config)))) | |
1059 | |
1060 | |
1061 (defun mh-show (&optional msg) | |
1062 "Show MESSAGE (default: displayed message). | |
1063 Forces a two-window display with the folder window on top (size | |
1064 mh-summary-height) and the show buffer below it." | |
1065 (interactive) | |
1066 (if (not msg) | |
1067 (setq msg (mh-get-msg-num t))) | |
1068 (setq mh-showing t) | |
1069 (mh-set-mode-name "mh-e show") | |
1070 (if (not (eql (next-window (minibuffer-window)) (selected-window))) | |
1071 (delete-other-windows)) ; force ourself to the top window | |
1072 (let ((folder mh-current-folder)) | |
1073 (mh-show-message-in-other-window) | |
1074 (mh-display-msg msg folder)) | |
1075 (other-window -1) | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1076 (if (not (= (1+ (window-height)) (screen-height))) ;not horizontally split |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1077 (shrink-window (- (window-height) mh-summary-height))) |
731 | 1078 (mh-recenter nil) |
1079 (if (not (memq msg mh-seen-list)) (mh-push msg mh-seen-list))) | |
1080 | |
1081 | |
1082 (defun mh-sort-folder () | |
1083 "Sort the messages in the current folder by date." | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1084 (interactive) |
731 | 1085 (mh-process-or-undo-commands mh-current-folder) |
1086 (setq mh-next-direction 'forward) | |
1087 (mh-set-folder-modified-p t) ; lock folder while sorting | |
1088 (message "Sorting folder...") | |
1089 (mh-exec-cmd "sortm" mh-current-folder) | |
1090 (message "Sorting folder...done") | |
1091 (mh-scan-folder mh-current-folder "all")) | |
1092 | |
1093 | |
1094 (defun mh-toggle-showing () | |
1095 "Toggle the scanning mode/showing mode of displaying messages." | |
1096 (interactive) | |
1097 (if mh-showing | |
1098 (mh-set-scan-mode) | |
1099 (mh-show))) | |
1100 | |
1101 | |
1102 (defun mh-undo (prefix-provided msg-or-seq) | |
1103 "Undo the deletion or refile of the specified MESSAGE(s). | |
1104 Default is the displayed message. If optional prefix argument is | |
1105 provided, then prompt for the message sequence." | |
1106 (interactive (list current-prefix-arg | |
1107 (if current-prefix-arg | |
1108 (mh-read-seq-default "Undo" t) | |
1109 (mh-get-msg-num t)))) | |
1110 (cond (prefix-provided | |
1111 (mh-mapc (function mh-undo-msg) (mh-seq-to-msgs msg-or-seq))) | |
1112 (t | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1113 (let ((original-position (point))) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1114 (beginning-of-line) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1115 (while (not (or (looking-at mh-deleted-msg-regexp) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1116 (looking-at mh-refiled-msg-regexp) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1117 (and (eq mh-next-direction 'forward) (bobp)) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1118 (and (eq mh-next-direction 'backward) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1119 (save-excursion (forward-line) (eobp))))) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1120 (forward-line (if (eq mh-next-direction 'forward) -1 1))) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1121 (if (or (looking-at mh-deleted-msg-regexp) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1122 (looking-at mh-refiled-msg-regexp)) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1123 (progn |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1124 (mh-undo-msg (mh-get-msg-num t)) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1125 (mh-maybe-show)) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1126 (goto-char original-position) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1127 (error "Nothing to undo"))))) |
731 | 1128 ;; update the mh-refile-list so mh-outstanding-commands-p will work |
1129 (mh-mapc (function | |
1130 (lambda (elt) | |
1131 (if (not (mh-seq-to-msgs elt)) | |
1132 (setq mh-refile-list (delq elt mh-refile-list))))) | |
1133 mh-refile-list) | |
1134 (if (not (mh-outstanding-commands-p)) | |
1135 (mh-set-folder-modified-p nil))) | |
1136 | |
1137 | |
1138 (defun mh-undo-msg (msg) | |
1139 ;; Undo the deletion or refile of one MESSAGE. | |
1140 (cond ((memq msg mh-delete-list) | |
1141 (setq mh-delete-list (delq msg mh-delete-list)) | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1142 (mh-remove-msg-from-seq msg 'deleted t)) |
731 | 1143 (t |
1144 (mh-mapc (function (lambda (dest) | |
1145 (mh-remove-msg-from-seq msg dest t))) | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1146 mh-refile-list))) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1147 (mh-notate msg ? mh-cmd-note)) |
731 | 1148 |
1149 | |
1150 (defun mh-undo-folder (&rest ignore) | |
1151 "Undo all commands in current folder." | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1152 (interactive) |
731 | 1153 (cond ((or mh-do-not-confirm |
1154 (yes-or-no-p "Undo all commands in folder? ")) | |
1155 (setq mh-delete-list nil | |
1156 mh-refile-list nil | |
1157 mh-seq-list nil | |
1158 mh-next-direction 'forward) | |
1159 (with-mh-folder-updating (nil) | |
1160 (mh-unmark-all-headers t))) | |
1161 (t | |
1162 (message "Commands not undone.") | |
1163 (sit-for 2)))) | |
1164 | |
1165 | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1166 (defun mh-unshar-msg (dir) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1167 "Unpack the shar file contained in the current message into directory DIR." |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1168 (interactive (list (read-file-name "Unshar message in directory: " |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1169 mh-unshar-default-directory |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1170 mh-unshar-default-directory nil))) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1171 (mh-display-msg (mh-get-msg-num t) mh-current-folder) ;update show buffer |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1172 (mh-unshar-buffer dir)) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1173 |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1174 (defun mh-unshar-buffer (dir) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1175 ;; Unpack the shar file contained in the current buffer into directory DIR. |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1176 (goto-char (point-min)) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1177 (if (or (re-search-forward "^#![ \t]*/bin/sh" nil t) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1178 (and (re-search-forward "^[^a-z0-9\"]*cut here\b" nil t) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1179 (forward-line 1)) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1180 (re-search-forward "^#" nil t) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1181 (re-search-forward "^: " nil t)) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1182 (let ((default-directory (expand-file-name dir)) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1183 (start (progn (beginning-of-line) (point))) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1184 (log-buffer (get-buffer-create "*Unshar Output*"))) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1185 (save-excursion |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1186 (set-buffer log-buffer) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1187 (setq default-directory (expand-file-name dir)) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1188 (erase-buffer) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1189 (if (file-directory-p default-directory) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1190 (insert "cd " dir "\n") |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1191 (insert "mkdir " dir "\n") |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1192 (call-process "mkdir" nil log-buffer t default-directory))) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1193 (set-window-start (display-buffer log-buffer) 0) ;so can watch progress |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1194 (call-process-region start (point-max) "sh" nil log-buffer t)) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1195 (error "Cannot find start of shar."))) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1196 |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1197 |
731 | 1198 (defun mh-visit-folder (folder &optional range) |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1199 "Visit FOLDER and display RANGE of messages. |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1200 Assumes mh-e has already been initialized." |
731 | 1201 (interactive (list (mh-prompt-for-folder "Visit" "+inbox" t) |
1202 (mh-read-msg-range "Range [all]? "))) | |
1203 (let ((config (current-window-configuration))) | |
1204 (mh-scan-folder folder (or range "all")) | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1205 (setq mh-previous-window-config config)) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1206 nil) |
731 | 1207 |
1208 | |
1209 (defun mh-widen () | |
1210 "Remove restrictions from the current folder, thereby showing all messages." | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1211 (interactive) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1212 (if mh-narrowed-to-seq |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1213 (with-mh-folder-updating (t) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1214 (delete-region (point-min) (point-max)) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1215 (widen) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1216 (mh-make-folder-mode-line))) |
731 | 1217 (setq mh-narrowed-to-seq nil)) |
1218 | |
1219 | |
1220 | |
1221 ;;; Support routines. | |
1222 | |
1223 (defun mh-delete-a-msg (msg) | |
1224 ;; Delete the MESSAGE. | |
1225 (save-excursion | |
1226 (mh-goto-msg msg nil t) | |
1227 (if (looking-at mh-refiled-msg-regexp) | |
1228 (error "Message %d is refiled. Undo refile before deleting." msg)) | |
1229 (if (looking-at mh-deleted-msg-regexp) | |
1230 nil | |
1231 (mh-set-folder-modified-p t) | |
1232 (mh-push msg mh-delete-list) | |
1233 (mh-add-msgs-to-seq msg 'deleted t) | |
1234 (mh-notate msg ?D mh-cmd-note)))) | |
1235 | |
1236 | |
1237 (defun mh-refile-a-msg (msg destination) | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1238 ;; Refile MESSAGE in FOLDER. FOLDER is a symbol, not a string. |
731 | 1239 (save-excursion |
1240 (mh-goto-msg msg nil t) | |
1241 (cond ((looking-at mh-deleted-msg-regexp) | |
1242 (error "Message %d is deleted. Undo delete before moving." msg)) | |
1243 ((looking-at mh-refiled-msg-regexp) | |
1244 (if (y-or-n-p | |
1245 (format "Message %d already refiled. Copy to %s as well? " | |
1246 msg destination)) | |
1247 (mh-exec-cmd "refile" (mh-get-msg-num t) "-link" | |
1248 "-src" mh-current-folder | |
1249 (symbol-name destination)) | |
1250 (message "Message not copied."))) | |
1251 (t | |
1252 (mh-set-folder-modified-p t) | |
1253 (if (not (memq destination mh-refile-list)) | |
1254 (mh-push destination mh-refile-list)) | |
1255 (if (not (memq msg (mh-seq-to-msgs destination))) | |
1256 (mh-add-msgs-to-seq msg destination t)) | |
1257 (mh-notate msg ?^ mh-cmd-note))))) | |
1258 | |
1259 | |
1260 (defun mh-display-msg (msg-num folder) | |
1261 ;; Display message NUMBER of FOLDER. | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1262 ;; Sets the current buffer to the show buffer. |
731 | 1263 (set-buffer folder) |
1264 ;; Bind variables in folder buffer in case they are local | |
1265 (let ((formfile mhl-formfile) | |
1266 (clean-message-header mh-clean-message-header) | |
1267 (invisible-headers mh-invisible-headers) | |
1268 (visible-headers mh-visible-headers) | |
1269 (msg-filename (mh-msg-filename msg-num)) | |
1270 (show-buffer mh-show-buffer) | |
1271 (folder mh-current-folder)) | |
1272 (if (not (file-exists-p msg-filename)) | |
1273 (error "Message %d does not exist" msg-num)) | |
1274 (switch-to-buffer show-buffer) | |
1275 (if mh-bury-show-buffer (bury-buffer (current-buffer))) | |
1276 (mh-when (not (equal msg-filename buffer-file-name)) | |
1277 ;; Buffer does not yet contain message. | |
1278 (clear-visited-file-modtime) | |
1279 (unlock-buffer) | |
1280 (setq buffer-file-name nil) ; no locking during setup | |
1281 (erase-buffer) | |
1282 (if formfile | |
1283 (if (stringp formfile) | |
1284 (mh-exec-lib-cmd-output "mhl" "-nobell" "-noclear" | |
1285 "-form" formfile msg-filename) | |
1286 (mh-exec-lib-cmd-output "mhl" "-nobell" "-noclear" | |
1287 msg-filename)) | |
1288 (insert-file-contents msg-filename)) | |
1289 (goto-char (point-min)) | |
1290 (cond (clean-message-header | |
1291 (mh-clean-msg-header (point-min) | |
1292 invisible-headers | |
1293 visible-headers) | |
1294 (goto-char (point-min))) | |
1295 (t | |
1296 (let ((case-fold-search t)) | |
1297 (re-search-forward | |
1298 "^To:\\|^From:\\|^Subject:\\|^Date:" nil t) | |
1299 (beginning-of-line) | |
1300 (mh-recenter 0)))) | |
1301 (set-buffer-modified-p nil) | |
1302 (setq buffer-file-name msg-filename) | |
1303 (set-mark nil) | |
1304 (setq mode-line-buffer-identification | |
1305 (list (format mh-show-buffer-mode-line-buffer-id | |
1306 folder msg-num)))))) | |
1307 | |
1308 | |
1309 (defun mh-invalidate-show-buffer () | |
1310 ;; Invalidate the show buffer so we must update it to use it. | |
1311 (if (get-buffer mh-show-buffer) | |
1312 (save-excursion | |
1313 (set-buffer mh-show-buffer) | |
1314 (setq buffer-file-name nil)))) | |
1315 | |
1316 | |
1317 (defun mh-show-message-in-other-window () | |
1318 (switch-to-buffer-other-window mh-show-buffer) | |
1319 (if mh-bury-show-buffer (bury-buffer (current-buffer)))) | |
1320 | |
1321 | |
1322 (defun mh-clean-msg-header (start invisible-headers visible-headers) | |
1323 ;; Flush extraneous lines in a message header, from the given POINT to the | |
1324 ;; end of the message header. If VISIBLE-HEADERS is non-nil, it contains a | |
1325 ;; regular expression specifying the lines to display, otherwise | |
1326 ;; INVISIBLE-HEADERS contains a regular expression specifying lines to | |
1327 ;; delete from the header. | |
1328 (let ((case-fold-search t)) | |
1329 (save-restriction | |
1330 (goto-char start) | |
1331 (if (search-forward "\n\n" nil t) | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1332 (backward-char 1)) |
731 | 1333 (narrow-to-region start (point)) |
1334 (goto-char (point-min)) | |
1335 (if visible-headers | |
1336 (while (< (point) (point-max)) | |
1337 (beginning-of-line) | |
1338 (cond ((looking-at visible-headers) | |
1339 (forward-line 1) | |
1340 (while (looking-at "^[ \t]+") (forward-line 1))) | |
1341 (t | |
1342 (mh-delete-line 1) | |
1343 (while (looking-at "^[ \t]+") | |
1344 (beginning-of-line) | |
1345 (mh-delete-line 1))))) | |
1346 (while (re-search-forward invisible-headers nil t) | |
1347 (beginning-of-line) | |
1348 (mh-delete-line 1) | |
1349 (while (looking-at "^[ \t]+") | |
1350 (beginning-of-line) | |
1351 (mh-delete-line 1)))) | |
1352 (unlock-buffer)))) | |
1353 | |
1354 | |
1355 (defun mh-delete-line (lines) | |
1356 ;; Delete version of kill-line. | |
1357 (delete-region (point) (save-excursion (forward-line lines) (point)))) | |
1358 | |
1359 | |
1360 (defun mh-read-draft (use initial-contents delete-contents-file) | |
1361 ;; Read draft file into a draft buffer and make that buffer the current one. | |
1362 ;; USE is a message used for prompting about the intended use of the message. | |
1363 ;; INITIAL-CONTENTS is filename that is read into an empty buffer, or NIL | |
1364 ;; if buffer should not be modified. Delete the initial-contents file if | |
1365 ;; DELETE-CONTENTS-FILE flag is set. | |
1366 ;; Returns the draft folder's name. | |
1367 ;; If the draft folder facility is enabled in ~/.mh_profile, a new buffer is | |
1368 ;; used each time and saved in the draft folder. The draft file can then be | |
1369 ;; reused. | |
1370 (cond (mh-draft-folder | |
1371 (let ((orig-default-dir default-directory)) | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1372 (pop-to-buffer (find-file-noselect (mh-new-draft-name)) t) |
731 | 1373 (rename-buffer (format "draft-%s" (buffer-name))) |
1374 (setq default-directory orig-default-dir))) | |
1375 (t | |
1376 (let ((draft-name (expand-file-name "draft" mh-user-path))) | |
1377 (pop-to-buffer "draft") ; Create if necessary | |
1378 (if (buffer-modified-p) | |
1379 (if (y-or-n-p "Draft has been modified; kill anyway? ") | |
1380 (set-buffer-modified-p nil) | |
1381 (error "Draft preserved"))) | |
1382 (setq buffer-file-name draft-name) | |
1383 (clear-visited-file-modtime) | |
1384 (unlock-buffer) | |
1385 (mh-when (and (file-exists-p draft-name) | |
1386 (not (equal draft-name initial-contents))) | |
1387 (insert-file-contents draft-name) | |
1388 (delete-file draft-name))))) | |
1389 (mh-when (and initial-contents | |
1390 (or (zerop (buffer-size)) | |
1391 (not (y-or-n-p | |
1392 (format "A draft exists. Use for %s? " use))))) | |
1393 (erase-buffer) | |
1394 (insert-file-contents initial-contents) | |
1395 (if delete-contents-file (delete-file initial-contents))) | |
1396 (auto-save-mode 1) | |
1397 (if mh-draft-folder | |
1398 (save-buffer)) ; Do not reuse draft name | |
1399 (buffer-name)) | |
1400 | |
1401 | |
1402 (defun mh-new-draft-name () | |
1403 ;; Returns the pathname of folder for draft messages. | |
1404 (save-excursion | |
1405 (set-buffer (get-buffer-create " *mh-temp*")) | |
1406 (erase-buffer) | |
1407 (mh-exec-cmd-output "mhpath" nil mh-draft-folder "new") | |
1408 (buffer-substring (point) (1- (mark))))) | |
1409 | |
1410 | |
1411 (defun mh-next-msg () | |
1412 ;; Move backward or forward to the next undeleted message in the buffer. | |
1413 (if (eq mh-next-direction 'forward) | |
1414 (mh-next-undeleted-msg 1) | |
1415 (mh-previous-undeleted-msg 1))) | |
1416 | |
1417 | |
1418 (defun mh-set-scan-mode () | |
1419 ;; Display the scan listing buffer, but do not show a message. | |
1420 (if (get-buffer mh-show-buffer) | |
1421 (delete-windows-on mh-show-buffer)) | |
1422 (mh-set-mode-name "mh-e scan") | |
1423 (setq mh-showing nil) | |
1424 (if mh-recenter-summary-p | |
1425 (mh-recenter nil))) | |
1426 | |
1427 | |
1428 (defun mh-maybe-show (&optional msg) | |
1429 ;; If in showing mode, then display the message pointed to by the cursor. | |
1430 (if mh-showing (mh-show msg))) | |
1431 | |
1432 | |
1433 (defun mh-set-mode-name (mode-name-string) | |
1434 ;; Set the mode-name and ensure that the mode line is updated. | |
1435 (setq mode-name mode-name-string) | |
1436 ;; Force redisplay of all buffers' mode lines to be considered. | |
1437 (save-excursion (set-buffer (other-buffer))) | |
1438 (set-buffer-modified-p (buffer-modified-p))) | |
1439 | |
1440 | |
1441 | |
1442 ;;; The folder data abstraction. | |
1443 | |
1444 (defvar mh-current-folder nil "Name of current folder, a string.") | |
1445 (defvar mh-show-buffer nil "Buffer that displays mesage for this folder.") | |
1446 (defvar mh-folder-filename nil "Full path of directory for this folder.") | |
1447 (defvar mh-showing nil "If non-nil, show the message in a separate window.") | |
1448 (defvar mh-next-seq-num nil "Index of free sequence id.") | |
1449 (defvar mh-delete-list nil "List of msg numbers to delete.") | |
1450 (defvar mh-refile-list nil "List of folder names in mh-seq-list.") | |
1451 (defvar mh-seq-list nil "Alist of (seq . msgs) numbers.") | |
1452 (defvar mh-seen-list nil "List of displayed messages.") | |
1453 (defvar mh-next-direction 'forward "Direction to move to next message.") | |
1454 (defvar mh-narrowed-to-seq nil "Sequence display is narrowed to.") | |
1455 (defvar mh-first-msg-num nil "Number of first msg in buffer.") | |
1456 (defvar mh-last-msg-num nil "Number of last msg in buffer.") | |
1457 | |
1458 | |
1459 (defun mh-make-folder (name) | |
1460 ;; Create and initialize a new mail folder called NAME and make it the | |
1461 ;; current folder. | |
1462 (switch-to-buffer name) | |
1463 (setq buffer-read-only nil) | |
1464 (erase-buffer) | |
1465 (setq buffer-read-only t) | |
1466 (mh-folder-mode) | |
1467 (mh-set-folder-modified-p nil) | |
1468 (setq buffer-file-name mh-folder-filename) | |
1469 (mh-set-mode-name "mh-e scan")) | |
1470 | |
1471 | |
1472 ;;; Don't use this mode when creating buffers if default-major-mode is nil. | |
1473 (put 'mh-folder-mode 'mode-class 'special) | |
1474 | |
1475 (defun mh-folder-mode () | |
1476 "Major mode for \"editing\" an MH folder scan listing. | |
1477 Messages can be marked for refiling and deletion. However, both actions | |
1478 are deferred until you request execution with \\[mh-execute-commands]. | |
1479 \\{mh-folder-mode-map} | |
1480 A prefix argument (\\[universal-argument]) to delete, refile, list, or undo | |
1481 applies the action to a message sequence. | |
1482 | |
1483 Variables controlling mh-e operation are (defaults in parentheses): | |
1484 | |
1485 mh-bury-show-buffer (t) | |
1486 Non-nil means that the buffer used to display message is buried. | |
1487 It will never be offered as the default other buffer. | |
1488 | |
1489 mh-clean-message-header (nil) | |
1490 Non-nil means remove header lines matching the regular expression | |
1491 specified in mh-invisible-headers from messages. | |
1492 | |
1493 mh-visible-headers (nil) | |
1494 If non-nil, it contains a regexp specifying the headers that are shown in | |
1495 a message if mh-clean-message-header is non-nil. Setting this variable | |
1496 overrides mh-invisible-headers. | |
1497 | |
1498 mh-do-not-confirm (nil) | |
1499 Non-nil means do not prompt for confirmation before executing some | |
1500 non-recoverable commands such as mh-kill-folder and mh-undo-folder. | |
1501 | |
1502 mhl-formfile (nil) | |
1503 Name of format file to be used by mhl to show messages. | |
1504 A value of T means use the default format file. | |
1505 Nil means don't use mhl to format messages. | |
1506 | |
1507 mh-lpr-command-format (\"lpr -p -J '%s'\") | |
1508 Format for command used to print a message on a system printer. | |
1509 | |
1510 mh-recenter-summary-p (nil) | |
1511 If non-nil, then the scan listing is recentered when the window displaying | |
1512 a messages is toggled off. | |
1513 | |
1514 mh-summary-height (4) | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1515 Number of lines in the summary window including the mode line. |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1516 |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1517 mh-ins-buf-prefix (\"> \") |
731 | 1518 String to insert before each non-blank line of a message as it is |
1519 inserted in a draft letter. | |
1520 | |
1521 The value of mh-folder-mode-hook is called when a new folder is set up." | |
1522 | |
1523 (kill-all-local-variables) | |
1524 (use-local-map mh-folder-mode-map) | |
1525 (setq major-mode 'mh-folder-mode) | |
1526 (mh-set-mode-name "mh-e folder") | |
1527 (make-local-vars | |
1528 'mh-current-folder (buffer-name) ; Name of folder, a string | |
1529 'mh-show-buffer (format "show-%s" (buffer-name)) ; Buffer that displays msgs | |
1530 'mh-folder-filename ; e.g. "/usr/foobar/Mail/inbox/" | |
1531 (file-name-as-directory (mh-expand-file-name (buffer-name))) | |
1532 'mh-showing nil ; Show message also? | |
1533 'mh-next-seq-num 0 ; Index of free sequence id | |
1534 'mh-delete-list nil ; List of msgs nums to delete | |
1535 'mh-refile-list nil ; List of folder names in mh-seq-list | |
1536 'mh-seq-list nil ; Alist of (seq . msgs) nums | |
1537 'mh-seen-list nil ; List of displayed messages | |
1538 'mh-next-direction 'forward ; Direction to move to next message | |
1539 'mh-narrowed-to-seq nil ; Sequence display is narrowed to | |
1540 'mh-first-msg-num nil ; Number of first msg in buffer | |
1541 'mh-last-msg-num nil ; Number of last msg in buffer | |
1542 'mh-previous-window-config nil) ; Previous window configuration | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1543 (setq truncate-lines t) |
731 | 1544 (auto-save-mode -1) |
1545 (setq buffer-offer-save t) | |
1546 (make-local-variable 'write-file-hooks) | |
1547 (setq write-file-hooks '(mh-execute-commands)) | |
1548 (make-local-variable 'revert-buffer-function) | |
1549 (setq revert-buffer-function 'mh-undo-folder) | |
1550 (run-hooks 'mh-folder-mode-hook)) | |
1551 | |
1552 | |
1553 (defun make-local-vars (&rest pairs) | |
1554 ;; Take VARIABLE-VALUE pairs and makes local variables initialized to the | |
1555 ;; value. | |
1556 (while pairs | |
1557 (make-variable-buffer-local (car pairs)) | |
1558 (set (car pairs) (car (cdr pairs))) | |
1559 (setq pairs (cdr (cdr pairs))))) | |
1560 | |
1561 | |
1562 (defun mh-scan-folder (folder range) | |
1563 ;; Scan the FOLDER over the RANGE. Return in the folder's buffer. | |
1564 (cond ((null (get-buffer folder)) | |
1565 (mh-make-folder folder)) | |
1566 (t | |
1567 (mh-process-or-undo-commands folder) | |
1568 (switch-to-buffer folder))) | |
1569 (mh-regenerate-headers range) | |
1570 (mh-when (zerop (buffer-size)) | |
1571 (if (equal range "all") | |
1572 (message "Folder %s is empty" folder) | |
1573 (message "No messages in %s, range %s" folder range)) | |
1574 (sit-for 5)) | |
1575 (mh-goto-cur-msg)) | |
1576 | |
1577 | |
1578 (defun mh-regenerate-headers (range) | |
1579 ;; Replace buffer with scan of its contents over range RANGE. | |
1580 (let ((folder mh-current-folder)) | |
1581 (message "Scanning %s..." folder) | |
1582 (with-mh-folder-updating (nil) | |
1583 (erase-buffer) | |
1584 (mh-exec-cmd-output "scan" nil | |
1585 "-noclear" "-noheader" | |
1586 "-width" (window-width) | |
1587 folder range) | |
1588 (goto-char (point-min)) | |
1589 (cond ((looking-at "scan: no messages in") | |
1590 (keep-lines mh-valid-scan-line)) ; Flush random scan lines | |
1591 ((looking-at "scan: ")) ; Keep error messages | |
1592 (t | |
1593 (keep-lines mh-valid-scan-line))) ; Flush random scan lines | |
1594 (mh-delete-seq-locally 'cur) ; To pick up new one | |
1595 (setq mh-seq-list (mh-read-folder-sequences folder nil)) | |
1596 (mh-notate-user-sequences) | |
1597 (mh-make-folder-mode-line (if (equal range "all") | |
1598 nil | |
1599 mh-partial-folder-mode-line-annotation))) | |
1600 (message "Scanning %s...done" folder))) | |
1601 | |
1602 | |
1603 (defun mh-get-new-mail (maildrop-name) | |
1604 ;; Read new mail from a maildrop into the current buffer. | |
1605 ;; Return T if there was new mail, NIL otherwise. Return in the current | |
1606 ;; buffer. | |
1607 (let ((point-before-inc (point)) | |
1608 (folder mh-current-folder) | |
1609 (return-value t)) | |
1610 (with-mh-folder-updating (t) | |
1611 (message (if maildrop-name | |
1612 (format "inc %s -file %s..." folder maildrop-name) | |
1613 (format "inc %s..." folder))) | |
1614 (mh-unmark-all-headers nil) | |
1615 (setq mh-next-direction 'forward) | |
1616 (goto-char (point-max)) | |
1617 (let ((start-of-inc (point))) | |
1618 (if maildrop-name | |
1619 (mh-exec-cmd-output "inc" nil folder | |
1620 "-file" (expand-file-name maildrop-name) | |
1621 "-width" (window-width) | |
1622 "-truncate") | |
1623 (mh-exec-cmd-output "inc" nil | |
1624 "-width" (window-width))) | |
1625 (message | |
1626 (if maildrop-name | |
1627 (format "inc %s -file %s...done" folder maildrop-name) | |
1628 (format "inc %s...done" folder))) | |
1629 (goto-char start-of-inc) | |
1630 (cond ((looking-at "inc: no mail") | |
1631 (keep-lines mh-valid-scan-line) ; Flush random scan lines | |
1632 (goto-char point-before-inc) | |
1633 (message "No new mail%s%s" (if maildrop-name " in " "") | |
1634 (if maildrop-name maildrop-name ""))) | |
1635 ((re-search-forward "^inc:" nil t) ; Error messages | |
1636 (error "inc error")) | |
1637 (t | |
1638 (mh-delete-seq-locally 'cur) ; To pick up new one | |
1639 (setq mh-seq-list (mh-read-folder-sequences folder t)) | |
1640 (mh-notate-user-sequences) | |
1641 (keep-lines mh-valid-scan-line) | |
1642 (mh-make-folder-mode-line) | |
1643 (mh-goto-cur-msg) | |
1644 (setq return-value t)))) | |
1645 return-value))) | |
1646 | |
1647 | |
1648 (defun mh-make-folder-mode-line (&optional annotation) | |
1649 ;; Set the fields of the mode line for a folder buffer. | |
1650 ;; The optional ANNOTATION string is displayed after the folder's name. | |
1651 (save-excursion | |
1652 (mh-first-msg) | |
1653 (setq mh-first-msg-num (mh-get-msg-num nil)) | |
1654 (mh-last-msg) | |
1655 (setq mh-last-msg-num (mh-get-msg-num nil)) | |
1656 (let ((lines (count-lines (point-min) (point-max)))) | |
1657 (setq mode-line-buffer-identification | |
1658 (list (format "{%%b%s} %d msg%s" | |
1659 (if annotation (format "/%s" annotation) "") | |
1660 lines | |
1661 (if (zerop lines) | |
1662 "s" | |
1663 (if (> lines 1) | |
1664 (format "s (%d-%d)" mh-first-msg-num | |
1665 mh-last-msg-num) | |
1666 (format " (%d)" mh-first-msg-num))))))))) | |
1667 | |
1668 | |
1669 (defun mh-unmark-all-headers (remove-all-flags) | |
1670 ;; Remove all '+' flags from the headers, and if called with a non-nil | |
1671 ;; argument, remove all 'D', '^' and '%' flags too. | |
1672 ;; Optimized for speed (i.e., no regular expressions). | |
1673 (save-excursion | |
1674 (let ((case-fold-search nil) | |
1675 (last-line (- (point-max) mh-cmd-note)) | |
1676 char) | |
1677 (mh-first-msg) | |
1678 (while (<= (point) last-line) | |
1679 (forward-char mh-cmd-note) | |
1680 (setq char (following-char)) | |
1681 (if (or (and remove-all-flags | |
1682 (or (eql char ?D) | |
1683 (eql char ?^) | |
1684 (eql char ?%))) | |
1685 (eql char ?+)) | |
1686 (progn | |
1687 (delete-char 1) | |
1688 (insert " "))) | |
1689 (forward-line))))) | |
1690 | |
1691 | |
1692 (defun mh-goto-cur-msg () | |
1693 ;; Position the cursor at the current message. | |
1694 (let ((cur-msg (car (mh-seq-to-msgs 'cur)))) | |
1695 (cond ((and cur-msg | |
1696 (mh-goto-msg cur-msg t nil)) | |
1697 (mh-notate nil ?+ mh-cmd-note) | |
1698 (mh-recenter 0) | |
1699 (mh-maybe-show cur-msg)) | |
1700 (t | |
1701 (mh-last-msg) | |
1702 (message "No current message"))))) | |
1703 | |
1704 | |
1705 (defun mh-pack-folder-1 (range) | |
1706 ;; Close and pack the current folder. | |
1707 (mh-process-or-undo-commands mh-current-folder) | |
1708 (message "Packing folder...") | |
1709 (mh-set-folder-modified-p t) ; lock folder while packing | |
1710 (save-excursion | |
1711 (mh-exec-cmd-quiet " *mh-temp*" "folder" mh-current-folder "-pack")) | |
1712 (mh-regenerate-headers range)) | |
1713 | |
1714 | |
1715 (defun mh-process-or-undo-commands (folder) | |
1716 ;; If FOLDER has outstanding commands, then either process or discard them. | |
1717 (set-buffer folder) | |
1718 (if (mh-outstanding-commands-p) | |
1719 (if (or mh-do-not-confirm | |
1720 (y-or-n-p | |
1721 "Process outstanding deletes and refiles (or lose them)? ")) | |
1722 (mh-process-commands folder) | |
1723 (mh-undo-folder)) | |
1724 (mh-invalidate-show-buffer))) | |
1725 | |
1726 | |
1727 (defun mh-process-commands (folder) | |
1728 ;; Process outstanding commands for the folder FOLDER. | |
1729 (message "Processing deletes and refiles for %s..." folder) | |
1730 (set-buffer folder) | |
1731 (with-mh-folder-updating (nil) | |
1732 ;; Update the unseen sequence if it exists | |
1733 (if (and mh-seen-list (mh-seq-to-msgs mh-unseen-seq)) | |
1734 (mh-undefine-sequence mh-unseen-seq mh-seen-list)) | |
1735 | |
1736 ;; Then refile messages | |
1737 (mh-mapc | |
1738 (function | |
1739 (lambda (dest) | |
1740 (let ((msgs (mh-seq-to-msgs dest))) | |
1741 (mh-when msgs | |
1742 (apply 'mh-exec-cmd "refile" | |
1743 "-src" folder (symbol-name dest) msgs) | |
1744 (mh-delete-scan-msgs msgs))))) | |
1745 mh-refile-list) | |
1746 | |
1747 ;; Now delete messages | |
1748 (mh-when mh-delete-list | |
1749 (apply 'mh-exec-cmd "rmm" folder mh-delete-list) | |
1750 (mh-delete-scan-msgs mh-delete-list)) | |
1751 | |
1752 ;; Don't need to remove sequences since delete and refile do so. | |
1753 | |
1754 ;; Mark cur message | |
1755 (if (> (buffer-size) 0) | |
1756 (mh-define-sequence 'cur (list (or (mh-get-msg-num nil) "last")))) | |
1757 | |
1758 (mh-invalidate-show-buffer) | |
1759 | |
1760 (setq mh-delete-list nil | |
1761 mh-refile-list nil | |
1762 mh-seq-list (mh-read-folder-sequences mh-current-folder nil) | |
1763 mh-seen-list nil) | |
1764 (mh-unmark-all-headers t) | |
1765 (mh-notate-user-sequences) | |
1766 (message "Processing deletes and refiles for %s...done" folder))) | |
1767 | |
1768 | |
1769 (defun mh-delete-scan-msgs (msgs) | |
1770 ;; Delete the scan listing lines for each of the msgs in the LIST. | |
1771 ;; Optimized for speed (i.e., no regular expressions). | |
1772 (setq msgs (sort msgs (function <))) ;okay to clobber msgs | |
1773 (save-excursion | |
1774 (mh-first-msg) | |
1775 (while (and msgs (< (point) (point-max))) | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1776 (cond ((equal (mh-get-msg-num nil) (car msgs)) |
731 | 1777 (delete-region (point) (save-excursion (forward-line) (point))) |
1778 (setq msgs (cdr msgs))) | |
1779 (t | |
1780 (forward-line)))))) | |
1781 | |
1782 | |
1783 (defun mh-set-folder-modified-p (flag) | |
1784 "Mark current folder as modified or unmodified according to FLAG." | |
1785 (set-buffer-modified-p flag)) | |
1786 | |
1787 | |
1788 (defun mh-outstanding-commands-p () | |
1789 ;; Returns non-nil if there are outstanding deletes or refiles. | |
1790 (or mh-delete-list mh-refile-list)) | |
1791 | |
1792 | |
1793 | |
1794 ;;; Mode for composing and sending a draft message. | |
1795 | |
1796 (defvar mh-sent-from-folder nil | |
1797 "Folder of msg associated with this letter.") | |
1798 | |
1799 (defvar mh-sent-from-msg nil | |
1800 "Number of msg associated with this letter.") | |
1801 | |
1802 (defvar mh-send-args nil | |
1803 "Extra arguments to pass to \"send\" command.") | |
1804 | |
1805 (defvar mh-annotate-char nil | |
1806 "Character to use to annotate mh-sent-from-msg.") | |
1807 | |
1808 (defvar mh-annotate-field nil | |
1809 "Field name for message annotation.") | |
1810 | |
1811 (defun mh-letter-mode () | |
1812 "Mode for composing letters in mh-e. | |
1813 When you have finished composing, type \\[mh-send-letter] to send the letter. | |
1814 | |
1815 Variables controlling this mode (defaults in parentheses): | |
1816 | |
1817 mh-delete-yanked-msg-window (nil) | |
1818 If non-nil, \\[mh-yank-cur-msg] will delete any windows displaying | |
1819 the yanked message. | |
1820 | |
1821 mh-yank-from-start-of-msg (t) | |
1822 If non-nil, \\[mh-yank-cur-msg] will include the entire message. | |
1823 If `body', just yank the body (no header). | |
1824 If nil, only the portion of the message following the point will be yanked. | |
1825 If there is a region, this variable is ignored. | |
1826 | |
1827 Upon invoking mh-letter-mode, text-mode-hook and mh-letter-mode-hook are | |
1828 invoked with no args, if those values are non-nil. | |
1829 | |
1830 \\{mh-letter-mode-map}" | |
1831 (interactive) | |
1832 (kill-all-local-variables) | |
1833 (make-local-variable 'paragraph-start) | |
1834 (setq paragraph-start (concat "^[ \t]*[-_][-_][-_]+$\\|" paragraph-start)) | |
1835 (make-local-variable 'paragraph-separate) | |
1836 (setq paragraph-separate | |
1837 (concat "^[ \t]*[-_][-_][-_]+$\\|" paragraph-separate)) | |
1838 (make-local-variable 'mh-send-args) | |
1839 (make-local-variable 'mh-annotate-char) | |
1840 (make-local-variable 'mh-annotate-field) | |
1841 (make-local-variable 'mh-previous-window-config) | |
1842 (make-local-variable 'mh-sent-from-folder) | |
1843 (make-local-variable 'mh-sent-from-msg) | |
1844 (use-local-map mh-letter-mode-map) | |
1845 (setq major-mode 'mh-letter-mode) | |
1846 (mh-set-mode-name "mh-e letter") | |
1847 (set-syntax-table mh-letter-mode-syntax-table) | |
1848 (run-hooks 'text-mode-hook 'mh-letter-mode-hook) | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1849 (mh-when (and (boundp 'auto-fill-hook) auto-fill-hook) ;emacs 18 |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1850 (make-local-variable 'auto-fill-hook) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1851 (setq auto-fill-hook 'mh-auto-fill-for-letter)) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1852 (mh-when (and (boundp 'auto-fill-function) auto-fill-function) ;emacs 19 |
731 | 1853 (make-local-variable 'auto-fill-function) |
1854 (setq auto-fill-function 'mh-auto-fill-for-letter))) | |
1855 | |
1856 | |
1857 (defun mh-auto-fill-for-letter () | |
1858 ;; Auto-fill in letters treats the header specially by inserting a tab | |
1859 ;; before continuation line. | |
1860 (do-auto-fill) | |
1861 (if (mh-in-header-p) | |
1862 (save-excursion | |
1863 (beginning-of-line nil) | |
1864 (insert-char ?\t 1)))) | |
1865 | |
1866 | |
1867 (defun mh-in-header-p () | |
1868 ;; Return non-nil if the point is in the header of a draft message. | |
1869 (save-excursion | |
1870 (let ((cur-point (point))) | |
1871 (goto-char (point-min)) | |
1872 (re-search-forward "^--------" nil t) | |
1873 (< cur-point (point))))) | |
1874 | |
1875 | |
1876 (defun mh-to-field () | |
1877 "Move point to the end of a specified header field. | |
1878 The field is indicated by the previous keystroke. Create the field if | |
1879 it does not exist. Set the mark to point before moving." | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1880 (interactive) |
731 | 1881 (expand-abbrev) |
1882 (let ((target (cdr (assoc (logior last-input-char ?`) mh-to-field-choices))) | |
1883 (case-fold-search t)) | |
1884 (cond ((mh-position-on-field target t) | |
1885 (let ((eol (point))) | |
1886 (skip-chars-backward " \t") | |
1887 (delete-region (point) eol)) | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1888 (if (and (not (eq (logior last-input-char ?`) ?s)) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1889 (save-excursion |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1890 (backward-char 1) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1891 (not (looking-at "[:,]")))) |
731 | 1892 (insert ", ") |
1893 (insert " "))) | |
1894 (t | |
1895 (goto-char (point-min)) | |
1896 (re-search-forward "^To:") | |
1897 (forward-line 1) | |
1898 (while (looking-at "^[ \t]") (forward-line 1)) | |
1899 (insert (format "%s \n" target)) | |
1900 (backward-char 1))))) | |
1901 | |
1902 | |
1903 (defun mh-to-fcc () | |
1904 "Insert an Fcc: field in the current message. | |
1905 Prompt for the field name with a completion list of the current folders." | |
1906 (interactive) | |
1907 (let ((last-input-char ?\C-f) | |
1908 (folder (mh-prompt-for-folder "Fcc" "" t))) | |
1909 (expand-abbrev) | |
1910 (save-excursion | |
1911 (mh-to-field) | |
1912 (insert (substring folder 1 nil))))) | |
1913 | |
1914 | |
1915 (defun mh-insert-signature () | |
1916 "Insert the file ~/.signature at the current point." | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1917 (interactive) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1918 (insert-file-contents "~/.signature") |
731 | 1919 (set-buffer-modified-p (buffer-modified-p))) ; force mode line update |
1920 | |
1921 | |
1922 (defun mh-check-whom () | |
1923 "Verify recipients of the current letter." | |
1924 (interactive) | |
1925 (let ((file-name (buffer-file-name))) | |
1926 (set-buffer-modified-p t) ; Force writing of contents | |
1927 (save-buffer) | |
1928 (message "Checking recipients...") | |
1929 (switch-to-buffer-other-window "*Mail Recipients*") | |
1930 (bury-buffer (current-buffer)) | |
1931 (erase-buffer) | |
1932 (mh-exec-cmd-output "whom" t file-name) | |
1933 (other-window -1) | |
1934 (message "Checking recipients...done"))) | |
1935 | |
1936 | |
1937 | |
1938 ;;; Routines to make a search pattern and search for a message. | |
1939 | |
1940 (defvar mh-searching-folder nil "Folder this pick is searching.") | |
1941 | |
1942 | |
1943 (defun mh-make-pick-template () | |
1944 ;; Initialize the current buffer with a template for a pick pattern. | |
1945 (erase-buffer) | |
1946 (kill-all-local-variables) | |
1947 (make-local-variable 'mh-searching-folder) | |
1948 (insert "From: \n" | |
1949 "To: \n" | |
1950 "Cc: \n" | |
1951 "Date: \n" | |
1952 "Subject: \n" | |
1953 "---------\n") | |
1954 (mh-letter-mode) | |
1955 (use-local-map mh-pick-mode-map) | |
1956 (goto-char (point-min)) | |
1957 (end-of-line)) | |
1958 | |
1959 | |
1960 (defun mh-do-pick-search () | |
1961 "Find messages that match the qualifications in the current pattern buffer. | |
1962 Messages are searched for in the folder named in mh-searching-folder. | |
1963 Put messages found in a sequence named `search'." | |
1964 (interactive) | |
1965 (let ((pattern-buffer (buffer-name)) | |
1966 (searching-buffer mh-searching-folder) | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
1967 range msgs |
731 | 1968 (pattern nil) |
1969 (new-buffer nil)) | |
1970 (save-excursion | |
1971 (cond ((get-buffer searching-buffer) | |
1972 (set-buffer searching-buffer) | |
1973 (setq range (format "%d-%d" mh-first-msg-num mh-last-msg-num))) | |
1974 (t | |
1975 (mh-make-folder searching-buffer) | |
1976 (setq range "all") | |
1977 (setq new-buffer t)))) | |
1978 (message "Searching...") | |
1979 (goto-char (point-min)) | |
1980 (while (setq pattern (mh-next-pick-field pattern-buffer)) | |
1981 (setq msgs (mh-seq-from-command searching-buffer | |
1982 'search | |
1983 (nconc (cons "pick" pattern) | |
1984 (list searching-buffer | |
1985 range | |
1986 "-sequence" "search" | |
1987 "-list")))) | |
1988 (setq range "search")) | |
1989 (message "Searching...done") | |
1990 (if new-buffer | |
1991 (mh-scan-folder searching-buffer msgs) | |
1992 (switch-to-buffer searching-buffer)) | |
1993 (delete-other-windows) | |
1994 (mh-notate-seq 'search ?% (1+ mh-cmd-note)))) | |
1995 | |
1996 | |
1997 (defun mh-next-pick-field (buffer) | |
1998 ;; Return the next piece of a pick argument that can be extracted from the | |
1999 ;; BUFFER. Returns nil if no pieces remain. | |
2000 (set-buffer buffer) | |
2001 (let ((case-fold-search t)) | |
2002 (cond ((eobp) | |
2003 nil) | |
2004 ((re-search-forward "^\\([a-z].*\\):[ \t]*\\([a-z0-9].*\\)$" nil t) | |
2005 (let* ((component | |
2006 (format "--%s" | |
2007 (downcase (buffer-substring (match-beginning 1) | |
2008 (match-end 1))))) | |
2009 (pat (buffer-substring (match-beginning 2) (match-end 2)))) | |
2010 (forward-line 1) | |
2011 (list component pat))) | |
2012 ((re-search-forward "^-*$" nil t) | |
2013 (forward-char 1) | |
2014 (let ((body (buffer-substring (point) (point-max)))) | |
2015 (if (and (> (length body) 0) (not (equal body "\n"))) | |
2016 (list "-search" body) | |
2017 nil))) | |
2018 (t | |
2019 nil)))) | |
2020 | |
2021 | |
2022 | |
2023 ;;; Routines to compose and send a letter. | |
2024 | |
2025 (defun mh-compose-and-send-mail (draft send-args | |
2026 sent-from-folder sent-from-msg | |
2027 to subject cc | |
2028 annotate-char annotate-field | |
2029 config) | |
2030 ;; Edit and compose a draft message in buffer DRAFT and send or save it. | |
2031 ;; SENT-FROM-FOLDER is buffer containing scan listing of current folder, or | |
2032 ;; nil if none exists. | |
2033 ;; SENT-FROM-MSG is the message number or sequence name or nil. | |
2034 ;; SEND-ARGS is an optional argument passed to the send command. | |
2035 ;; The TO, SUBJECT, and CC fields are passed to the | |
2036 ;; mh-compose-letter-function. | |
2037 ;; If ANNOTATE-CHAR is non-null, it is used to notate the scan listing of the | |
2038 ;; message. In that case, the ANNOTATE-FIELD is used to build a string | |
2039 ;; for mh-annotate-msg. | |
2040 ;; CONFIG is the window configuration to restore after sending the letter. | |
2041 (pop-to-buffer draft) | |
2042 (mh-letter-mode) | |
2043 (setq mh-sent-from-folder sent-from-folder) | |
2044 (setq mh-sent-from-msg sent-from-msg) | |
2045 (setq mh-send-args send-args) | |
2046 (setq mh-annotate-char annotate-char) | |
2047 (setq mh-annotate-field annotate-field) | |
2048 (setq mh-previous-window-config config) | |
2049 (setq mode-line-buffer-identification (list "{%b}")) | |
2050 (if (and (boundp 'mh-compose-letter-function) | |
2051 (symbol-value 'mh-compose-letter-function)) | |
2052 ;; run-hooks will not pass arguments. | |
2053 (let ((value (symbol-value 'mh-compose-letter-function))) | |
2054 (if (and (listp value) (not (eq (car value) 'lambda))) | |
2055 (while value | |
2056 (funcall (car value) to subject cc) | |
2057 (setq value (cdr value))) | |
2058 (funcall mh-compose-letter-function to subject cc))))) | |
2059 | |
2060 | |
2061 (defun mh-send-letter (&optional arg) | |
2062 "Send the draft letter in the current buffer. | |
2063 If optional prefix argument is provided, monitor delivery. | |
2064 Run mh-before-send-letter-hook before doing anything." | |
2065 (interactive "P") | |
2066 (run-hooks 'mh-before-send-letter-hook) | |
2067 (set-buffer-modified-p t) ; Make sure buffer is written | |
2068 (save-buffer) | |
2069 (message "Sending...") | |
2070 (let ((draft-buffer (current-buffer)) | |
2071 (file-name (buffer-file-name)) | |
2072 (config mh-previous-window-config)) | |
2073 (cond (arg | |
2074 (pop-to-buffer "MH mail delivery") | |
2075 (erase-buffer) | |
2076 (if mh-send-args | |
2077 (mh-exec-cmd-output "send" t "-watch" "-nopush" | |
2078 "-nodraftfolder" mh-send-args file-name) | |
2079 (mh-exec-cmd-output "send" t "-watch" "-nopush" | |
2080 "-nodraftfolder" file-name)) | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
2081 (goto-char (point-max)) ; show the interesting part |
731 | 2082 (recenter -1) |
2083 (set-buffer draft-buffer)) ; for annotation below | |
2084 (mh-send-args | |
2085 (mh-exec-cmd-daemon "send" "-nodraftfolder" "-noverbose" | |
2086 mh-send-args file-name)) | |
2087 (t | |
2088 (mh-exec-cmd-daemon "send" "-nodraftfolder" "-noverbose" | |
2089 file-name))) | |
2090 | |
2091 (if mh-annotate-char | |
2092 (mh-annotate-msg mh-sent-from-msg | |
2093 mh-sent-from-folder | |
2094 mh-annotate-char | |
2095 "-component" mh-annotate-field | |
2096 "-text" (format "\"%s %s\"" | |
2097 (mh-get-field "To:") | |
2098 (mh-get-field "Cc:")))) | |
2099 | |
2100 (mh-when (or (not arg) | |
2101 (y-or-n-p "Kill draft buffer? ")) | |
2102 (kill-buffer draft-buffer) | |
2103 (if config | |
2104 (set-window-configuration config))) | |
2105 (message "Sending...done"))) | |
2106 | |
2107 | |
2108 (defun mh-insert-letter (prefix-provided folder msg) | |
2109 "Insert a message from any folder into the current letter. | |
2110 Removes the message's headers using mh-invisible-headers. | |
2111 Prefixes each non-blank line with mh-ins-buf-prefix (default \">> \"). | |
2112 If optional prefix argument provided, do not indent and do not delete | |
2113 headers. Leaves the mark before the letter and point after it." | |
2114 (interactive | |
2115 (list current-prefix-arg | |
2116 (mh-prompt-for-folder "Message from" mh-sent-from-folder nil) | |
2117 (read-input (format "Message number%s: " | |
2118 (if mh-sent-from-msg | |
2119 (format " [%d]" mh-sent-from-msg) | |
2120 ""))))) | |
2121 (save-restriction | |
2122 (narrow-to-region (point) (point)) | |
2123 (let ((start (point-min))) | |
2124 (if (equal msg "") (setq msg (int-to-string mh-sent-from-msg))) | |
2125 (mh-exec-lib-cmd-output "mhl" "-nobell" "-noclear" | |
2126 (expand-file-name msg | |
2127 (mh-expand-file-name folder))) | |
2128 (mh-when (not prefix-provided) | |
2129 (mh-clean-msg-header start mh-invisible-headers mh-visible-headers) | |
2130 (set-mark start) ; since mh-clean-msg-header moves it | |
2131 (mh-insert-prefix-string mh-ins-buf-prefix))))) | |
2132 | |
2133 | |
2134 (defun mh-yank-cur-msg () | |
2135 "Insert the current message into the draft buffer. | |
2136 Prefix each non-blank line in the message with the string in | |
2137 `mh-ins-buf-prefix'. If a region is set in the message's buffer, then | |
2138 only the region will be inserted. Otherwise, the entire message will | |
2139 be inserted if `mh-yank-from-start-of-msg' is non-nil. If this variable | |
2140 is nil, the portion of the message following the point will be yanked. | |
2141 If `mh-delete-yanked-msg-window' is non-nil, any window displaying the | |
2142 yanked message will be deleted." | |
2143 (interactive) | |
2144 (if (and mh-sent-from-folder mh-sent-from-msg) | |
2145 (let ((to-point (point)) | |
2146 (to-buffer (current-buffer))) | |
2147 (set-buffer mh-sent-from-folder) | |
2148 (if mh-delete-yanked-msg-window | |
2149 (delete-windows-on mh-show-buffer)) | |
2150 (set-buffer mh-show-buffer) ; Find displayed message | |
2151 (let ((mh-ins-str (cond ((mark) | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
2152 (buffer-substring (region-beginning) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
2153 (region-end))) |
731 | 2154 ((eq 'body mh-yank-from-start-of-msg) |
2155 (buffer-substring | |
2156 (save-excursion | |
2157 (goto-char (point-min)) | |
2158 (mh-goto-header-end 1) | |
2159 (point)) | |
2160 (point-max))) | |
2161 (mh-yank-from-start-of-msg | |
2162 (buffer-substring (point-min) (point-max))) | |
2163 (t | |
2164 (buffer-substring (point) (point-max)))))) | |
2165 (set-buffer to-buffer) | |
2166 (narrow-to-region to-point to-point) | |
2167 (push-mark) | |
2168 (insert mh-ins-str) | |
2169 (mh-insert-prefix-string mh-ins-buf-prefix) | |
2170 (insert "\n") | |
2171 (widen))) | |
2172 (error "There is no current message"))) | |
2173 | |
2174 | |
2175 (defun mh-insert-prefix-string (mh-ins-string) | |
2176 ;; Run MH-YANK-HOOK to insert a prefix string before each line in the buffer. | |
2177 ;; Generality for supercite users. | |
2178 (save-excursion | |
2179 (set-mark (point-max)) | |
2180 (goto-char (point-min)) | |
2181 (run-hooks 'mh-yank-hooks))) | |
2182 | |
2183 | |
2184 (defun mh-fully-kill-draft () | |
2185 "Kill the draft message file and the draft message buffer. | |
2186 Use \\[kill-buffer] if you don't want to delete the draft message file." | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
2187 (interactive) |
731 | 2188 (if (y-or-n-p "Kill draft message? ") |
2189 (let ((config mh-previous-window-config)) | |
2190 (if (file-exists-p (buffer-file-name)) | |
2191 (delete-file (buffer-file-name))) | |
2192 (set-buffer-modified-p nil) | |
2193 (kill-buffer (buffer-name)) | |
2194 (message "") | |
2195 (if config | |
2196 (set-window-configuration config))) | |
2197 (error "Message not killed"))) | |
2198 | |
2199 | |
2200 (defun mh-recenter (arg) | |
2201 ;; Like recenter but with two improvements: nil arg means recenter, | |
2202 ;; and only does anything if the current buffer is in the selected | |
2203 ;; window. (Commands like save-some-buffers can make this false.) | |
2204 (if (eql (get-buffer-window (current-buffer)) | |
2205 (selected-window)) | |
2206 (recenter (if arg arg '(t))))) | |
2207 | |
2208 | |
2209 | |
2210 ;;; Commands to manipulate sequences. Sequences are stored in an alist | |
2211 ;;; of the form: | |
2212 ;;; ((seq-name msgs ...) (seq-name msgs ...) ...) | |
2213 | |
2214 (defun mh-make-seq (name msgs) (cons name msgs)) | |
2215 | |
2216 (defmacro mh-seq-name (pair) (list 'car pair)) | |
2217 | |
2218 (defmacro mh-seq-msgs (pair) (list 'cdr pair)) | |
2219 | |
2220 (defun mh-find-seq (name) (assoc name mh-seq-list)) | |
2221 | |
2222 | |
2223 (defun mh-seq-to-msgs (seq) | |
2224 "Return a list of the messages in SEQUENCE." | |
2225 (mh-seq-msgs (mh-find-seq seq))) | |
2226 | |
2227 | |
2228 (defun mh-seq-containing-msg (msg) | |
2229 ;; Return a list of the sequences containing MESSAGE. | |
2230 (let ((l mh-seq-list) | |
2231 (seqs ())) | |
2232 (while l | |
2233 (if (memq msg (mh-seq-msgs (car l))) | |
2234 (mh-push (mh-seq-name (car l)) seqs)) | |
2235 (setq l (cdr l))) | |
2236 seqs)) | |
2237 | |
2238 | |
2239 (defun mh-msg-to-seq (msg) | |
2240 ;; Given a MESSAGE number, return the first sequence in which it occurs. | |
2241 (car (mh-seq-containing-msg msg))) | |
2242 | |
2243 | |
2244 (defun mh-read-seq-default (prompt not-empty) | |
2245 ;; Read and return sequence name with default narrowed or previous sequence. | |
2246 (mh-read-seq prompt not-empty (or mh-narrowed-to-seq mh-previous-seq))) | |
2247 | |
2248 | |
2249 (defun mh-read-seq (prompt not-empty &optional default) | |
2250 ;; Read and return a sequence name. Prompt with PROMPT, raise an error | |
2251 ;; if the sequence is empty and the NOT-EMPTY flag is non-nil, and supply | |
2252 ;; an optional DEFAULT sequence. | |
2253 ;; A reply of '%' defaults to the first sequence containing the current | |
2254 ;; message. | |
2255 (let* ((input (completing-read (format "%s %s %s" prompt "sequence:" | |
2256 (if default | |
2257 (format "[%s] " default) | |
2258 "")) | |
2259 (mh-seq-names mh-seq-list))) | |
2260 (seq (cond ((equal input "%") (mh-msg-to-seq (mh-get-msg-num t))) | |
2261 ((equal input "") default) | |
2262 (t (intern input)))) | |
2263 (msgs (mh-seq-to-msgs seq))) | |
2264 (if (and (null msgs) not-empty) | |
2265 (error (format "No messages in sequence `%s'" seq))) | |
2266 seq)) | |
2267 | |
2268 | |
2269 (defun mh-read-folder-sequences (folder define-sequences) | |
2270 ;; Read and return the predefined sequences for a FOLDER. If | |
2271 ;; DEFINE-SEQUENCES is non-nil, then define mh-e's sequences before | |
2272 ;; reading MH's sequences. | |
2273 (let ((seqs ())) | |
2274 (mh-when define-sequences | |
2275 (mh-define-sequences mh-seq-list) | |
2276 (mh-mapc (function (lambda (seq) ; Save the internal sequences | |
2277 (if (mh-folder-name-p (mh-seq-name seq)) | |
2278 (mh-push seq seqs)))) | |
2279 mh-seq-list)) | |
2280 (save-excursion | |
2281 (mh-exec-cmd-quiet " *mh-temp*" "mark" folder "-list") | |
2282 (goto-char (point-min)) | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
2283 ;; look for name in line of form "cur: 4" or "myseq (private): 23" |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
2284 (while (re-search-forward "^[^: ]+" nil t) |
731 | 2285 (mh-push (mh-make-seq (intern (buffer-substring (match-beginning 0) |
2286 (match-end 0))) | |
2287 (mh-read-msg-list)) | |
2288 seqs)) | |
2289 (delete-region (point-min) (point))) ; avoid race with mh-process-daemon | |
2290 seqs)) | |
2291 | |
2292 | |
2293 (defun mh-seq-names (seq-list) | |
2294 ;; Return an alist containing the names of the SEQUENCES. | |
2295 (mapcar (function (lambda (entry) (list (symbol-name (mh-seq-name entry))))) | |
2296 seq-list)) | |
2297 | |
2298 | |
2299 (defun mh-seq-from-command (folder seq seq-command) | |
2300 ;; In FOLDER, make a sequence named SEQ by executing COMMAND. | |
2301 ;; COMMAND is a list. The first element is a program name | |
2302 ;; and the subsequent elements are its arguments, all strings. | |
2303 (let ((msg) | |
2304 (msgs ()) | |
2305 (case-fold-search t)) | |
2306 (save-excursion | |
2307 (save-window-excursion | |
2308 (apply 'mh-exec-cmd-quiet " *mh-temp*" seq-command) | |
2309 (goto-char (point-min)) | |
2310 (while (setq msg (car (mh-read-msg-list))) | |
2311 (mh-push msg msgs) | |
2312 (forward-line 1))) | |
2313 (set-buffer folder) | |
2314 (setq msgs (nreverse msgs)) ; Put in ascending order | |
2315 (mh-push (mh-make-seq seq msgs) mh-seq-list) | |
2316 msgs))) | |
2317 | |
2318 | |
2319 (defun mh-read-msg-list () | |
2320 ;; Return a list of message numbers from the current point to the end of | |
2321 ;; the line. | |
2322 (let ((msgs ()) | |
2323 (end-of-line (save-excursion (end-of-line) (point))) | |
2324 num) | |
2325 (while (re-search-forward "[0-9]+" end-of-line t) | |
2326 (setq num (string-to-int (buffer-substring (match-beginning 0) | |
2327 (match-end 0)))) | |
2328 (cond ((looking-at "-") ; Message range | |
2329 (forward-char 1) | |
2330 (re-search-forward "[0-9]+" end-of-line t) | |
2331 (let ((num2 (string-to-int (buffer-substring (match-beginning 0) | |
2332 (match-end 0))))) | |
2333 (if (< num2 num) | |
2334 (error "Bad message range: %d-%d" num num2)) | |
2335 (while (<= num num2) | |
2336 (mh-push num msgs) | |
2337 (setq num (1+ num))))) | |
2338 ((not (zerop num)) (mh-push num msgs)))) | |
2339 msgs)) | |
2340 | |
2341 | |
2342 (defun mh-remove-seq (seq) | |
2343 ;; Delete the SEQUENCE. | |
2344 (mh-map-to-seq-msgs 'mh-notate-if-in-one-seq seq ? (1+ mh-cmd-note) seq) | |
2345 (mh-undefine-sequence seq (list "all")) | |
2346 (mh-delete-seq-locally seq)) | |
2347 | |
2348 | |
2349 (defun mh-delete-seq-locally (seq) | |
2350 ;; Remove mh-e's record of SEQUENCE. | |
2351 (let ((entry (mh-find-seq seq))) | |
2352 (setq mh-seq-list (delq entry mh-seq-list)))) | |
2353 | |
2354 | |
2355 (defun mh-remove-msg-from-seq (msg seq &optional internal-flag) | |
2356 ;; Remove MESSAGE from the SEQUENCE. If optional FLAG is non-nil, do not | |
2357 ;; inform MH of the change. | |
2358 (let ((entry (mh-find-seq seq))) | |
2359 (mh-when entry | |
2360 (mh-notate-if-in-one-seq msg ? (1+ mh-cmd-note) (mh-seq-name entry)) | |
2361 (if (not internal-flag) | |
2362 (mh-undefine-sequence seq (list msg))) | |
2363 (setcdr entry (delq msg (mh-seq-msgs entry)))))) | |
2364 | |
2365 | |
2366 (defun mh-add-msgs-to-seq (msgs seq &optional internal-flag) | |
2367 ;; Add MESSAGE(s) to the SEQUENCE. If optional FLAG is non-nil, do not mark | |
2368 ;; the message in the scan listing or inform MH of the addition. | |
2369 (let ((entry (mh-find-seq seq))) | |
2370 (if (and msgs (atom msgs)) (setq msgs (list msgs))) | |
2371 (if (null entry) | |
2372 (mh-push (mh-make-seq seq msgs) mh-seq-list) | |
2373 (if msgs (setcdr entry (append msgs (cdr entry))))) | |
2374 (mh-when (not internal-flag) | |
2375 (mh-add-to-sequence seq msgs) | |
2376 (mh-notate-seq seq ?% (1+ mh-cmd-note))))) | |
2377 | |
2378 | |
2379 (defun mh-rename-seq (seq new-name) | |
2380 "Rename a SEQUENCE to have a new NAME." | |
2381 (interactive "SOld sequence name: \nSNew name: ") | |
2382 (let ((old-seq (mh-find-seq seq))) | |
2383 (if old-seq | |
2384 (rplaca old-seq new-name) | |
2385 (error "Sequence %s does not exists" seq)) | |
2386 (mh-undefine-sequence seq (mh-seq-msgs old-seq)) | |
2387 (mh-define-sequence new-name (mh-seq-msgs old-seq)))) | |
2388 | |
2389 | |
2390 (defun mh-notate-user-sequences () | |
2391 ;; Mark the scan listing of all messages in user-defined sequences. | |
2392 (let ((seqs mh-seq-list) | |
2393 name) | |
2394 (while seqs | |
2395 (setq name (mh-seq-name (car seqs))) | |
2396 (if (not (mh-internal-seq name)) | |
2397 (mh-notate-seq name ?% (1+ mh-cmd-note))) | |
2398 (setq seqs (cdr seqs))))) | |
2399 | |
2400 | |
2401 (defun mh-internal-seq (name) | |
2402 ;; Return non-NIL if NAME is the name of an internal mh-e sequence. | |
2403 (or (memq name '(answered cur deleted forwarded printed)) | |
2404 (eq name mh-unseen-seq) | |
2405 (mh-folder-name-p name))) | |
2406 | |
2407 | |
2408 (defun mh-folder-name-p (name) | |
2409 ;; Return non-NIL if NAME is possibly the name of a folder. | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
2410 ;; A name (a string or symbol) can be a folder name if it begins with "+". |
731 | 2411 (if (symbolp name) |
2412 (eql (aref (symbol-name name) 0) ?+) | |
2413 (eql (aref name 0) ?+))) | |
2414 | |
2415 | |
2416 (defun mh-notate-seq (seq notation offset) | |
2417 ;; Mark the scan listing of all messages in the SEQUENCE with the CHARACTER | |
2418 ;; at the given OFFSET from the beginning of the listing line. | |
2419 (mh-map-to-seq-msgs 'mh-notate seq notation offset)) | |
2420 | |
2421 | |
2422 (defun mh-notate-if-in-one-seq (msg notation offset seq) | |
2423 ;; If the MESSAGE is in only the SEQUENCE, then mark the scan listing of the | |
2424 ;; message with the CHARACTER at the given OFFSET from the beginning of the | |
2425 ;; listing line. | |
2426 (let ((in-seqs (mh-seq-containing-msg msg))) | |
2427 (if (and (eq seq (car in-seqs)) (null (cdr in-seqs))) | |
2428 (mh-notate msg notation offset)))) | |
2429 | |
2430 | |
2431 (defun mh-map-to-seq-msgs (func seq &rest args) | |
2432 ;; Invoke the FUNCTION at each message in the SEQUENCE, passing the | |
2433 ;; remaining ARGS as arguments. | |
2434 (save-excursion | |
2435 (let ((msgs (mh-seq-to-msgs seq))) | |
2436 (while msgs | |
2437 (if (mh-goto-msg (car msgs) t t) | |
2438 (apply func (car msgs) args)) | |
2439 (setq msgs (cdr msgs)))))) | |
2440 | |
2441 | |
2442 (defun mh-map-over-seqs (func seq-list) | |
2443 ;; Apply the FUNCTION to each element in the list of SEQUENCES, | |
2444 ;; passing the sequence name and the list of messages as arguments. | |
2445 (while seq-list | |
2446 (funcall func (mh-seq-name (car seq-list)) (mh-seq-msgs (car seq-list))) | |
2447 (setq seq-list (cdr seq-list)))) | |
2448 | |
2449 | |
2450 (defun mh-define-sequences (seq-list) | |
2451 ;; Define the sequences in SEQ-LIST. | |
2452 (mh-map-over-seqs 'mh-define-sequence seq-list)) | |
2453 | |
2454 | |
2455 (defun mh-add-to-sequence (seq msgs) | |
2456 ;; Add to a SEQUENCE each message the list of MSGS. | |
2457 (if (not (mh-folder-name-p seq)) | |
2458 (if msgs | |
2459 (apply 'mh-exec-cmd "mark" mh-current-folder | |
2460 "-sequence" (symbol-name seq) | |
2461 "-add" msgs)))) | |
2462 | |
2463 | |
2464 (defun mh-define-sequence (seq msgs) | |
2465 ;; Define the SEQUENCE to contain the list of MSGS. Do not mark | |
2466 ;; pseudo-sequences or empty sequences. | |
2467 (if (and msgs | |
2468 (not (mh-folder-name-p seq))) | |
2469 (save-excursion | |
2470 (apply 'mh-exec-cmd "mark" mh-current-folder | |
2471 "-sequence" (symbol-name seq) | |
2472 "-add" "-zero" (mh-list-to-string msgs))))) | |
2473 | |
2474 | |
2475 (defun mh-undefine-sequence (seq msgs) | |
2476 ;; Remove from the SEQUENCE the list of MSGS. | |
2477 (apply 'mh-exec-cmd "mark" mh-current-folder | |
2478 "-sequence" (symbol-name seq) | |
2479 "-delete" msgs)) | |
2480 | |
2481 | |
2482 (defun mh-copy-seq-to-point (seq location) | |
2483 ;; Copy the scan listing of the messages in SEQUENCE to after the point | |
2484 ;; LOCATION in the current buffer. | |
2485 (mh-map-to-seq-msgs 'mh-copy-line-to-point seq location)) | |
2486 | |
2487 | |
2488 (defun mh-copy-line-to-point (msg location) | |
2489 ;; Copy the current line to the LOCATION in the current buffer. | |
2490 (beginning-of-line) | |
2491 (let ((beginning-of-line (point))) | |
2492 (forward-line 1) | |
2493 (copy-region-as-kill beginning-of-line (point)) | |
2494 (goto-char location) | |
2495 (yank) | |
2496 (goto-char beginning-of-line))) | |
2497 | |
2498 | |
2499 | |
2500 ;;; Issue commands to MH. | |
2501 | |
2502 (defun mh-exec-cmd (command &rest args) | |
2503 ;; Execute MH command COMMAND with ARGS. | |
2504 ;; Any output is assumed to be an error and is shown to the user. | |
2505 (save-excursion | |
2506 (set-buffer " *mh-temp*") | |
2507 (erase-buffer) | |
2508 (apply 'call-process | |
2509 (expand-file-name command mh-progs) nil t nil | |
2510 (mh-list-to-string args)) | |
2511 (if (> (buffer-size) 0) | |
2512 (save-window-excursion | |
2513 (switch-to-buffer-other-window " *mh-temp*") | |
2514 (sit-for 5))))) | |
2515 | |
2516 | |
2517 (defun mh-exec-cmd-quiet (buffer command &rest args) | |
2518 ;; In BUFFER, execute MH command COMMAND with ARGS. | |
2519 ;; ARGS is a list of strings. Return in BUFFER, if one exists. | |
2520 (mh-when (stringp buffer) | |
2521 (set-buffer buffer) | |
2522 (erase-buffer)) | |
2523 (apply 'call-process | |
2524 (expand-file-name command mh-progs) nil buffer nil | |
2525 args)) | |
2526 | |
2527 | |
2528 (defun mh-exec-cmd-output (command display &rest args) | |
2529 ;; Execute MH command COMMAND with DISPLAY flag and ARGS putting the output | |
2530 ;; into buffer after point. Set mark after inserted text. | |
2531 (push-mark (point) t) | |
2532 (apply 'call-process | |
2533 (expand-file-name command mh-progs) nil t display | |
2534 (mh-list-to-string args)) | |
2535 (exchange-point-and-mark)) | |
2536 | |
2537 | |
2538 (defun mh-exec-cmd-daemon (command &rest args) | |
2539 ;; Execute MH command COMMAND with ARGS. Any output from command is | |
2540 ;; displayed in an asynchronous pop-up window. | |
2541 (save-excursion | |
2542 (set-buffer (get-buffer-create " *mh-temp*")) | |
2543 (erase-buffer)) | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
2544 (let* ((process-connection-type nil) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
2545 (process (apply 'start-process |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
2546 command nil |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
2547 (expand-file-name command mh-progs) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
2548 (mh-list-to-string args)))) |
731 | 2549 (set-process-filter process 'mh-process-daemon))) |
2550 | |
2551 | |
2552 (defun mh-process-daemon (process output) | |
2553 ;; Process daemon that puts output into a temporary buffer. | |
2554 (set-buffer (get-buffer-create " *mh-temp*")) | |
2555 (insert-before-markers output) | |
2556 (display-buffer " *mh-temp*")) | |
2557 | |
2558 | |
2559 (defun mh-exec-lib-cmd-output (command &rest args) | |
2560 ;; Execute MH library command COMMAND with ARGS. | |
2561 ;; Put the output into buffer after point. Set mark after inserted text. | |
2562 (push-mark (point) t) | |
2563 (apply 'call-process | |
2564 (expand-file-name command mh-lib) nil t nil | |
2565 (mh-list-to-string args)) | |
2566 (exchange-point-and-mark)) | |
2567 | |
2568 | |
2569 (defun mh-list-to-string (l) | |
2570 ;; Flattens the list L and makes every element of the new list into a string. | |
2571 (let ((new-list nil)) | |
2572 (while l | |
2573 (cond ((null (car l))) | |
2574 ((symbolp (car l)) (mh-push (symbol-name (car l)) new-list)) | |
2575 ((numberp (car l)) (mh-push (int-to-string (car l)) new-list)) | |
2576 ((equal (car l) "")) | |
2577 ((stringp (car l)) (mh-push (car l) new-list)) | |
2578 ((listp (car l)) | |
2579 (setq new-list (nconc (nreverse (mh-list-to-string (car l))) | |
2580 new-list))) | |
2581 (t (error "Bad element in mh-list-to-string: %s" (car l)))) | |
2582 (setq l (cdr l))) | |
2583 (nreverse new-list))) | |
2584 | |
2585 | |
2586 | |
2587 ;;; Commands to annotate a message. | |
2588 | |
2589 (defun mh-annotate-msg (msg buffer note &rest args) | |
2590 ;; Mark the MESSAGE in BUFFER listing with the character NOTE and annotate | |
2591 ;; the saved message with ARGS. | |
2592 (apply 'mh-exec-cmd "anno" buffer msg args) | |
2593 (save-excursion | |
2594 (cond ((get-buffer buffer) ; Buffer may be deleted | |
2595 (set-buffer buffer) | |
2596 (if (symbolp msg) | |
2597 (mh-notate-seq msg note (1+ mh-cmd-note)) | |
2598 (mh-notate msg note (1+ mh-cmd-note))))))) | |
2599 | |
2600 | |
2601 (defun mh-notate (msg notation offset) | |
2602 ;; Marks MESSAGE with the character NOTATION at position OFFSET. | |
2603 ;; Null MESSAGE means the message that the cursor points to. | |
2604 (save-excursion | |
2605 (if (or (null msg) | |
2606 (mh-goto-msg msg t t)) | |
2607 (with-mh-folder-updating (t) | |
2608 (beginning-of-line) | |
2609 (forward-char offset) | |
2610 (delete-char 1) | |
2611 (insert notation))))) | |
2612 | |
2613 | |
2614 | |
2615 ;;; User prompting commands. | |
2616 | |
2617 (defun mh-prompt-for-folder (prompt default can-create) | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
2618 ;; Prompt for a folder name with PROMPT. Returns the folder's name as a |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
2619 ;; string. DEFAULT is used if the folder exists and the user types return. |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
2620 ;; If the CAN-CREATE flag is t, then a non-existent folder is made. |
731 | 2621 (let* ((prompt (format "%s folder%s" prompt |
2622 (if (equal "" default) | |
2623 "? " | |
2624 (format " [%s]? " default)))) | |
2625 name) | |
2626 (if (null mh-folder-list) | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
2627 (mh-set-folder-list)) |
731 | 2628 (while (and (setq name (completing-read prompt mh-folder-list |
2629 nil nil "+")) | |
2630 (equal name "") | |
2631 (equal default ""))) | |
2632 (cond ((or (equal name "") (equal name "+")) | |
2633 (setq name default)) | |
2634 ((not (mh-folder-name-p name)) | |
2635 (setq name (format "+%s" name)))) | |
2636 (let ((new-file-p (not (file-exists-p (mh-expand-file-name name))))) | |
2637 (cond ((and new-file-p | |
2638 (y-or-n-p | |
2639 (format "Folder %s does not exist. Create it? " name))) | |
2640 (message "Creating %s" name) | |
2641 (call-process "mkdir" nil nil nil (mh-expand-file-name name)) | |
2642 (message "Creating %s...done" name) | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
2643 (mh-push (list name) mh-folder-list)) |
731 | 2644 (new-file-p |
2645 (error "Folder %s is not created" name)) | |
2646 (t | |
2647 (mh-when (null (assoc name mh-folder-list)) | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
2648 (mh-push (list name) mh-folder-list))))) |
731 | 2649 name)) |
2650 | |
2651 | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
2652 (defun mh-set-folder-list () |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
2653 "Sets mh-folder-list correctly. |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
2654 A useful function for the command line or for when you need to sync by hand." |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
2655 (setq mh-folder-list (mh-make-folder-list))) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
2656 |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
2657 |
731 | 2658 (defun mh-make-folder-list () |
2659 "Return a list of the user's folders. | |
2660 Result is in a form suitable for completing read." | |
2661 (interactive) | |
2662 (message "Collecting folder names...") | |
2663 (save-window-excursion | |
2664 (mh-exec-cmd-quiet " *mh-temp*" "folders" "-fast" | |
2665 (if mh-recursive-folders | |
2666 "-recurse" | |
2667 "-norecurse")) | |
2668 (goto-char (point-min)) | |
2669 (let ((list nil) | |
2670 start) | |
2671 (while (not (eobp)) | |
2672 (setq start (point)) | |
2673 (forward-line 1) | |
2674 (mh-push (list (format "+%s" (buffer-substring start (1- (point))))) | |
2675 list)) | |
2676 (message "Collecting folder names...done") | |
2677 list))) | |
2678 | |
2679 | |
2680 (defun mh-remove-folder-from-folder-list (folder) | |
2681 ;; Remove FOLDER from the list of folders. | |
2682 (setq mh-folder-list | |
2683 (delq (assoc folder mh-folder-list) mh-folder-list))) | |
2684 | |
2685 | |
2686 (defun mh-read-msg-range (prompt) | |
2687 ;; Read a list of blank-separated items. | |
2688 (let* ((buf (read-string prompt)) | |
2689 (buf-size (length buf)) | |
2690 (start 0) | |
2691 (input ())) | |
2692 (while (< start buf-size) | |
2693 (let ((next (read-from-string buf start buf-size))) | |
2694 (mh-push (car next) input) | |
2695 (setq start (cdr next)))) | |
2696 (nreverse input))) | |
2697 | |
2698 | |
2699 | |
2700 ;;; Misc. functions. | |
2701 | |
2702 (defun mh-get-msg-num (error-if-no-message) | |
2703 ;; Return the message number of the displayed message. If the argument | |
2704 ;; ERROR-IF-NO-MESSAGE is non-nil, then complain if the cursor is not | |
2705 ;; pointing to a message. | |
2706 (save-excursion | |
2707 (beginning-of-line) | |
2708 (cond ((looking-at mh-msg-number-regexp) | |
2709 (string-to-int (buffer-substring (match-beginning 1) | |
2710 (match-end 1)))) | |
2711 (error-if-no-message | |
2712 (error "Cursor not pointing to message")) | |
2713 (t nil)))) | |
2714 | |
2715 | |
2716 (defun mh-msg-search-pat (n) | |
2717 ;; Return a search pattern for message N in the scan listing. | |
2718 (format mh-msg-search-regexp n)) | |
2719 | |
2720 | |
2721 (defun mh-msg-filename (msg &optional folder) | |
2722 ;; Return the file name of MESSAGE in FOLDER (default current folder). | |
2723 (expand-file-name (int-to-string msg) | |
2724 (if folder | |
2725 (mh-expand-file-name folder) | |
2726 mh-folder-filename))) | |
2727 | |
2728 | |
2729 (defun mh-msg-filenames (msgs &optional folder) | |
2730 ;; Return a list of file names for MSGS in FOLDER (default current folder). | |
2731 (mapconcat (function (lambda (msg) (mh-msg-filename msg folder))) msgs " ")) | |
2732 | |
2733 | |
2734 (defun mh-expand-file-name (filename &optional default) | |
2735 "Just like `expand-file-name', but also handles MH folder names. | |
2736 Assumes that any filename that starts with '+' is a folder name." | |
2737 (if (mh-folder-name-p filename) | |
2738 (expand-file-name (substring filename 1) mh-user-path) | |
2739 (expand-file-name filename default))) | |
2740 | |
2741 | |
2742 (defun mh-find-path () | |
2743 ;; Set mh-user-path, mh-draft-folder, and mh-unseen-seq from profile file. | |
2744 (save-excursion | |
2745 ;; Be sure profile is fully expanded before switching buffers | |
2746 (let ((profile (expand-file-name (or (getenv "MH") "~/.mh_profile")))) | |
2747 (if (not (file-exists-p profile)) | |
2748 (error "Cannot find MH profile %s" profile)) | |
2749 (set-buffer (get-buffer-create " *mh-temp*")) | |
2750 (erase-buffer) | |
2751 (insert-file-contents profile) | |
2752 (setq mh-draft-folder (mh-get-field "Draft-Folder:")) | |
2753 (cond ((equal mh-draft-folder "") | |
2754 (setq mh-draft-folder nil)) | |
2755 ((not (mh-folder-name-p mh-draft-folder)) | |
2756 (setq mh-draft-folder (format "+%s" mh-draft-folder)))) | |
2757 (setq mh-user-path (mh-get-field "Path:")) | |
2758 (if (equal mh-user-path "") | |
2759 (setq mh-user-path "Mail")) | |
2760 (setq mh-user-path | |
2761 (file-name-as-directory | |
2762 (expand-file-name mh-user-path (expand-file-name "~")))) | |
2763 (if (and mh-draft-folder | |
2764 (not (file-exists-p (mh-expand-file-name mh-draft-folder)))) | |
2765 (error "Draft folder %s does not exist. Create it and try again." | |
2766 mh-draft-folder)) | |
2767 (setq mh-unseen-seq (mh-get-field "Unseen-Sequence:")) | |
2768 (if (equal mh-unseen-seq "") | |
2769 (setq mh-unseen-seq 'unseen) | |
2770 (setq mh-unseen-seq (intern mh-unseen-seq)))))) | |
2771 | |
2772 | |
2773 (defun mh-get-field (field) | |
2774 ;; Find and return the value of field FIELD in the current buffer. | |
2775 ;; Returns the empty string if the field is not in the message. | |
2776 (let ((case-fold-search t)) | |
2777 (goto-char (point-min)) | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
2778 (cond ((not (re-search-forward (format "^%s" field) nil t)) "") |
731 | 2779 ((looking-at "[\t ]*$") "") |
2780 (t | |
2781 (re-search-forward "[\t ]*\\([^\t \n].*\\)$" nil t) | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
2782 (let ((start (match-beginning 1))) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
2783 (forward-line 1) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
2784 (while (looking-at "[ \t]") |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
2785 (forward-line 1)) |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
2786 (buffer-substring start (1- (point)))))))) |
731 | 2787 |
2788 | |
2789 (defun mh-insert-fields (&rest name-values) | |
2790 ;; Insert the NAME-VALUE pairs in the current buffer. | |
2791 ;; Do not insert any pairs whose value is the empty string. | |
2792 (let ((case-fold-search t)) | |
2793 (while name-values | |
2794 (let ((field-name (car name-values)) | |
2795 (value (car (cdr name-values)))) | |
2796 (mh-when (not (equal value "")) | |
2797 (goto-char (point-min)) | |
2798 (cond ((not (re-search-forward (format "^%s" field-name) nil t)) | |
2799 (mh-goto-header-end 0) | |
2800 (insert field-name " " value "\n")) | |
2801 (t | |
2802 (end-of-line) | |
2803 (insert " " value)))) | |
2804 (setq name-values (cdr (cdr name-values))))))) | |
2805 | |
2806 | |
2807 (defun mh-position-on-field (field set-mark) | |
2808 ;; Set point to the end of the line beginning with FIELD. | |
2809 ;; Set the mark to the old value of point, if SET-MARK is non-nil. | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
2810 ;; Returns non-nil iff the field was found. |
731 | 2811 (let ((case-fold-search t)) |
2812 (if set-mark (push-mark)) | |
2813 (goto-char (point-min)) | |
2814 (mh-goto-header-end 0) | |
2815 (if (re-search-backward (format "^%s" field) nil t) | |
2816 (progn (end-of-line) t) | |
2817 nil))) | |
2818 | |
2819 | |
2820 (defun mh-goto-header-end (arg) | |
2821 ;; Find the end of the message header in the current buffer and position | |
2822 ;; the cursor at the ARG'th newline after the header. | |
2823 (if (re-search-forward "^$\\|^-+$" nil nil) | |
2824 (forward-line arg))) | |
2825 | |
2826 | |
2827 | |
2828 ;;; Build the folder-mode keymap: | |
2829 | |
2830 (suppress-keymap mh-folder-mode-map) | |
2831 (define-key mh-folder-mode-map "q" 'mh-quit) | |
2832 (define-key mh-folder-mode-map "b" 'mh-quit) | |
2833 (define-key mh-folder-mode-map "?" 'mh-msg-is-in-seq) | |
2834 (define-key mh-folder-mode-map "%" 'mh-put-msg-in-seq) | |
2835 (define-key mh-folder-mode-map "|" 'mh-pipe-msg) | |
2836 (define-key mh-folder-mode-map "\ea" 'mh-edit-again) | |
2837 (define-key mh-folder-mode-map "\e%" 'mh-delete-msg-from-seq) | |
2838 (define-key mh-folder-mode-map "\C-xn" 'mh-narrow-to-seq) | |
2839 (define-key mh-folder-mode-map "\C-xw" 'mh-widen) | |
2840 (define-key mh-folder-mode-map "\eb" 'mh-burst-digest) | |
2841 (define-key mh-folder-mode-map "\eu" 'mh-undo-folder) | |
2842 (define-key mh-folder-mode-map "\e " 'mh-page-digest) | |
2843 (define-key mh-folder-mode-map "\e\177" 'mh-page-digest-backwards) | |
2844 (define-key mh-folder-mode-map "\ee" 'mh-extract-rejected-mail) | |
2845 (define-key mh-folder-mode-map "\ef" 'mh-visit-folder) | |
2846 (define-key mh-folder-mode-map "\ek" 'mh-kill-folder) | |
2847 (define-key mh-folder-mode-map "\el" 'mh-list-folders) | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
2848 (define-key mh-folder-mode-map "\en" 'mh-unshar-msg) |
731 | 2849 (define-key mh-folder-mode-map "\eo" 'mh-write-msg-to-file) |
2850 (define-key mh-folder-mode-map "\ep" 'mh-pack-folder) | |
2851 (define-key mh-folder-mode-map "\es" 'mh-search-folder) | |
2852 (define-key mh-folder-mode-map "\er" 'mh-rescan-folder) | |
2853 (define-key mh-folder-mode-map "l" 'mh-print-msg) | |
2854 (define-key mh-folder-mode-map "t" 'mh-toggle-showing) | |
2855 (define-key mh-folder-mode-map "c" 'mh-copy-msg) | |
2856 (define-key mh-folder-mode-map ">" 'mh-write-msg-to-file) | |
2857 (define-key mh-folder-mode-map "i" 'mh-inc-folder) | |
2858 (define-key mh-folder-mode-map "x" 'mh-execute-commands) | |
2859 (define-key mh-folder-mode-map "e" 'mh-execute-commands) | |
2860 (define-key mh-folder-mode-map "r" 'mh-redistribute) | |
2861 (define-key mh-folder-mode-map "f" 'mh-forward) | |
2862 (define-key mh-folder-mode-map "s" 'mh-send) | |
2863 (define-key mh-folder-mode-map "m" 'mh-send) | |
2864 (define-key mh-folder-mode-map "a" 'mh-reply) | |
2865 (define-key mh-folder-mode-map "j" 'mh-goto-msg) | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
2866 (define-key mh-folder-mode-map "<" 'mh-first-msg) |
731 | 2867 (define-key mh-folder-mode-map "g" 'mh-goto-msg) |
2868 (define-key mh-folder-mode-map "\177" 'mh-previous-page) | |
2869 (define-key mh-folder-mode-map " " 'mh-page-msg) | |
2870 (define-key mh-folder-mode-map "." 'mh-show) | |
2871 (define-key mh-folder-mode-map "u" 'mh-undo) | |
2872 (define-key mh-folder-mode-map "!" 'mh-refile-or-write-again) | |
2873 (define-key mh-folder-mode-map "^" 'mh-refile-msg) | |
2874 (define-key mh-folder-mode-map "d" 'mh-delete-msg) | |
2875 (define-key mh-folder-mode-map "\C-d" 'mh-delete-msg-no-motion) | |
2876 (define-key mh-folder-mode-map "p" 'mh-previous-undeleted-msg) | |
2877 (define-key mh-folder-mode-map "n" 'mh-next-undeleted-msg) | |
2878 (define-key mh-folder-mode-map "o" 'mh-refile-msg) | |
2879 | |
2880 | |
2881 ;;; Build the letter-mode keymap: | |
2882 | |
2883 (define-key mh-letter-mode-map "\C-c\C-f\C-b" 'mh-to-field) | |
2884 (define-key mh-letter-mode-map "\C-c\C-f\C-c" 'mh-to-field) | |
2885 (define-key mh-letter-mode-map "\C-c\C-f\C-f" 'mh-to-fcc) | |
2886 (define-key mh-letter-mode-map "\C-c\C-f\C-s" 'mh-to-field) | |
2887 (define-key mh-letter-mode-map "\C-c\C-f\C-t" 'mh-to-field) | |
2888 (define-key mh-letter-mode-map "\C-c\C-fb" 'mh-to-field) | |
2889 (define-key mh-letter-mode-map "\C-c\C-fc" 'mh-to-field) | |
2890 (define-key mh-letter-mode-map "\C-c\C-ff" 'mh-to-fcc) | |
2891 (define-key mh-letter-mode-map "\C-c\C-fs" 'mh-to-field) | |
2892 (define-key mh-letter-mode-map "\C-c\C-ft" 'mh-to-field) | |
2893 (define-key mh-letter-mode-map "\C-c\C-q" 'mh-fully-kill-draft) | |
2894 (define-key mh-letter-mode-map "\C-c\C-w" 'mh-check-whom) | |
2895 (define-key mh-letter-mode-map "\C-c\C-i" 'mh-insert-letter) | |
2896 (define-key mh-letter-mode-map "\C-c\C-y" 'mh-yank-cur-msg) | |
2897 (define-key mh-letter-mode-map "\C-c\C-s" 'mh-insert-signature) | |
2898 (define-key mh-letter-mode-map "\C-c\C-c" 'mh-send-letter) | |
2899 | |
2900 | |
2901 ;;; Build the pick-mode keymap: | |
2902 | |
2903 (define-key mh-pick-mode-map "\C-c\C-c" 'mh-do-pick-search) | |
2904 (define-key mh-pick-mode-map "\C-c\C-f\C-b" 'mh-to-field) | |
2905 (define-key mh-pick-mode-map "\C-c\C-f\C-c" 'mh-to-field) | |
2906 (define-key mh-pick-mode-map "\C-c\C-f\C-f" 'mh-to-field) | |
2907 (define-key mh-pick-mode-map "\C-c\C-f\C-s" 'mh-to-field) | |
2908 (define-key mh-pick-mode-map "\C-c\C-f\C-t" 'mh-to-field) | |
2909 (define-key mh-pick-mode-map "\C-c\C-fb" 'mh-to-field) | |
2910 (define-key mh-pick-mode-map "\C-c\C-fc" 'mh-to-field) | |
2911 (define-key mh-pick-mode-map "\C-c\C-ff" 'mh-to-field) | |
2912 (define-key mh-pick-mode-map "\C-c\C-fs" 'mh-to-field) | |
2913 (define-key mh-pick-mode-map "\C-c\C-ft" 'mh-to-field) | |
2914 (define-key mh-pick-mode-map "\C-c\C-w" 'mh-check-whom) | |
2915 | |
2916 | |
2917 | |
2918 ;;; For Gnu Emacs. | |
2919 ;;; Local Variables: *** | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
2920 ;;; eval: (put 'mh-when 'lisp-indent-hook 1) *** |
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
2921 ;;; eval: (put 'with-mh-folder-updating 'lisp-indent-hook 1) *** |
731 | 2922 ;;; End: *** |
2923 | |
2924 (provide 'mh-e) | |
2925 | |
2926 ;;; mh-e.el ends here | |
3220
77a302be84da
Version 3.8.1 from Gildea.
Richard M. Stallman <rms@gnu.org>
parents:
2349
diff
changeset
|
2927 |