0
|
1 ;; Last edited: Fri Nov 2 10:26:24 1990
|
|
2 ;; extra widgets for rmail and rmailsum
|
|
3 ;; Copyright (C) 1990 Henry S. Thompson
|
|
4
|
|
5 ;; This file is part of GNU Emacs.
|
|
6
|
|
7 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
8 ;; but WITHOUT ANY WARRANTY. No author or distributor
|
|
9 ;; accepts responsibility to anyone for the consequences of using it
|
|
10 ;; or for whether it serves any particular purpose or works at all,
|
|
11 ;; unless he says so in writing. Refer to the GNU Emacs General Public
|
|
12 ;; License for full details.
|
|
13
|
|
14 ;; Everyone is granted permission to copy, modify and redistribute
|
|
15 ;; GNU Emacs, but only under the conditions described in the
|
|
16 ;; GNU Emacs General Public License. A copy of this license is
|
|
17 ;; supposed to have been given to you along with GNU Emacs so you
|
|
18 ;; can know your rights and responsibilities. It should be in a
|
|
19 ;; file named COPYING. Among other things, the copyright notice
|
|
20 ;; and this notice must be preserved on all copies.
|
|
21
|
|
22 (provide 'mail-extras)
|
|
23 (require 'rmail)
|
|
24 (require 'sendmail)
|
|
25
|
|
26
|
|
27 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
28 ;; mods and fixes for reading mail ;;
|
|
29 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
30
|
|
31 (defvar ht-last-file (expand-file-name "~/XMAIL")
|
|
32 "default for moving mail to")
|
|
33 (make-variable-buffer-local 'ht-last-file)
|
|
34
|
|
35 (defvar rmht-always-recompress t
|
|
36 "If non-nil, when saving into compressed babyl file,
|
|
37 always recompress and save immediately")
|
|
38
|
|
39 (defvar rmht-allow-autosave t
|
|
40 "if non-nil, leaves autosave alone for compressed babyl files,
|
|
41 otherwise turns it off")
|
|
42
|
|
43 (add-hook 'rmail-mode-hook 'rmail-mode-fun1)
|
|
44 (add-hook 'rmail-mode-hook 'rmail-mode-fun2)
|
|
45
|
|
46 ;; run the first time in to RMAIL
|
|
47 (defun rmail-mode-fun1 ()
|
|
48 "add ht's mods to RMAIL"
|
|
49 (define-key rmail-mode-map "R" 'reply-w/o-cc)
|
|
50 (define-key rmail-mode-map "M" 'rmht-output)
|
|
51 (define-key rmail-mode-map "H" 'print-buffer)
|
|
52 (define-key rmail-mode-map "W" 'edit-and-move-to-diary)
|
|
53 (define-key rmail-mode-map "D" 'update-default-diary)
|
|
54 (define-key rmail-mode-map "F" 're-post-failed-mail)
|
|
55 (define-key rmail-mode-map "B" 'ht-write-body-to-file)
|
|
56 ;; fix the doc string
|
|
57 (repl-comment 'rmail-mode
|
|
58 "Rmail Mode is used by \\[rmail] for editing Rmail files.
|
|
59 All normal editing commands are turned off.
|
|
60 Instead, these commands are available (additions from ht's mail-extras.el
|
|
61 indicated by *:
|
|
62
|
|
63 . Move point to front of this message (same as \\[beginning-of-buffer]).
|
|
64 SPC Scroll to next screen of this message.
|
|
65 DEL Scroll to previous screen of this message.
|
|
66 n Move to Next non-deleted message.
|
|
67 p Move to Previous non-deleted message.
|
|
68 M-n Move to Next message whether deleted or not.
|
|
69 M-p Move to Previous message whether deleted or not.
|
|
70 > Move to the last message in Rmail file.
|
|
71 j Jump to message specified by numeric position in file.
|
|
72 M-s Search for string and show message it is found in.
|
|
73 d Delete this message, move to next nondeleted.
|
|
74 C-d Delete this message, move to previous nondeleted.
|
|
75 u Undelete message. Tries current message, then earlier messages
|
|
76 till a deleted message is found.
|
|
77 e Expunge deleted messages.
|
|
78 s Expunge and save the file.
|
|
79 q Quit Rmail: expunge, save, then switch to another buffer.
|
|
80 C-x C-s Save without expunging.
|
|
81 g Move new mail from system spool directory or mbox into this file.
|
|
82 m Mail a message (same as \\[mail-other-window]).
|
|
83 c Continue composing outgoing message started before.
|
|
84 r Reply to this message. Like m but initializes some fields.
|
|
85 R * Like r, but reply to originator only.
|
|
86 f Forward this message to another user.
|
|
87 F * like f, but assumes message is \"failed mail\" for re-sending
|
|
88 o Output this message to an Rmail file (append it).
|
|
89 C-o Output this message to a Unix-format mail file (append it).
|
|
90 M * Output this message to a file,
|
|
91 in format determined by extension (babyl for RMAIL/msg for Unix).
|
|
92 B * Write the body of the message to a file, leaving a pointer
|
|
93 H * Print the message (same as \\<global-map>\\[print-buffer]).\\<rmail-mode-map>
|
|
94 i Input Rmail file. Run Rmail on that file.
|
|
95 a Add label to message. It will be displayed in the mode line.
|
|
96 k Kill label. Remove a label from current message.
|
|
97 C-M-n Move to Next message with specified label
|
|
98 (label defaults to last one specified).
|
|
99 Standard labels: filed, unseen, answered, forwarded, deleted.
|
|
100 Any other label is present only if you add it with `a'.
|
|
101 C-M-p Move to Previous message with specified label
|
|
102 h, C-M-h Show headers buffer, with a one line summary of each message.
|
|
103 l, C-M-l Like h only just messages with particular label(s) are summarized.
|
|
104 C-M-r Like h only just messages with particular recipient(s) are summarized.
|
|
105 t Toggle header, show Rmail header if unformatted or vice versa.
|
|
106 w Edit the current message. C-c C-c to return to Rmail.
|
|
107 W * Edit the subject field. C-c C-c to move the message to the Diary.
|
|
108 D * Update the Diary.
|
|
109
|
|
110 Messages for the diary (see also \\[describe-mode] in rmail-summary mode
|
|
111 or \\[describe-function] rmail-summary-mode) should have a subject field
|
|
112 which begins with the date and optional time of the event described therein.
|
|
113 These must be in the form
|
|
114 d m y t
|
|
115 where d is one or two digits for the day,
|
|
116 m is either the full month name or the first three letters thereof,
|
|
117 y is two digits for the year,
|
|
118 and t, if present, is 4 digits for the time,
|
|
119 thus for example
|
|
120 31 Jun 91 1530
|
|
121 ")
|
|
122 (remove-hook 'rmail-mode-hook 'rmail-mode-fun1))
|
|
123
|
|
124 (defun rmail-mode-fun2 ()
|
|
125 "always run in RMAIL mode"
|
|
126 (setq case-fold-search t))
|
|
127
|
|
128 (defun reply-w/o-cc ()
|
|
129 "Reply as r, but without sending to other recipients"
|
|
130 (interactive)
|
|
131 (rmail-reply t))
|
|
132
|
|
133 (defun rmht-output (&optional file-name gnus)
|
|
134 "Move to a file, determining format by extension (babyl/msg)"
|
|
135 (interactive)
|
|
136 (if (not file-name)
|
|
137 (setq file-name (car (get-move-file-name))))
|
|
138 (if (string-match "\\.g?[zZ]$" file-name)
|
|
139 (let ((clean-file-name (substring file-name 0 (match-beginning 0)))
|
|
140 there)
|
|
141 (if (setq there (get-file-buffer clean-file-name))
|
|
142 nil
|
|
143 (save-window-excursion (rmail clean-file-name)
|
|
144 (setq there
|
|
145 (get-file-buffer clean-file-name))))
|
|
146 (rmht-output clean-file-name gnus)
|
|
147 (if rmht-always-recompress
|
|
148 (save-excursion
|
|
149 (set-buffer there)
|
|
150 (save-buffer))
|
|
151 (if (not rmht-allow-autosave)
|
|
152 (save-excursion
|
|
153 (set-buffer there)
|
|
154 (auto-save-mode -1)))))
|
|
155 (setq file-name (expand-file-name file-name))
|
|
156 (save-excursion
|
|
157 (if (string-match "\\.babyl$" file-name)
|
|
158 (if gnus
|
|
159 (gnus-output-to-rmail file-name)
|
|
160 (rmail-output-to-rmail-file file-name 1))
|
|
161 (if (string-match "\\.msg$" file-name)
|
|
162 (if (or (get-file-buffer file-name)
|
|
163 (file-exists-p file-name)
|
|
164 (yes-or-no-p
|
|
165 (concat "\"" file-name "\" does not exist, create it? ")))
|
|
166 (rmail-output file-name 1)
|
|
167 (error "Output file does not exist"))
|
|
168 (error "not a valid mail file: %s" file-name))))
|
|
169 (setq ht-last-file file-name)
|
|
170 (if (not gnus) (ht-rmail-delete-forward))))
|
|
171
|
|
172 (defun get-move-file-name ()
|
|
173 "get a file name for moving a message to"
|
|
174 (list (read-file-name
|
|
175 (concat "Output message to file: (default "
|
|
176 (file-name-nondirectory ht-last-file)
|
|
177 ") ")
|
|
178 (file-name-directory ht-last-file)
|
|
179 ht-last-file)))
|
|
180
|
|
181 (defun re-post-failed-mail ()
|
|
182 "try to salvage the original from failed mail and prepare to resend it"
|
|
183 (interactive)
|
|
184 (rmail-forward nil)
|
|
185 (let ((top (point))
|
|
186 subjp textp)
|
|
187 (re-search-forward "^Subject: ")
|
|
188 (kill-line nil)
|
|
189 (setq subjp (point))
|
|
190 (re-search-forward "^From: ") ; the bouncer
|
|
191 (re-search-forward "^From: ") ; should be us
|
|
192 (re-search-forward "^Subject: ")
|
|
193 (kill-line nil)
|
|
194 (save-excursion (goto-char subjp)
|
|
195 (yank))
|
|
196 (beginning-of-line 3)
|
|
197 (setq textp (point))
|
|
198 (goto-char top)
|
|
199 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
|
|
200 (beginning-of-line 2)
|
|
201 (delete-region (point) textp)
|
|
202 (goto-char top)))
|
|
203
|
|
204 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
205 ;; mods and fixes for mail summaries ;;
|
|
206 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
207
|
|
208 (add-hook 'rmail-summary-mode-hook 'rmail-summary-mode-fun1)
|
|
209
|
|
210 ;; run the first time we make a summary window
|
|
211 (defun rmail-summary-mode-fun1 ()
|
|
212 "install ht's mods"
|
|
213 (define-key rmail-summary-mode-map "r" 'rms-reply-w-cc)
|
|
214 (define-key rmail-summary-mode-map "R" 'rms-reply-w/o-cc)
|
|
215 (define-key rmail-summary-mode-map "s" 'diary-save)
|
|
216 (define-key rmail-summary-mode-map "m" 'rms-move)
|
|
217 (define-key rmail-summary-mode-map "d" 'rms-delete)
|
|
218 (define-key rmail-summary-mode-map "h" 'rms-hardcopy)
|
|
219 (define-key rmail-summary-mode-map " " 'ht-rmailsum-scroll-msg-up)
|
|
220 (define-key rmail-summary-mode-map "\177" 'ht-rmailsum-scroll-msg-down)
|
|
221 ;; fix the doc string
|
|
222 (repl-comment 'rmail-summary-mode
|
|
223 "Major mode in effect in Rmail summary buffer.
|
|
224 A subset of the Rmail mode commands are supported in this mode.
|
|
225 As commands are issued in the summary buffer the corresponding
|
|
226 mail message is displayed in the rmail buffer.
|
|
227 Modifications from ht's mail-extras.el indicated with *:
|
|
228
|
|
229 n Move to next undeleted message, or arg messages.
|
|
230 p Move to previous undeleted message, or arg messages.
|
|
231 C-n Move to next, or forward arg messages.
|
|
232 C-p Move to previous, or previous arg messages.
|
|
233 j Jump to the message at the cursor location.
|
|
234 d Delete the message at the cursor location and move to next message.
|
|
235 u Undelete this or previous deleted message.
|
|
236 q Quit Rmail.
|
|
237 x Exit and kill the summary window.
|
|
238 space * If cursor is on line of current message,
|
|
239 scroll message window forward. Otherwise, jump to indicated message.
|
|
240 delete * same as space, but scrolls backward.
|
|
241 r * Same as r in rmail window. Reply to current message.
|
|
242 R * Same as R in rmail window. Reply to current message, originator only.
|
|
243 s * Update and save the rmail file, and re-summarise. Re-sorts if Diary.
|
|
244 m * Same as M in rmail window. Moves message to file.
|
|
245 h * Same as H in rmail window. Prints message on line printer.
|
|
246
|
|
247 Entering this mode calls value of hook variable rmail-summary-mode-hook.
|
|
248
|
|
249 If the file summarised is called by the name given in ht-diary-file-name,
|
|
250 which defaults to diary.babyl,
|
|
251 then the summary will be called *Diary*, sorted in date order and
|
|
252 formated in a special way.
|
|
253
|
|
254 Messages in the diary should have a subject field
|
|
255 which begins with the date and optional time of the event described therein.
|
|
256 These must be in the form
|
|
257 d m y t
|
|
258 where d is one or two digits for the day,
|
|
259 m is either the full month name or the first three letters thereof,
|
|
260 y is two digits for the year,
|
|
261 and t, if present, is 4 digits for the time,
|
|
262 thus for example
|
|
263 Subject: 31 Jun 91 1530 Hades freezing ceremony followed by champagne reception
|
|
264 ")
|
|
265 (remove-hook 'rmail-summary-mode-hook 'rmail-summary-mode-fun1))
|
|
266
|
|
267 (defun rmht-sum-reply (sender-only)
|
|
268 "reply to current message"
|
|
269 (rmail-summary-goto-msg)
|
|
270 (pop-to-buffer rmail-buffer)
|
|
271 (rmail-reply sender-only)
|
|
272 (switch-to-buffer rmail-summary-buffer)
|
|
273 (switch-to-buffer "*mail*")
|
|
274 )
|
|
275
|
|
276 (defun rms-reply-w-cc ()
|
|
277 "Do r in RMAIL - reply to everybody"
|
|
278 (interactive)
|
|
279 (rmht-sum-reply nil))
|
|
280
|
|
281 (defun rms-reply-w/o-cc ()
|
|
282 "Do R in RMAIL - reply to sender only"
|
|
283 (interactive)
|
|
284 (rmht-sum-reply t))
|
|
285
|
|
286 (defun rms-save ()
|
|
287 "expunge deleted messages, save RMAIL file and re-display headers"
|
|
288 (interactive)
|
|
289 (pop-to-buffer rmail-buffer)
|
|
290 (rmail-expunge-and-save)
|
|
291 (rmail-summary))
|
|
292
|
|
293 (defun rms-delete ()
|
|
294 "delete current and move down to next in summary buffer"
|
|
295 (interactive)
|
|
296 (rmail-summary-goto-msg)
|
|
297 (save-excursion
|
|
298 (set-buffer rmail-buffer)
|
|
299 (rmail-delete-forward nil))
|
|
300 (rms-del))
|
|
301
|
|
302 (defun rms-move ()
|
|
303 "Move to a file, mode determined by file extension (babyl/msg)"
|
|
304 (interactive)
|
|
305 (rmail-summary-goto-msg)
|
|
306 (save-excursion
|
|
307 (set-buffer rmail-buffer)
|
|
308 (rmht-output))
|
|
309 (rms-del))
|
|
310
|
|
311 (defun rms-del ()
|
|
312 "mark current summary line as deleted and move down"
|
|
313 (let ((buffer-read-only nil))
|
|
314 (skip-chars-forward " ")
|
|
315 (skip-chars-forward "[0-9]")
|
|
316 (delete-char 1)
|
|
317 (insert "D"))
|
|
318 (forward-line 1))
|
|
319
|
|
320 (defun rms-hardcopy ()
|
|
321 "hardcopy the current message"
|
|
322 (interactive)
|
|
323 (pop-to-buffer rmail-buffer)
|
|
324 (print-buffer)
|
|
325 (pop-to-buffer rmail-summary-buffer))
|
|
326
|
|
327
|
|
328 ;; fix interpretation of SPACE and DEL in summary windows to
|
|
329 ;; 1) scroll the right window regardless of how many panes are up;
|
|
330 ;; 2) go to the message associated with the current line if not already there,
|
|
331 ;; a la gnus, for instance
|
|
332
|
|
333 (defun ht-rmailsum-normalise ()
|
|
334 "if not already showing message named on current line, go to it & return t"
|
|
335 (beginning-of-line)
|
|
336 (let ((current-msg-num (cdr (assoc 'rmail-current-message
|
|
337 (buffer-local-variables
|
|
338 (or rmail-buffer
|
|
339 (error
|
|
340 "not in a summary buffer"))))))
|
|
341 (line-message-num (string-to-int
|
|
342 (buffer-substring
|
|
343 (point)
|
|
344 (min (point-max)(+ 5 (point)))))))
|
|
345 (if (= current-msg-num line-message-num)
|
|
346 nil
|
|
347 (rmail-summary-goto-msg line-message-num)
|
|
348 t)))
|
|
349
|
|
350 (defun ht-rmailsum-scroll-msg-up (&optional dist)
|
|
351 "goto other message or scroll current message forward"
|
|
352 (interactive "P")
|
|
353 (if (ht-rmailsum-normalise)
|
|
354 nil
|
|
355 (pop-to-buffer rmail-buffer)
|
|
356 (scroll-up dist)
|
|
357 (pop-to-buffer rmail-summary-buffer)))
|
|
358
|
|
359 (defun ht-rmailsum-scroll-msg-down (&optional dist)
|
|
360 "goto other message or scroll current message backward"
|
|
361 (interactive "P")
|
|
362 (if (ht-rmailsum-normalise)
|
|
363 nil
|
|
364 (pop-to-buffer rmail-buffer)
|
|
365 (scroll-down dist)
|
|
366 (pop-to-buffer rmail-summary-buffer)))
|
|
367
|
|
368 (autoload 'edit-and-move-to-diary "diary")
|
|
369 (autoload 'update-diary "diary")
|
|
370 (autoload 'diary-save "diary")
|
|
371
|
|
372 ;; unfortunately, gnus mucks about with the buffers before calling
|
|
373 ;; mail, so we have to intervene to make the about-to-mail-hook work right
|
|
374
|
|
375 (defun ht-Subject-mode-fun ()
|
|
376 "fix the map to save window state"
|
|
377 (define-key gnus-summary-mode-map "r" 'ht-Subject-mail-reply)
|
|
378 (define-key gnus-summary-mode-map "R" 'ht-Subject-mail-reply-with-original)
|
|
379 (define-key gnus-summary-mode-map "m" 'ht-Subject-mail-other-window)
|
|
380 (define-key gnus-summary-mode-map "M" 'ht-Subject-move)
|
|
381 (remove-hook 'gnus-summary-mode-hook 'ht-Subject-mode-fun))
|
|
382
|
|
383 (add-hook 'gnus-summary-mode-hook 'ht-Subject-mode-fun)
|
|
384
|
|
385 (defun ht-Subject-mail-reply (yank)
|
|
386 "Runs about-to-mail-hook, then calls gnus-summary-mail-reply"
|
|
387 (interactive "P")
|
|
388 (require 'sendmail)
|
|
389 (run-hooks 'about-to-mail-hook)
|
|
390 (let (about-to-mail-hook)
|
|
391 (gnus-summary-reply yank)))
|
|
392
|
|
393 (defun ht-Subject-mail-reply-with-original ()
|
|
394 "Runs about-to-mail-hook, then calls gnus-summary-mail-reply-with-original"
|
|
395 (interactive)
|
|
396 (require 'sendmail)
|
|
397 (run-hooks 'about-to-mail-hook)
|
|
398 (let (about-to-mail-hook)
|
|
399 (gnus-summary-reply-with-original)))
|
|
400
|
|
401 (defun ht-Subject-mail-other-window ()
|
|
402 "Runs about-to-mail-hook, then calls gnus-summary-mail-other-window"
|
|
403 (interactive)
|
|
404 (require 'sendmail)
|
|
405 (run-hooks 'about-to-mail-hook)
|
|
406 (let (about-to-mail-hook)
|
|
407 (gnus-summary-mail-other-window)))
|
|
408
|
|
409 (defun ht-Subject-move ()
|
|
410 "Move article to a file, mode determined by file extension (babyl/msg)"
|
|
411 (interactive)
|
|
412 (gnus-summary-select-article)
|
|
413 (save-excursion
|
|
414 (set-buffer gnus-article-buffer)
|
|
415 (rmht-output nil t)))
|
|
416
|
|
417
|
|
418 (defun ht-write-body-to-file (file)
|
|
419 "Write the body of the message to a file and replace it with a pointer"
|
|
420 (interactive "FFile to save in: ")
|
|
421 (goto-char (point-min))
|
|
422 (or (search-forward "\n\n" nil t)
|
|
423 (error "Can't find text"))
|
|
424 (write-region (point)(point-max) file)
|
|
425 (rmail-edit-current-message)
|
|
426 (delete-region (point)(point-max))
|
|
427 (insert "\n>> " file "\n")
|
|
428 (rmail-cease-edit)
|
|
429 (rmht-output))
|