1 ;;; mh-e.el --- GNU Emacs interface to the MH mail system
3 ;;; Copyright 1985,86,87,88,90,92,93,94 Free Software Foundation, Inc.
5 (defconst mh-e-time-stamp "Time-stamp: <94/04/13 11:30:48 gildea>")
6 (defconst mh-e-version "4.1"
7 "Version numbers of this version of mh-e.")
9 ;; Maintainer: Stephen Gildea <gildea@lcs.mit.edu>
13 ;; mh-e is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
18 ;; mh-e is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with mh-e; see the file COPYING. If not, write to
25 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
30 ;;; M-x mh-rmail to read mail. Type C-h m there for a list of commands.
31 ;;; C-u M-x mh-rmail to visit any folder.
32 ;;; M-x mh-smail to send mail. From within the mail reader, "m" works, too.
33 ;;; Your .emacs might benefit from these bindings:
34 ;;; (global-set-key "\C-cr" 'mh-rmail)
35 ;;; (global-set-key "\C-xm" 'mh-smail)
36 ;;; (global-set-key "\C-x4m" 'mh-smail-other-window)
38 ;;; MH (Message Handler) is a powerful mail reader. The MH newsgroup
39 ;;; is comp.mail.mh; the mailing list is mh-users@ics.uci.edu (send to
40 ;;; mh-users-request to be added). See the monthly Frequently Asked
41 ;;; Questions posting there for information on getting MH.
43 ;;; mh-e works with Emacs 18 or 19, and MH 5 or 6.
45 ;;; NB. MH must have been compiled with the MHE compiler flag or several
46 ;;; features necessary mh-e will be missing from MH commands, specifically
47 ;;; the -build switch to repl and forw.
51 ;;; Original version for Gosling emacs by Brian Reid, Stanford, 1982.
52 ;;; Modified by James Larus, BBN, July 1984 and UCB, 1984 & 1985.
53 ;;; Rewritten for GNU Emacs, James Larus 1985. larus@ginger.berkeley.edu
54 ;;; Modified by Stephen Gildea 1988. gildea@lcs.mit.edu
55 (defconst mh-e-RCS-id "$Header: /home/fsf/rms/e19/lisp/RCS/mh-e.el,v 1.2 1994/04/13 20:42:10 rms Exp rms $")
63 ;;; Site customization (see also mh-utils.el):
65 (defvar mh-redist-full-contents nil
66 "Non-nil if the `dist' command needs whole letter for redistribution.
67 This is the case only when `send' is compiled with the BERK option.
68 If MH will not allow you to redist a previously redist'd msg, set to nil.")
72 (defvar mh-folder-mode-hook nil
73 "Invoked in MH-Folder mode on a new folder.")
75 (defvar mh-inc-folder-hook nil
76 "Invoked by \\<mh-folder-mode-map>`\\[mh-inc-folder]' after incorporating mail into a folder.")
78 (defvar mh-show-hook nil
79 "Invoked after \\<mh-folder-mode-map>`\\[mh-show]' shows a message.")
81 (defvar mh-show-mode-hook nil
82 "Invoked in MH-Show mode on each message.")
84 (defvar mh-delete-msg-hook nil
85 "Invoked after marking each message for deletion.")
87 (defvar mh-refile-msg-hook nil
88 "Invoked after marking each message for refiling.")
90 (defvar mh-before-quit-hook nil
91 "Invoked by \\<mh-folder-mode-map>`\\[mh-quit]' before quitting mh-e. See also mh-quit-hook.")
93 (defvar mh-quit-hook nil
94 "Invoked after \\<mh-folder-mode-map>`\\[mh-quit]' quits mh-e. See also mh-before-quit-hook.")
98 ;;; Personal preferences:
100 (defvar mh-lpr-command-format "lpr -p -J '%s'"
101 "*Format for Unix command that prints a message.
102 The string should be a Unix command line, with the string '%s' where
103 the job's name (folder and message number) should appear. The formatted
104 message text is piped to this command when you type \\<mh-folder-mode-map>`\\[mh-print-msg]'.")
106 (defvar mh-scan-prog "scan"
107 "*Program to run to generate one-line-per-message listing of a folder.
108 Normally \"scan\" or a file name linked to scan. This file is searched
109 for relative to the mh-progs directory unless it is an absolute pathname.
110 Automatically becomes buffer-local when set in any fashion.")
111 (make-variable-buffer-local 'mh-scan-prog)
113 (defvar mh-inc-prog "inc"
114 "*Program to run to incorporate new mail into a folder.
115 Normally \"inc\". This file is searched for relative to
116 the mh-progs directory unless it is an absolute pathname.")
118 (defvar mh-print-background nil
119 "*Print messages in the background if non-nil.
120 WARNING: do not delete the messages until printing is finished;
121 otherwise, your output may be truncated.")
123 (defvar mh-recenter-summary-p nil
124 "*Recenter summary window when the show window is toggled off if non-nil.")
126 (defvar mh-ins-buf-prefix "> "
127 "*String to put before each non-blank line of a yanked or inserted message.
128 \\<mh-letter-mode-map>Used when the message is inserted into an outgoing letter
129 by \\[mh-insert-letter] or \\[mh-yank-cur-msg].")
131 (defvar mh-do-not-confirm nil
132 "*Non-nil means do not prompt for confirmation before some mh-e commands.
133 Affects non-recoverable commands such as mh-kill-folder and mh-undo-folder.")
135 (defvar mh-store-default-directory nil
136 "*Last directory used by \\[mh-store-msg]; default for next store.
137 A directory name string, or nil to use current directory.")
139 ;;; Parameterize mh-e to work with different scan formats. The defaults work
140 ;;; with the standard MH scan listings, in which the first 4 characters on
141 ;;; the line are the message number, followed by two places for notations.
143 (defvar mh-good-msg-regexp "^....[^D^]"
144 "Regexp specifiying the scan lines that are 'good' messages.")
146 (defvar mh-deleted-msg-regexp "^....D"
147 "Regexp matching scan lines of deleted messages.")
149 (defvar mh-refiled-msg-regexp "^....\\^"
150 "Regexp matching scan lines of refiled messages.")
152 (defvar mh-valid-scan-line "^ *[0-9]"
153 "Regexp matching scan lines for messages (not error messages).")
155 (defvar mh-flagged-scan-msg-regexp "^....\\D\\|^....\\^\\|^....\\+\\|^.....%"
156 "Regexp matching flagged scan lines.
157 Matches lines marked as deleted, refiled, in a sequence, or the cur message.")
159 (defvar mh-cur-scan-msg-regexp "^....\\+"
160 "Regexp matching scan line for the cur message.")
162 (defvar mh-show-buffer-mode-line-buffer-id "{show-%s} %d"
163 "Format string to produce `mode-line-buffer-identification' for show buffers.
164 First argument is folder name. Second is message number.")
166 (defvar mh-partial-folder-mode-line-annotation "select"
167 "Annotation when displaying part of a folder.
168 The string is displayed after the folder's name. NIL for no annotation.")
171 ;;; Internal variables:
173 (defvar mh-last-destination nil
174 "Destination of last refile or write command.")
176 (defvar mh-folder-mode-map (make-keymap)
177 "Keymap for MH folders.")
179 (defvar mh-next-seq-num nil
180 "Index of free sequence id.")
182 (defvar mh-delete-list nil
183 "List of msg numbers to delete.")
185 (defvar mh-refile-list nil
186 "List of folder names in mh-seq-list.")
188 (defvar mh-next-direction 'forward
189 "Direction to move to next message.")
191 (defvar mh-narrowed-to-seq nil
192 "Sequence display is narrowed to.")
194 (defvar mh-first-msg-num nil
195 "Number of first msg in buffer.")
197 (defvar mh-last-msg-num nil
198 "Number of last msg in buffer.")
201 ;;; Macros and generic functions:
203 (defun mh-mapc (func list)
205 (funcall func (car list))
206 (setq list (cdr list))))
213 (defun mh-rmail (&optional arg)
214 "Inc(orporate) new mail with MH, or, with arg, scan an MH mail folder.
215 This function is an entry point to mh-e, the Emacs front end
216 to the MH mail system."
220 (call-interactively 'mh-visit-folder)
224 ;;; mh-smail and mh-smail-other-window have been moved to the new file
225 ;;; mh-comp.el, but Emacs 18 still looks for them here, so provide a
226 ;;; definition here, too, for a while.
229 "Compose and send mail with the MH mail system.
230 This function is an entry point to mh-e, the Emacs front end
231 to the MH mail system."
235 (call-interactively 'mh-send))
238 (defun mh-smail-other-window ()
239 "Compose and send mail in other window with the MH mail system.
240 This function is an entry point to mh-e, the Emacs front end
241 to the MH mail system."
245 (call-interactively 'mh-send-other-window))
249 ;;; User executable mh-e commands:
252 (defun mh-delete-msg (msg-or-seq)
253 "Mark the specified MESSAGE(s) for subsequent deletion and move to the next.
254 Default is the displayed message. If optional prefix argument is
255 given then prompt for the message sequence."
256 (interactive (list (if current-prefix-arg
257 (mh-read-seq-default "Delete" t)
258 (mh-get-msg-num t))))
259 (mh-delete-msg-no-motion msg-or-seq)
263 (defun mh-delete-msg-no-motion (msg-or-seq)
264 "Mark the specified MESSAGE(s) for subsequent deletion.
265 Default is the displayed message. If optional prefix argument is
266 provided, then prompt for the message sequence."
267 (interactive (list (if current-prefix-arg
268 (mh-read-seq-default "Delete" t)
269 (mh-get-msg-num t))))
270 (if (numberp msg-or-seq)
271 (mh-delete-a-msg msg-or-seq)
272 (mh-map-to-seq-msgs 'mh-delete-a-msg msg-or-seq)))
275 (defun mh-execute-commands ()
276 "Process outstanding delete and refile requests."
278 (if mh-narrowed-to-seq (mh-widen))
279 (mh-process-commands mh-current-folder)
281 (mh-goto-cur-msg) ; after mh-set-scan-mode for efficiency
282 (mh-make-folder-mode-line)
283 t) ; return t for local-write-file-hooks
286 (defun mh-first-msg ()
287 "Move to the first message."
289 (goto-char (point-min)))
292 (defun mh-header-display ()
293 "Show the current message with all its headers.
294 Displays headers that might have been suppressed by setting the
295 variables `mh-clean-message-header' or `mhl-formfile', or by the fallback
296 behavior of scrolling uninteresting headers off the top of the window.
297 Type \"\\[mh-show]\" to show the message normally again."
299 (and (not mh-showing-with-headers)
300 (or mhl-formfile mh-clean-message-header)
301 (mh-invalidate-show-buffer))
302 (let ((mhl-formfile nil)
303 (mh-clean-message-header nil))
305 (mh-in-show-buffer (mh-show-buffer)
306 (goto-char (point-min))
308 (setq mh-showing-with-headers t)))
311 (defun mh-inc-folder (&optional maildrop-name)
312 "Inc(orporate)s new mail into +inbox.
313 Optional prefix argument specifies an alternate maildrop from the default.
314 If this is given, incorporates mail into the current folder, rather
315 than +inbox. Runs `mh-inc-folder-hook' after incorporating new mail.
316 Do not call this function from outside mh-e; use \\[mh-rmail] instead."
317 (interactive (list (if current-prefix-arg
319 (read-file-name "inc mail from file: "
321 (let ((config (current-window-configuration)))
322 (if (not maildrop-name)
323 (cond ((not (get-buffer "+inbox"))
324 (mh-make-folder "+inbox")
325 (setq mh-previous-window-config config))
326 ((not (eq (current-buffer) (get-buffer "+inbox")))
327 (switch-to-buffer "+inbox")
328 (setq mh-previous-window-config config)))))
329 (mh-get-new-mail maildrop-name)
330 (run-hooks 'mh-inc-folder-hook))
333 (defun mh-last-msg ()
334 "Move to the last message."
336 (goto-char (point-max))
337 (while (and (not (bobp)) (looking-at "^$"))
341 (defun mh-next-undeleted-msg (&optional arg)
342 "Move to next undeleted message in window."
344 (forward-line (prefix-numeric-value arg))
345 (setq mh-next-direction 'forward)
346 (cond ((re-search-forward mh-good-msg-regexp nil 0 arg)
351 (if (get-buffer mh-show-buffer)
352 (delete-windows-on mh-show-buffer)))))
355 (defun mh-refile-msg (msg-or-seq dest)
356 "Refile MESSAGE(s) (default: displayed message) in FOLDER.
357 If optional prefix argument provided, then prompt for message sequence."
359 (list (if current-prefix-arg
360 (mh-read-seq-default "Refile" t)
363 (mh-prompt-for-folder
365 (or (and mh-msg-folder-hook
366 (let ((file-name (mh-msg-filename (mh-get-msg-num t))))
368 (set-buffer (get-buffer-create " *mh-temp*"))
370 (insert-file-contents file-name)
371 (let ((buffer-file-name file-name))
372 (funcall mh-msg-folder-hook)))))
373 (and (eq 'refile (car mh-last-destination))
374 (symbol-name (cdr mh-last-destination)))
377 (setq mh-last-destination (cons 'refile dest))
378 (if (numberp msg-or-seq)
379 (mh-refile-a-msg msg-or-seq dest)
380 (mh-map-to-seq-msgs 'mh-refile-a-msg msg-or-seq dest))
384 (defun mh-refile-or-write-again (msg)
385 "Re-execute the last refile or write command on the given MESSAGE.
386 Default is the displayed message. Use the same folder or file as the
387 previous refile or write command."
388 (interactive (list (mh-get-msg-num t)))
389 (if (null mh-last-destination)
390 (error "No previous refile or write"))
391 (cond ((eq (car mh-last-destination) 'refile)
392 (mh-refile-a-msg msg (cdr mh-last-destination))
393 (message "Destination folder: %s" (cdr mh-last-destination)))
395 (apply 'mh-write-msg-to-file msg (cdr mh-last-destination))
396 (message "Destination: %s" (cdr mh-last-destination))))
402 Start by running mh-before-quit-hook. Restore the previous window
403 configuration, if one exists. Finish by running mh-quit-hook."
405 (run-hooks 'mh-before-quit-hook)
407 (mh-invalidate-show-buffer)
408 (bury-buffer (current-buffer))
409 (if (get-buffer mh-show-buffer)
410 (bury-buffer mh-show-buffer))
411 (if mh-previous-window-config
412 (set-window-configuration mh-previous-window-config))
413 (run-hooks 'mh-quit-hook))
415 (defun mh-page-msg (&optional arg)
416 "Page the displayed message forwards.
417 Scrolls ARG lines or a full screen if no argument is supplied."
419 (scroll-other-window arg))
422 (defun mh-previous-page (&optional arg)
423 "Page the displayed message backwards.
424 Scrolls ARG lines or a full screen if no argument is supplied."
426 (mh-in-show-buffer (mh-show-buffer)
430 (defun mh-previous-undeleted-msg (&optional arg)
431 "Move to previous undeleted message in window."
433 (setq mh-next-direction 'backward)
435 (cond ((re-search-backward mh-good-msg-regexp nil 0 arg)
438 (if (get-buffer mh-show-buffer)
439 (delete-windows-on mh-show-buffer)))))
442 (defun mh-rescan-folder (&optional range)
443 "Rescan a folder after optionally processing the outstanding commands.
444 If optional prefix argument is provided, prompt for the range of
445 messages to display. Otherwise show the entire folder."
446 (interactive (list (if current-prefix-arg
447 (mh-read-msg-range "Range to scan [all]? ")
449 (setq mh-next-direction 'forward)
450 (mh-scan-folder mh-current-folder (or range "all")))
453 (defun mh-write-msg-to-file (msg file no-headers)
454 "Append MESSAGE to the end of a FILE.
455 If NO-HEADERS (prefix argument) is provided, write only the message body.
456 Otherwise send the entire message including the headers."
458 (list (mh-get-msg-num t)
459 (let ((default-dir (if (eq 'write (car mh-last-destination))
460 (file-name-directory (car (cdr mh-last-destination)))
462 (read-file-name "Save message in file: " default-dir
463 (expand-file-name "mail.out" default-dir)))
465 (let ((file-name (mh-msg-filename msg))
466 (output-file (mh-expand-file-name file)))
467 (setq mh-last-destination (list 'write file no-headers))
469 (set-buffer (get-buffer-create " *mh-temp*"))
471 (insert-file-contents file-name)
472 (goto-char (point-min))
473 (if no-headers (search-forward "\n\n"))
474 (append-to-file (point) (point-max) output-file))))
477 (defun mh-toggle-showing ()
478 "Toggle the scanning mode/showing mode of displaying messages."
485 (defun mh-undo (msg-or-seq)
486 "Undo the deletion or refile of the specified MESSAGE(s).
487 Default is the displayed message. If optional prefix argument is
488 provided, then prompt for the message sequence."
489 (interactive (list (if current-prefix-arg
490 (mh-read-seq-default "Undo" t)
491 (mh-get-msg-num t))))
492 (cond ((numberp msg-or-seq)
493 (let ((original-position (point)))
495 (while (not (or (looking-at mh-deleted-msg-regexp)
496 (looking-at mh-refiled-msg-regexp)
497 (and (eq mh-next-direction 'forward) (bobp))
498 (and (eq mh-next-direction 'backward)
499 (save-excursion (forward-line) (eobp)))))
500 (forward-line (if (eq mh-next-direction 'forward) -1 1)))
501 (if (or (looking-at mh-deleted-msg-regexp)
502 (looking-at mh-refiled-msg-regexp))
504 (mh-undo-msg (mh-get-msg-num t))
506 (goto-char original-position)
507 (error "Nothing to undo"))))
509 (mh-mapc (function mh-undo-msg) (mh-seq-to-msgs msg-or-seq))))
510 ;; update the mh-refile-list so mh-outstanding-commands-p will work
513 (if (not (mh-seq-to-msgs elt))
514 (setq mh-refile-list (delq elt mh-refile-list)))))
516 (if (not (mh-outstanding-commands-p))
517 (mh-set-folder-modified-p nil)))
521 "Display version information about mh-e and MH."
524 (set-buffer (get-buffer-create " *mh-temp*"))
526 (insert " mh-e info:\n\nversion: " mh-e-version "\n" mh-e-time-stamp
527 "\nEmacs: " emacs-version " on " (symbol-name system-type) " ")
529 (call-process "uname" nil t nil "-a")
531 (insert "\n\n MH info:\n\n" (expand-file-name "inc" mh-progs) ":\n")
532 (let ((help-start (point)))
533 (condition-case err-data
534 (mh-exec-cmd-output "inc" nil "-help")
535 (file-error (insert (mapconcat 'concat (cdr err-data) ": "))))
536 (goto-char help-start)
537 (search-forward "version: " nil t)
539 (delete-region help-start (point))
540 (goto-char (point-min)))
541 (display-buffer " *mh-temp*"))
544 (defun mh-visit-folder (folder &optional range)
545 "Visits FOLDER and displays RANGE of messages.
546 Assumes mh-e has already been initialized.
547 Do not call this function from outside mh-e; see \\[mh-rmail] instead."
548 (interactive (list (mh-prompt-for-folder "Visit" "+inbox" t)
549 (mh-read-msg-range "Range [all]? ")))
550 (let ((config (current-window-configuration)))
551 (mh-scan-folder folder (or range "all"))
552 (setq mh-previous-window-config config))
556 (defun mh-compat-quit ()
557 "\"b\" reserved for future use as mh-burst-digest; will assume you want \"\\[mh-quit]\" ..."
558 ;; This is a temporary compatibility function
560 (message "%s" (documentation this-command))
562 (call-interactively 'mh-quit))
566 ;;; Support routines.
568 (defun mh-delete-a-msg (msg)
569 ;; Delete the MESSAGE.
571 (mh-goto-msg msg nil t)
572 (if (looking-at mh-refiled-msg-regexp)
573 (error "Message %d is refiled. Undo refile before deleting." msg))
574 (if (looking-at mh-deleted-msg-regexp)
576 (mh-set-folder-modified-p t)
577 (setq mh-delete-list (cons msg mh-delete-list))
578 (mh-add-msgs-to-seq msg 'deleted t)
579 (mh-notate msg ?D mh-cmd-note)
580 (run-hooks 'mh-delete-msg-hook))))
582 (defun mh-refile-a-msg (msg destination)
583 ;; Refile MESSAGE in FOLDER. FOLDER is a symbol, not a string.
585 (mh-goto-msg msg nil t)
586 (cond ((looking-at mh-deleted-msg-regexp)
587 (error "Message %d is deleted. Undo delete before moving." msg))
588 ((looking-at mh-refiled-msg-regexp)
590 (format "Message %d already refiled. Copy to %s as well? "
592 (mh-exec-cmd "refile" (mh-get-msg-num t) "-link"
593 "-src" mh-current-folder
594 (symbol-name destination))
595 (message "Message not copied.")))
597 (mh-set-folder-modified-p t)
598 (if (not (memq destination mh-refile-list))
599 (setq mh-refile-list (cons destination mh-refile-list)))
600 (if (not (memq msg (mh-seq-to-msgs destination)))
601 (mh-add-msgs-to-seq msg destination t))
602 (mh-notate msg ?^ mh-cmd-note)
603 (run-hooks 'mh-refile-msg-hook)))))
606 (defun mh-next-msg ()
607 ;; Move backward or forward to the next undeleted message in the buffer.
608 (if (eq mh-next-direction 'forward)
609 (mh-next-undeleted-msg 1)
610 (mh-previous-undeleted-msg 1)))
613 (defun mh-set-scan-mode ()
614 ;; Display the scan listing buffer, but do not show a message.
615 (if (get-buffer mh-show-buffer)
616 (delete-windows-on mh-show-buffer))
617 (setq mh-showing nil)
618 (set-buffer-modified-p (buffer-modified-p)) ;force mode line update
619 (if mh-recenter-summary-p
623 (defun mh-undo-msg (msg)
624 ;; Undo the deletion or refile of one MESSAGE.
625 (cond ((memq msg mh-delete-list)
626 (setq mh-delete-list (delq msg mh-delete-list))
627 (mh-delete-msg-from-seq msg 'deleted t))
629 (mh-mapc (function (lambda (dest)
630 (mh-delete-msg-from-seq msg dest t)))
632 (mh-notate msg ? mh-cmd-note))
637 ;;; The folder data abstraction.
639 (defun mh-make-folder (name)
640 ;; Create and initialize a new mail folder called NAME and make it the
642 (switch-to-buffer name)
643 (setq buffer-read-only nil)
645 (setq buffer-read-only t)
647 (mh-set-folder-modified-p nil)
648 (setq buffer-file-name mh-folder-filename))
651 ;;; Ensure new buffers won't get this mode if default-major-mode is nil.
652 (put 'mh-folder-mode 'mode-class 'special)
654 (defun mh-folder-mode ()
655 "Major mh-e mode for \"editing\" an MH folder scan listing.\\<mh-folder-mode-map>
656 You can show the message the cursor is pointing to, and step through the
657 messages. Messages can be marked for deletion or refiling into another
658 folder; these commands are executed all at once with a separate command.
660 A prefix argument (\\[universal-argument]) to delete, refile, list, or undo
661 applies the action to a message sequence.
663 Here is a list of the standard keys for mh-e commands, grouped by function.
664 This list is purposefully not customized; mh-e has a long history, and many
665 alternate key bindings as a result. This list is to encourage users to use
666 standard keys so the other keys can perhaps someday be put to new uses.
668 t toggle show or scan-only mode
669 . show message, or back to top if already showing
676 j jump to message by number
679 o, ^ mark for output (refile) to another folder
680 ? show folder of pending refile
681 u undo delete or refile marking
683 x execute marked deletes and refiles
684 i incorporate new mail
693 M-r rescan this folder
695 Here are all the commands with their current binding, listed in key order:
696 \\{mh-folder-mode-map}
698 Variables controlling mh-e operation are (defaults in parentheses):
700 mh-recursive-folders (nil)
701 Non-nil means commands which operate on folders do so recursively.
703 mh-bury-show-buffer (t)
704 Non-nil means that the buffer used to display message is buried.
705 It will never be offered as the default other buffer.
707 mh-clean-message-header (nil)
708 Non-nil means remove header lines matching the regular expression
709 specified in mh-invisible-headers from messages.
711 mh-visible-headers (nil)
712 If non-nil, it contains a regexp specifying the headers that are shown in
713 a message if mh-clean-message-header is non-nil. Setting this variable
714 overrides mh-invisible-headers.
716 mh-do-not-confirm (nil)
717 Non-nil means do not prompt for confirmation before executing some
718 non-recoverable commands such as mh-kill-folder and mh-undo-folder.
721 Name of format file to be used by mhl to show messages.
722 A value of T means use the default format file.
723 Nil means don't use mhl to format messages.
725 mh-lpr-command-format (\"lpr -p -J '%s'\")
726 Format for command used to print a message on a system printer.
728 mh-scan-prog (\"scan\")
729 Program to run to generate one-line-per-message listing of a folder.
730 Normally \"scan\" or a file name linked to scan. This file is searched
731 for relative to the mh-progs directory unless it is an absolute pathname.
732 Automatically becomes buffer-local when set in any fashion.
734 mh-print-background (nil)
735 Print messages in the background if non-nil.
736 WARNING: do not delete the messages until printing is finished;
737 otherwise, your output may be truncated.
739 mh-recenter-summary-p (nil)
740 If non-nil, then the scan listing is recentered when the window displaying
741 a messages is toggled off.
743 mh-summary-height (4)
744 Number of lines in the summary window including the mode line.
746 mh-ins-buf-prefix (\"> \")
747 String to insert before each non-blank line of a message as it is
748 inserted in a draft letter.
750 The value of mh-folder-mode-hook is called when a new folder is set up."
752 (kill-all-local-variables)
753 (use-local-map mh-folder-mode-map)
754 (setq major-mode 'mh-folder-mode)
755 (mh-set-mode-name "MH-Folder")
757 'mh-current-folder (buffer-name) ; Name of folder, a string
758 'mh-show-buffer (format "show-%s" (buffer-name)) ; Buffer that displays msgs
759 'mh-folder-filename ; e.g. "/usr/foobar/Mail/inbox/"
760 (file-name-as-directory (mh-expand-file-name (buffer-name)))
761 'mh-showing nil ; Show message also?
762 'mh-next-seq-num 0 ; Index of free sequence id
763 'mh-delete-list nil ; List of msgs nums to delete
764 'mh-refile-list nil ; List of folder names in mh-seq-list
765 'mh-seq-list nil ; Alist of (seq . msgs) nums
766 'mh-seen-list nil ; List of displayed messages
767 'mh-next-direction 'forward ; Direction to move to next message
768 'mh-narrowed-to-seq nil ; Sequence display is narrowed to
769 'mh-first-msg-num nil ; Number of first msg in buffer
770 'mh-last-msg-num nil ; Number of last msg in buffer
771 'mh-previous-window-config nil) ; Previous window configuration
772 (setq truncate-lines t)
774 (setq buffer-offer-save t)
775 (make-local-variable 'local-write-file-hooks)
776 (setq local-write-file-hooks '(mh-execute-commands))
777 (make-local-variable 'revert-buffer-function)
778 (setq revert-buffer-function 'mh-undo-folder)
779 (or (assq 'mh-showing minor-mode-alist)
780 (setq minor-mode-alist
781 (cons '(mh-showing " Show") minor-mode-alist)))
782 (run-hooks 'mh-folder-mode-hook))
785 (defun make-local-vars (&rest pairs)
786 ;; Take VARIABLE-VALUE pairs and makes local variables initialized to the
789 (make-variable-buffer-local (car pairs))
790 (set (car pairs) (car (cdr pairs)))
791 (setq pairs (cdr (cdr pairs)))))
794 (defun mh-scan-folder (folder range)
795 ;; Scan the FOLDER over the RANGE. Return in the folder's buffer.
796 (cond ((null (get-buffer folder))
797 (mh-make-folder folder))
799 (mh-process-or-undo-commands folder)
800 (switch-to-buffer folder)))
801 (mh-regenerate-headers range)
802 (cond ((zerop (buffer-size))
803 (if (equal range "all")
804 (message "Folder %s is empty" folder)
805 (message "No messages in %s, range %s" folder range))
810 (defun mh-regenerate-headers (range)
811 ;; Replace buffer with scan of its contents over range RANGE.
812 (let ((folder mh-current-folder))
813 (message "Scanning %s..." folder)
814 (with-mh-folder-updating (nil)
816 (mh-exec-cmd-output mh-scan-prog nil
817 "-noclear" "-noheader"
818 "-width" (window-width)
820 (goto-char (point-min))
821 (cond ((looking-at "scan: no messages in")
822 (keep-lines mh-valid-scan-line)) ; Flush random scan lines
823 ((looking-at "scan: ")) ; Keep error messages
825 (keep-lines mh-valid-scan-line))) ; Flush random scan lines
826 (mh-delete-seq-locally 'cur) ; To pick up new one
827 (setq mh-seq-list (mh-read-folder-sequences folder nil))
828 (mh-notate-user-sequences)
829 (mh-make-folder-mode-line (if (equal range "all")
831 mh-partial-folder-mode-line-annotation)))
832 (message "Scanning %s...done" folder)))
835 (defun mh-get-new-mail (maildrop-name)
836 ;; Read new mail from a maildrop into the current buffer.
837 ;; Return in the current buffer.
838 (let ((point-before-inc (point))
839 (folder mh-current-folder)
841 (with-mh-folder-updating (t)
842 (message (if maildrop-name
843 (format "inc %s -file %s..." folder maildrop-name)
844 (format "inc %s..." folder)))
845 (setq mh-next-direction 'forward)
846 (goto-char (point-max))
847 (let ((start-of-inc (point)))
849 (mh-exec-cmd-output mh-inc-prog nil folder
850 "-file" (expand-file-name maildrop-name)
851 "-width" (window-width)
853 (mh-exec-cmd-output "inc" nil
854 "-width" (window-width)))
857 (format "inc %s -file %s...done" folder maildrop-name)
858 (format "inc %s...done" folder)))
859 (goto-char start-of-inc)
860 (cond ((looking-at "inc: no mail")
861 (message "No new mail%s%s" (if maildrop-name " in " "")
862 (if maildrop-name maildrop-name "")))
863 ((re-search-forward "^inc:" nil t) ; Error messages
866 ;; remove old cur notation (cf mh-goto-cur-msg code)
867 (let ((cur-msg (car (mh-seq-to-msgs 'cur))))
870 (mh-goto-msg cur-msg t nil)
871 (looking-at mh-cur-scan-msg-regexp)
872 (mh-notate nil ? mh-cmd-note))))
873 (setq new-mail-p t)))
874 (keep-lines mh-valid-scan-line) ; Flush random scan lines
875 (mh-delete-seq-locally 'cur) ; To pick up new one
876 (setq mh-seq-list (mh-read-folder-sequences folder t))
877 (mh-notate-user-sequences)
881 (mh-make-folder-mode-line))
882 (goto-char point-before-inc))))))
885 (defun mh-make-folder-mode-line (&optional annotation)
886 ;; Set the fields of the mode line for a folder buffer.
887 ;; The optional ANNOTATION string is displayed after the folder's name.
890 (setq mh-first-msg-num (mh-get-msg-num nil))
892 (setq mh-last-msg-num (mh-get-msg-num nil))
893 (let ((lines (count-lines (point-min) (point-max))))
894 (setq mode-line-buffer-identification
895 (list (format "{%%b%s} %d msg%s"
896 (if annotation (format "/%s" annotation) "")
901 (format "s (%d-%d)" mh-first-msg-num
903 (format " (%d)" mh-first-msg-num)))))))))
906 (defun mh-unmark-all-headers (remove-all-flags)
907 ;; Remove all '+' flags from the headers, and if called with a non-nil
908 ;; argument, remove all 'D', '^' and '%' flags too.
909 ;; Optimized for speed (i.e., no regular expressions).
911 (let ((case-fold-search nil)
912 (last-line (- (point-max) mh-cmd-note))
915 (while (<= (point) last-line)
916 (forward-char mh-cmd-note)
917 (setq char (following-char))
918 (if (or (and remove-all-flags
929 (defun mh-goto-cur-msg ()
930 ;; Position the cursor at the current message.
931 (let ((cur-msg (car (mh-seq-to-msgs 'cur))))
933 (mh-goto-msg cur-msg t nil))
934 (mh-notate nil ?+ mh-cmd-note)
936 (mh-maybe-show cur-msg))
939 (message "No current message")))))
942 (defun mh-process-or-undo-commands (folder)
943 ;; If FOLDER has outstanding commands, then either process or discard them.
944 ;; Called by functions like mh-sort-folder, so also invalidate show buffer.
946 (if (mh-outstanding-commands-p)
947 (if (or mh-do-not-confirm
949 "Process outstanding deletes and refiles (or lose them)? "))
950 (mh-process-commands folder)
953 (mh-invalidate-show-buffer))
956 (defun mh-process-commands (folder)
957 ;; Process outstanding commands for the folder FOLDER.
958 (message "Processing deletes and refiles for %s..." folder)
960 (with-mh-folder-updating (nil)
961 ;; Update the unseen sequence if it exists
964 ;; Then refile messages
968 (let ((msgs (mh-seq-to-msgs dest)))
970 (apply 'mh-exec-cmd "refile"
971 "-src" folder (symbol-name dest) msgs)
972 (mh-delete-scan-msgs msgs))))))
974 (setq mh-refile-list nil)
976 ;; Now delete messages
977 (cond (mh-delete-list
978 (apply 'mh-exec-cmd "rmm" folder mh-delete-list)
979 (mh-delete-scan-msgs mh-delete-list)
980 (setq mh-delete-list nil)))
982 ;; Don't need to remove sequences since delete and refile do so.
985 (if (> (buffer-size) 0)
986 (mh-define-sequence 'cur (or (mh-get-msg-num nil) "last")))
988 (and (buffer-file-name (get-buffer mh-show-buffer))
989 (not (file-exists-p (buffer-file-name (get-buffer mh-show-buffer))))
990 ;; If "inc" were to put a new msg in this file,
991 ;; we would not notice, so mark it invalid now.
992 (mh-invalidate-show-buffer))
994 (setq mh-seq-list (mh-read-folder-sequences mh-current-folder nil))
995 (mh-unmark-all-headers t)
996 (mh-notate-user-sequences)
997 (message "Processing deletes and refiles for %s...done" folder)))
1000 (defun mh-update-unseen ()
1001 ;; Push updates to the Unseen sequence out to MH.
1004 (if (mh-seq-to-msgs mh-unseen-seq)
1005 (mh-undefine-sequence mh-unseen-seq mh-seen-list))
1006 (setq mh-seen-list nil))))
1009 (defun mh-delete-scan-msgs (msgs)
1010 ;; Delete the scan listing lines for each of the msgs in the LIST.
1011 ;; Optimized for speed (i.e., no regular expressions).
1012 (setq msgs (sort msgs (function <))) ;okay to clobber msgs
1015 (while (and msgs (< (point) (point-max)))
1016 (cond ((equal (mh-get-msg-num nil) (car msgs))
1017 (delete-region (point) (save-excursion (forward-line) (point)))
1018 (setq msgs (cdr msgs)))
1023 (defun mh-outstanding-commands-p ()
1024 ;; Returns non-nil if there are outstanding deletes or refiles.
1025 (or mh-delete-list mh-refile-list))
1029 ;;; Basic sequence handling
1031 (defun mh-delete-seq-locally (seq)
1032 ;; Remove mh-e's record of SEQUENCE.
1033 (let ((entry (mh-find-seq seq)))
1034 (setq mh-seq-list (delq entry mh-seq-list))))
1036 (defun mh-read-folder-sequences (folder save-refiles)
1037 ;; Read and return the predefined sequences for a FOLDER.
1038 ;; If SAVE-REFILES is non-nil, then keep the sequences
1039 ;; that note messages to be refiled.
1042 (mh-mapc (function (lambda (seq) ; Save the refiling sequences
1043 (if (mh-folder-name-p (mh-seq-name seq))
1044 (setq seqs (cons seq seqs)))))
1047 (if (eq 0 (mh-exec-cmd-quiet nil "mark" folder "-list"))
1049 ;; look for name in line of form "cur: 4" or "myseq (private): 23"
1050 (while (re-search-forward "^[^: ]+" nil t)
1051 (setq seqs (cons (mh-make-seq (intern (buffer-substring
1056 (delete-region (point-min) (point))))) ; avoid race with mh-process-daemon
1059 (defun mh-read-msg-list ()
1060 ;; Return a list of message numbers from the current point to the end of
1063 (end-of-line (save-excursion (end-of-line) (point)))
1065 (while (re-search-forward "[0-9]+" end-of-line t)
1066 (setq num (string-to-int (buffer-substring (match-beginning 0)
1068 (cond ((looking-at "-") ; Message range
1070 (re-search-forward "[0-9]+" end-of-line t)
1071 (let ((num2 (string-to-int (buffer-substring (match-beginning 0)
1074 (error "Bad message range: %d-%d" num num2))
1075 (while (<= num num2)
1076 (setq msgs (cons num msgs))
1077 (setq num (1+ num)))))
1078 ((not (zerop num)) (setq msgs (cons num msgs)))))
1081 (defun mh-notate-user-sequences ()
1082 ;; Mark the scan listing of all messages in user-defined sequences.
1083 (let ((seqs mh-seq-list)
1086 (setq name (mh-seq-name (car seqs)))
1087 (if (not (mh-internal-seq name))
1088 (mh-notate-seq name ?% (1+ mh-cmd-note)))
1089 (setq seqs (cdr seqs)))))
1092 (defun mh-internal-seq (name)
1093 ;; Return non-NIL if NAME is the name of an internal mh-e sequence.
1094 (or (memq name '(answered cur deleted forwarded printed))
1095 (eq name mh-unseen-seq)
1096 (eq name mh-previous-seq)
1097 (mh-folder-name-p name)))
1100 (defun mh-delete-msg-from-seq (msg seq &optional internal-flag)
1101 "Delete MESSAGE from SEQUENCE. MESSAGE defaults to displayed message.
1102 From Lisp, optional third arg INTERNAL non-nil means do not
1103 inform MH of the change."
1104 (interactive (list (mh-get-msg-num t)
1105 (mh-read-seq-default "Delete from" t)
1107 (let ((entry (mh-find-seq seq)))
1109 (mh-notate-if-in-one-seq msg ? (1+ mh-cmd-note) (mh-seq-name entry))
1110 (if (not internal-flag)
1111 (mh-undefine-sequence seq msg))
1112 (setcdr entry (delq msg (mh-seq-msgs entry)))))))
1115 (defun mh-undefine-sequence (seq msgs)
1116 ;; Remove from the SEQUENCE the MSGS, which may be a list or single msg.
1117 (mh-exec-cmd "mark" mh-current-folder "-delete"
1118 "-sequence" (symbol-name seq)
1122 (defun mh-define-sequence (seq msgs)
1123 ;; Define the SEQUENCE to contain the list of MSGS.
1124 ;; Do not mark pseudo-sequences or empty sequences.
1125 ;; Signals an error if SEQUENCE is an illegal name.
1127 (not (mh-folder-name-p seq)))
1129 (mh-exec-cmd-error nil "mark" mh-current-folder "-add" "-zero"
1130 "-sequence" (symbol-name seq)
1134 (defun mh-define-sequences (seq-list)
1135 ;; Define the sequences in SEQ-LIST.
1136 (mh-map-over-seqs 'mh-define-sequence seq-list))
1139 (defun mh-map-over-seqs (func seq-list)
1140 ;; Apply the FUNCTION to each element in the list of SEQUENCES,
1141 ;; passing the sequence name and the list of messages as arguments.
1143 (funcall func (mh-seq-name (car seq-list)) (mh-seq-msgs (car seq-list)))
1144 (setq seq-list (cdr seq-list))))
1147 (defun mh-notate-if-in-one-seq (msg notation offset seq)
1148 ;; If the MESSAGE is in only the SEQUENCE, then mark the scan listing of the
1149 ;; message with the CHARACTER at the given OFFSET from the beginning of the
1151 (let ((in-seqs (mh-seq-containing-msg msg)))
1152 (if (and (eq seq (car in-seqs)) (null (cdr in-seqs)))
1153 (mh-notate msg notation offset))))
1156 (defun mh-seq-containing-msg (msg)
1157 ;; Return a list of the sequences containing MESSAGE.
1158 (let ((l mh-seq-list)
1161 (if (memq msg (mh-seq-msgs (car l)))
1162 (setq seqs (cons (mh-seq-name (car l)) seqs)))
1169 ;;; User prompting commands.
1172 (defun mh-read-msg-range (prompt)
1173 ;; Read a list of blank-separated items.
1174 (let* ((buf (read-string prompt))
1175 (buf-size (length buf))
1178 (while (< start buf-size)
1179 (let ((next (read-from-string buf start buf-size)))
1180 (setq input (cons (car next) input))
1181 (setq start (cdr next))))
1186 ;;; Build the folder-mode keymap:
1188 (suppress-keymap mh-folder-mode-map)
1189 (define-key mh-folder-mode-map "q" 'mh-quit)
1190 (define-key mh-folder-mode-map "b" 'mh-compat-quit)
1191 (define-key mh-folder-mode-map "?" 'mh-msg-is-in-seq)
1192 (define-key mh-folder-mode-map "%" 'mh-put-msg-in-seq)
1193 (define-key mh-folder-mode-map "|" 'mh-pipe-msg)
1194 (define-key mh-folder-mode-map "\ea" 'mh-edit-again)
1195 (define-key mh-folder-mode-map "\e%" 'mh-delete-msg-from-seq)
1196 (define-key mh-folder-mode-map "\e#" 'mh-delete-seq)
1197 (define-key mh-folder-mode-map "\C-xn" 'mh-narrow-to-seq)
1198 (define-key mh-folder-mode-map "\C-xw" 'mh-widen)
1199 (define-key mh-folder-mode-map "\eb" 'mh-burst-digest)
1200 (define-key mh-folder-mode-map "\eu" 'mh-undo-folder)
1201 (define-key mh-folder-mode-map "\e " 'mh-page-digest)
1202 (define-key mh-folder-mode-map "\e\177" 'mh-page-digest-backwards)
1203 (define-key mh-folder-mode-map "\ed" 'mh-redistribute)
1204 (define-key mh-folder-mode-map "\ee" 'mh-extract-rejected-mail)
1205 (define-key mh-folder-mode-map "\ef" 'mh-visit-folder)
1206 (define-key mh-folder-mode-map "\ek" 'mh-kill-folder)
1207 (define-key mh-folder-mode-map "\el" 'mh-list-folders)
1208 (define-key mh-folder-mode-map "\en" 'mh-store-msg)
1209 (define-key mh-folder-mode-map "\ep" 'mh-pack-folder)
1210 (define-key mh-folder-mode-map "\eq" 'mh-list-sequences)
1211 (define-key mh-folder-mode-map "\es" 'mh-search-folder)
1212 (define-key mh-folder-mode-map "\er" 'mh-rescan-folder)
1213 (define-key mh-folder-mode-map "l" 'mh-print-msg)
1214 (define-key mh-folder-mode-map "t" 'mh-toggle-showing)
1215 (define-key mh-folder-mode-map "c" 'mh-copy-msg)
1216 (define-key mh-folder-mode-map "i" 'mh-inc-folder)
1217 (define-key mh-folder-mode-map "x" 'mh-execute-commands)
1218 (define-key mh-folder-mode-map "e" 'mh-execute-commands)
1219 (define-key mh-folder-mode-map "f" 'mh-forward)
1220 (define-key mh-folder-mode-map "m" 'mh-send)
1221 (define-key mh-folder-mode-map "s" 'mh-send)
1222 (define-key mh-folder-mode-map "r" 'mh-reply)
1223 (define-key mh-folder-mode-map "a" 'mh-reply)
1224 (define-key mh-folder-mode-map "j" 'mh-goto-msg)
1225 (define-key mh-folder-mode-map "g" 'mh-goto-msg)
1226 (define-key mh-folder-mode-map "\e>" 'mh-last-msg)
1227 (define-key mh-folder-mode-map "\177" 'mh-previous-page)
1228 (define-key mh-folder-mode-map " " 'mh-page-msg)
1229 (define-key mh-folder-mode-map "." 'mh-show)
1230 (define-key mh-folder-mode-map "," 'mh-header-display)
1231 (define-key mh-folder-mode-map "u" 'mh-undo)
1232 (define-key mh-folder-mode-map "d" 'mh-delete-msg)
1233 (define-key mh-folder-mode-map "\C-d" 'mh-delete-msg-no-motion)
1234 (define-key mh-folder-mode-map "p" 'mh-previous-undeleted-msg)
1235 (define-key mh-folder-mode-map "n" 'mh-next-undeleted-msg)
1236 (define-key mh-folder-mode-map "o" 'mh-refile-msg)
1237 (define-key mh-folder-mode-map "^" 'mh-refile-msg)
1238 (define-key mh-folder-mode-map "\C-o" 'mh-write-msg-to-file)
1239 (define-key mh-folder-mode-map ">" 'mh-write-msg-to-file)
1240 (define-key mh-folder-mode-map "!" 'mh-refile-or-write-again)
1244 ;;;autoload the other mh-e parts
1248 (autoload 'mh-smail "mh-comp"
1249 "Compose and send mail with the MH mail system." t)
1250 (autoload 'mh-smail-other-window "mh-comp"
1251 "Compose and send mail in other window with the MH mail system." t)
1252 (autoload 'mh-edit-again "mh-comp"
1253 "Clean-up a draft or a message previously sent and make it resendable." t)
1254 (autoload 'mh-extract-rejected-mail "mh-comp"
1255 "Extract a letter returned by the mail system and make it resendable." t)
1256 (autoload 'mh-forward "mh-comp"
1257 "Forward MESSAGE(s) (default: displayed message)." t)
1258 (autoload 'mh-redistribute "mh-comp"
1259 "Redistribute a letter." t)
1260 (autoload 'mh-reply "mh-comp"
1261 "Reply to a MESSAGE (default: displayed message)." t)
1262 (autoload 'mh-send "mh-comp"
1263 "Compose and send a letter." t)
1264 (autoload 'mh-send-other-window "mh-comp"
1265 "Compose and send a letter in another window." t)
1266 (autoload 'mh-letter-mode "mh-comp"
1267 "Mode for composing letters in mh-e." t)
1272 (autoload 'mh-burst-digest "mh-funcs"
1273 "Burst apart the current message, which should be a digest." t)
1274 (autoload 'mh-copy-msg "mh-funcs"
1275 "Copy specified MESSAGE(s) to another FOLDER without deleting them." t)
1276 (autoload 'mh-kill-folder "mh-funcs"
1277 "Remove the current folder." t)
1278 (autoload 'mh-list-folders "mh-funcs"
1279 "List mail folders." t)
1280 (autoload 'mh-pack-folder "mh-funcs"
1281 "Renumber the messages of a folder to be 1..n." t)
1282 (autoload 'mh-pipe-msg "mh-funcs"
1283 "Pipe the current message through the given shell COMMAND." t)
1284 (autoload 'mh-page-digest "mh-funcs"
1285 "Advance displayed message to next digested message." t)
1286 (autoload 'mh-page-digest-backwards "mh-funcs"
1287 "Back up displayed message to previous digested message." t)
1288 (autoload 'mh-print-msg "mh-funcs"
1289 "Print MESSAGE(s) (default: displayed message) on a line printer." t)
1290 (autoload 'mh-sort-folder "mh-funcs"
1291 "Sort the messages in the current folder by date." t)
1292 (autoload 'mh-undo-folder "mh-funcs"
1293 "Undo all commands in current folder." t)
1294 (autoload 'mh-store-msg "mh-funcs"
1295 "Store the file(s) contained in the current message into DIRECTORY.
1296 The message can contain a shar file or uuencoded file." t)
1297 (autoload 'mh-store-buffer "mh-funcs"
1298 "Store the file(s) contained in the current buffer into DIRECTORY.
1299 The buffer can contain a shar file or uuencoded file." t)
1304 (autoload 'mh-search-folder "mh-pick"
1305 "Search FOLDER for messages matching a pattern." t)
1309 (autoload 'mh-put-msg-in-seq "mh-seq"
1310 "Add MESSAGE(s) (default: displayed message) to SEQUENCE." t)
1311 (autoload 'mh-delete-seq "mh-seq"
1312 "Delete the SEQUENCE." t)
1313 (autoload 'mh-list-sequences "mh-seq"
1314 "List the sequences defined in FOLDER." t)
1315 (autoload 'mh-msg-is-in-seq "mh-seq"
1316 "Display the sequences that contain MESSAGE (default: displayed message)." t)
1317 (autoload 'mh-narrow-to-seq "mh-seq"
1318 "Restrict display of this folder to just messages in a sequence." t)
1319 (autoload 'mh-widen "mh-seq"
1320 "Remove restrictions from current folder, thereby showing all messages." t)
1321 (autoload 'mh-rename-seq "mh-seq"
1322 "Rename a SEQUENCE to have a new NAME." t)
1324 ;;; mh-e.el ends here