Mercurial > emacs
changeset 6365:a1b8926f7ece
entered into RCS
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 15 Mar 1994 06:16:30 +0000 |
parents | 59663885e8c7 |
children | 6f28d7614611 |
files | lisp/mail/mh-comp.el lisp/mail/mh-e.el lisp/mail/mh-funcs.el lisp/mail/mh-mime.el lisp/mail/mh-pick.el lisp/mail/mh-seq.el lisp/mail/mh-utils.el |
diffstat | 7 files changed, 4003 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lisp/mail/mh-comp.el Tue Mar 15 06:16:30 1994 +0000 @@ -0,0 +1,934 @@ +;;; mh-comp --- mh-e functions for composing messages +;; Time-stamp: <94/03/08 10:05:20 gildea> + +;; Copyright 1993 Free Software Foundation, Inc. + +;; This file is part of mh-e. + +;; mh-e is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 2, or (at your option) +;; any later version. + +;; mh-e is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with mh-e; see the file COPYING. If not, write to +;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + +;;; Commentary: + +;; Internal support for mh-e package. + +;;; Code: + +(provide 'mh-comp) +(require 'mh-utils) + +(defvar mh-note-repl "-" + "String whose first character is used to notate replied to messages.") + +(defvar mh-note-forw "F" + "String whose first character is used to notate forwarded messages.") + +(defvar mh-note-dist "R" + "String whose first character is used to notate redistributed messages.") + +(defvar mh-send-prog "send" + "Name of the MH send program. +Some sites need to change this because of a name conflict.") + +(defvar mh-yank-hooks nil + "Obsolete hook for modifying a citation just inserted in the mail buffer. +Each hook function can find the citation between point and mark. +And each hook function should leave point and mark around the citation +text as modified. + +This is a normal hook, misnamed for historical reasons. +It is semi-obsolete and is only used if mail-citation-hook is nil.") + +(defvar mail-citation-hook nil + "*Hook for modifying a citation just inserted in the mail buffer. +Each hook function can find the citation between point and mark. +And each hook function should leave point and mark around the citation +text as modified. + +If this hook is entirely empty (nil), the text of the message is inserted +with mh-ins-buf-prefix prefixed to each line. + +See also the variable mh-yank-from-start-of-msg, which controls how +much of the message passed to the hook.") + +;;; Copied from sendmail.el for Hyperbole +(defvar mail-header-separator "--------" + "*Line used by MH to separate headers from text in messages being composed.") + +;;; Personal preferences: + +(defvar mh-delete-yanked-msg-window nil + "*Controls window display when a message is yanked by \\<mh-letter-mode-map>\\[mh-yank-cur-msg]. +If non-nil, yanking the current message into a draft letter deletes any +windows displaying the message.") + +(defvar mh-yank-from-start-of-msg t + "*Controls which part of a message is yanked by \\<mh-letter-mode-map>\\[mh-yank-cur-msg]. +If non-nil, include the entire message. If the symbol `body', then yank the +message minus the header. If nil, yank only the portion of the message +following the point. If the show buffer has a region, this variable is +ignored.") + +(defvar mh-reply-default-reply-to nil + "*Sets the person or persons to whom a reply will be sent. +If nil, prompt for recipient. If non-nil, then \\<mh-folder-mode-map>`\\[mh-reply]' will use this +value and it should be one of \"from\", \"to\", or \"cc\".") + +(defvar mh-signature-file-name "~/.signature" + "*Name of file containing the user's signature. +Inserted into message by \\<mh-letter-mode-map>\\[mh-insert-signature].") + +(defvar mh-forward-subject-format "%s: %s" + "*Format to generate the Subject: line contents for a forwarded message. +The two string arguments to the format are the sender of the original +message and the original subject line.") + +(defvar mh-comp-formfile "components" + "Name of file to be used as a skeleton for composing messages. +Default is \"components\". If not a complete path name, the file +is searched for first in the user's MH directory, then in the +system MH lib directory.") + +;;; Hooks: + +(defvar mh-letter-mode-hook nil + "Invoked in `mh-letter-mode' on a new letter.") + +(defvar mh-compose-letter-function nil + "Invoked in `mh-compose-and-send-mail' on a draft letter. +It is passed three arguments: TO recipients, SUBJECT, and CC recipients.") + +(defvar mh-before-send-letter-hook nil + "Invoked at the beginning of the \\<mh-letter-mode-map>\\[mh-send-letter] command.") + + +(defvar mh-rejected-letter-start + (concat "^ ----- Unsent message follows -----$" ;from mail system + "\\|^------- Unsent Draft$" ;from MH itself + "\\|^---------- Original Message ----------$" ;from zmailer + "\\|^ --- The unsent message follows ---$" ;from AIX mail system + "\\|^ Your message follows:$") ;from MMDF-II + "Regexp specifying the beginning of the wrapper around a returned letter. +This wrapper is generated by the mail system when rejecting a letter.") + +(defvar mh-new-draft-cleaned-headers + "^Date:\\|^Received:\\|^Message-Id:\\|^From:\\|^Sender:\\|^Delivery-Date:\\|^Return-Path:" + "Regexp of header lines to remove before offering a message as a new draft. +Used by the \\<mh-folder-mode-map>`\\[mh-edit-again]' and `\\[mh-extract-rejected-mail]' commands.") + +(defvar mh-to-field-choices '((?t . "To:") (?s . "Subject:") (?c . "Cc:") + (?b . "Bcc:") (?f . "Fcc:")) + "Alist of (final-character . field-name) choices for mh-to-field.") + +(defvar mh-letter-mode-map (copy-keymap text-mode-map) + "Keymap for composing mail.") + +(defvar mh-letter-mode-syntax-table nil + "Syntax table used by mh-e while in MH-Letter mode.") + +(if mh-letter-mode-syntax-table + () + (setq mh-letter-mode-syntax-table + (make-syntax-table text-mode-syntax-table)) + (modify-syntax-entry ?% "." mh-letter-mode-syntax-table)) + + +;;;###autoload +(defun mh-smail () + "Compose and send mail with the MH mail system. +This function is an entry point to mh-e, the Emacs front end +to the MH mail system." + (interactive) + (mh-find-path) + (call-interactively 'mh-send)) + + +(defun mh-edit-again (msg) + "Clean-up a draft or a message previously sent and make it resendable. +The variable mh-new-draft-cleaned-headers specifies the headers to remove. +See also documentation for `\\[mh-send]' function." + (interactive (list (mh-get-msg-num t))) + (let* ((from-folder mh-current-folder) + (config (current-window-configuration)) + (draft + (cond ((and mh-draft-folder (equal from-folder mh-draft-folder)) + (pop-to-buffer (find-file-noselect (mh-msg-filename msg)) t) + (rename-buffer (format "draft-%d" msg)) + (buffer-name)) + (t + (mh-read-draft "clean-up" (mh-msg-filename msg) nil))))) + (mh-clean-msg-header (point-min) mh-new-draft-cleaned-headers nil) + (goto-char (point-min)) + (set-buffer-modified-p nil) + (mh-compose-and-send-mail draft "" from-folder nil nil nil nil nil nil + config))) + + +(defun mh-extract-rejected-mail (msg) + "Extract a letter returned by the mail system and make it resendable. +Default is the displayed message. The variable mh-new-draft-cleaned-headers +gives the headers to clean out of the original message. +See also documentation for `\\[mh-send]' function." + (interactive (list (mh-get-msg-num t))) + (let ((from-folder mh-current-folder) + (config (current-window-configuration)) + (draft (mh-read-draft "extraction" (mh-msg-filename msg) nil))) + (goto-char (point-min)) + (cond ((re-search-forward mh-rejected-letter-start nil t) + (skip-chars-forward " \t\n") + (delete-region (point-min) (point)) + (mh-clean-msg-header (point-min) mh-new-draft-cleaned-headers nil)) + (t + (message "Does not appear to be a rejected letter."))) + (goto-char (point-min)) + (set-buffer-modified-p nil) + (mh-compose-and-send-mail draft "" from-folder msg (mh-get-field "To:") + (mh-get-field "From:") (mh-get-field "Cc:") + nil nil config))) + + +(defun mh-forward (to cc &optional msg-or-seq) + "Forward a message or message sequence. Defaults to displayed message. +If optional prefix argument provided, then prompt for the message sequence. +See also documentation for `\\[mh-send]' function." + (interactive (list (mh-read-address "To: ") + (mh-read-address "Cc: ") + (if current-prefix-arg + (mh-read-seq-default "Forward" t) + (mh-get-msg-num t)))) + (or msg-or-seq + (setq msg-or-seq (mh-get-msg-num t))) + (let* ((folder mh-current-folder) + (config (current-window-configuration)) + ;; forw always leaves file in "draft" since it doesn't have -draft + (draft-name (expand-file-name "draft" mh-user-path)) + (draft (cond ((or (not (file-exists-p draft-name)) + (y-or-n-p "The file 'draft' exists. Discard it? ")) + (mh-exec-cmd "forw" + "-build" mh-current-folder msg-or-seq) + (prog1 + (mh-read-draft "" draft-name t) + (mh-insert-fields "To:" to "Cc:" cc) + (set-buffer-modified-p nil))) + (t + (mh-read-draft "" draft-name nil))))) + (goto-char (point-min)) + (re-search-forward "^------- Forwarded Message") + (forward-line -1) + (narrow-to-region (point) (point-max)) + (let ((orig-from (save-excursion (mh-get-field "From:"))) + (orig-subject (save-excursion (mh-get-field "Subject:")))) + (widen) + (let ((forw-subject + (mh-forwarded-letter-subject orig-from orig-subject))) + (save-excursion (mh-insert-fields "Subject:" forw-subject)) + (delete-other-windows) + (if (numberp msg-or-seq) + (mh-add-msgs-to-seq msg-or-seq 'forwarded t) + (mh-add-msgs-to-seq (mh-seq-to-msgs msg-or-seq) 'forwarded t)) + (mh-compose-and-send-mail draft "" folder msg-or-seq + to forw-subject cc + mh-note-forw "Forwarded:" + config))))) + +(defun mh-forwarded-letter-subject (from subject) + ;; Return a Subject suitable for a forwarded message. + ;; Original message has headers FROM and SUBJECT. + (let ((addr-start (string-match "<" from)) + (comment (string-match "(" from))) + (cond ((and addr-start (> addr-start 0)) + ;; Full Name <luser@host> + (setq from (substring from 0 (1- addr-start)))) + (comment + ;; luser@host (Full Name) + (setq from (substring from (1+ comment) (1- (length from))))))) + (format mh-forward-subject-format from subject)) + + +;;;###autoload +(defun mh-smail-other-window () + "Compose and send mail in other window with the MH mail system. +This function is an entry point to mh-e, the Emacs front end +to the MH mail system." + (interactive) + (mh-find-path) + (call-interactively 'mh-send-other-window)) + + +(defun mh-redistribute (to cc &optional msg) + "Redistribute a letter. +Depending on how your copy of MH was compiled, you may need to change the +setting of the variable mh-redist-full-contents. See its documentation." + (interactive (list (mh-read-address "Redist-To: ") + (mh-read-address "Redist-Cc: ") + (mh-get-msg-num t))) + (or msg + (setq msg (mh-get-msg-num t))) + (save-window-excursion + (let ((folder mh-current-folder) + (draft (mh-read-draft "redistribution" + (if mh-redist-full-contents + (mh-msg-filename msg) + nil) + nil))) + (mh-goto-header-end 0) + (insert "Resent-To: " to "\n") + (if (not (equal cc "")) (insert "Resent-cc: " cc "\n")) + (mh-clean-msg-header (point-min) + "^Message-Id:\\|^Received:\\|^Return-Path:\\|^Sender:\\|^Date:\\|^From:" + nil) + (save-buffer) + (message "Redistributing...") + (if mh-redist-full-contents + (call-process "/bin/sh" nil 0 nil "-c" + (format "mhdist=1 mhaltmsg=%s %s -push %s" + (buffer-file-name) + (expand-file-name mh-send-prog mh-progs) + (buffer-file-name))) + (call-process "/bin/sh" nil 0 nil "-c" + (format "mhdist=1 mhaltmsg=%s mhannotate=1 %s -push %s" + (mh-msg-filename msg folder) + (expand-file-name mh-send-prog mh-progs) + (buffer-file-name)))) + (mh-annotate-msg msg folder mh-note-dist + "-component" "Resent:" + "-text" (format "\"%s %s\"" to cc)) + (kill-buffer draft) + (message "Redistributing...done")))) + + +(defun mh-reply (msg &optional includep) + "Reply to a MESSAGE (default: displayed message). +If optional prefix argument INCLUDEP provided, then include the message +in the reply using filter mhl.reply in your MH directory. +Prompts for type of addresses to reply to: + from sender only, + to sender and primary recipients, + cc/all sender and all recipients. +See also documentation for `\\[mh-send]' function." + (interactive (list (mh-get-msg-num t) current-prefix-arg)) + (let ((minibuffer-help-form + "from => Sender only\nto => Sender and primary recipients\ncc or all => Sender and all recipients")) + (let ((reply-to (or mh-reply-default-reply-to + (completing-read "Reply to whom: " + '(("from") ("to") ("cc") ("all")) + nil + t))) + (folder mh-current-folder) + (show-buffer mh-show-buffer) + (config (current-window-configuration))) + (message "Composing a reply...") + (mh-exec-cmd "repl" "-build" "-noquery" "-nodraftfolder" + mh-current-folder msg + (cond ((or (equal reply-to "from") (equal reply-to "")) + '("-nocc" "all")) + ((equal reply-to "to") + '("-cc" "to")) + ((or (equal reply-to "cc") (equal reply-to "all")) + '("-cc" "all" "-nocc" "me"))) + (if includep + '("-filter" "mhl.reply"))) + (let ((draft (mh-read-draft "reply" + (expand-file-name "reply" mh-user-path) + t))) + (delete-other-windows) + (set-buffer-modified-p nil) + + (let ((to (mh-get-field "To:")) + (subject (mh-get-field "Subject:")) + (cc (mh-get-field "Cc:"))) + (goto-char (point-min)) + (mh-goto-header-end 1) + (or includep + (mh-in-show-buffer (show-buffer) + (mh-display-msg msg folder))) + (mh-add-msgs-to-seq msg 'answered t) + (message "Composing a reply...done") + (mh-compose-and-send-mail draft "" folder msg to subject cc + mh-note-repl "Replied:" config)))))) + + +(defun mh-send (to cc subject) + "Compose and send a letter. +The file named by `mh-comp-formfile' will be used as the form. +The letter is composed in mh-letter-mode; see its documentation for more +details. If `mh-compose-letter-function' is defined, it is called on the +draft and passed three arguments: to, subject, and cc. +Do not call this function from outside mh-e; use \\[mh-smail] instead." + (interactive (list + (mh-read-address "To: ") + (mh-read-address "Cc: ") + (read-string "Subject: "))) + (let ((config (current-window-configuration))) + (delete-other-windows) + (mh-send-sub to cc subject config))) + + +(defun mh-send-other-window (to cc subject) + "Compose and send a letter in another window. +Do not call this function from outside mh-e; +use \\[mh-smail-other-window] instead. +See also documentation for `\\[mh-send]' function." + (interactive (list + (mh-read-address "To: ") + (mh-read-address "Cc: ") + (read-string "Subject: "))) + (let ((pop-up-windows t)) + (mh-send-sub to cc subject (current-window-configuration)))) + + +(defun mh-send-sub (to cc subject config) + "Do the real work of composing and sending a letter. +Expects the TO, CC, and SUBJECT fields as arguments. +CONFIG is the window configuration before sending mail." + (let ((folder mh-current-folder) + (msg-num (mh-get-msg-num nil))) + (message "Composing a message...") + (let ((draft (mh-read-draft + "message" + (let (components) + (cond + ((file-exists-p + (setq components + (expand-file-name mh-comp-formfile mh-user-path))) + components) + ((file-exists-p + (setq components + (expand-file-name mh-comp-formfile mh-lib))) + components) + (t + (error (format "Can't find components file \"%s\"" + components))))) + nil))) + (mh-insert-fields "To:" to "Subject:" subject "Cc:" cc) + (goto-char (point-max)) + (message "Composing a message...done") + (mh-compose-and-send-mail draft "" folder msg-num + to subject cc + nil nil config)))) + + +(defun mh-read-draft (use initial-contents delete-contents-file) + ;; Read draft file into a draft buffer and make that buffer the current one. + ;; USE is a message used for prompting about the intended use of the message. + ;; INITIAL-CONTENTS is filename that is read into an empty buffer, or NIL + ;; if buffer should not be modified. Delete the initial-contents file if + ;; DELETE-CONTENTS-FILE flag is set. + ;; Returns the draft folder's name. + ;; If the draft folder facility is enabled in ~/.mh_profile, a new buffer is + ;; used each time and saved in the draft folder. The draft file can then be + ;; reused. + (cond (mh-draft-folder + (let ((orig-default-dir default-directory) + (draft-file-name (mh-new-draft-name))) + (pop-to-buffer (generate-new-buffer + (format "draft-%s" + (file-name-nondirectory draft-file-name)))) + (condition-case () + (insert-file-contents draft-file-name t) + (file-error)) + (setq default-directory orig-default-dir))) + (t + (let ((draft-name (expand-file-name "draft" mh-user-path))) + (pop-to-buffer "draft") ; Create if necessary + (if (buffer-modified-p) + (if (y-or-n-p "Draft has been modified; kill anyway? ") + (set-buffer-modified-p nil) + (error "Draft preserved"))) + (setq buffer-file-name draft-name) + (clear-visited-file-modtime) + (unlock-buffer) + (cond ((and (file-exists-p draft-name) + (not (equal draft-name initial-contents))) + (insert-file-contents draft-name) + (delete-file draft-name)))))) + (cond ((and initial-contents + (or (zerop (buffer-size)) + (not (y-or-n-p + (format "A draft exists. Use for %s? " use))))) + (erase-buffer) + (insert-file-contents initial-contents) + (if delete-contents-file (delete-file initial-contents)))) + (auto-save-mode 1) + (if mh-draft-folder + (save-buffer)) ; Do not reuse draft name + (buffer-name)) + + +(defun mh-new-draft-name () + ;; Returns the pathname of folder for draft messages. + (save-excursion + (mh-exec-cmd-quiet t "mhpath" mh-draft-folder "new") + (buffer-substring (point-min) (1- (point-max))))) + + +(defun mh-annotate-msg (msg buffer note &rest args) + ;; Mark the MESSAGE in BUFFER listing with the character NOTE and annotate + ;; the saved message with ARGS. + (apply 'mh-exec-cmd "anno" buffer msg args) + (save-excursion + (cond ((get-buffer buffer) ; Buffer may be deleted + (set-buffer buffer) + (if (symbolp msg) + (mh-notate-seq msg note (1+ mh-cmd-note)) + (mh-notate msg note (1+ mh-cmd-note))))))) + + +(defun mh-insert-fields (&rest name-values) + ;; Insert the NAME-VALUE pairs in the current buffer. + ;; If field NAME exists, append VALUE to it. + ;; Do not insert any pairs whose value is the empty string. + (let ((case-fold-search t)) + (while name-values + (let ((field-name (car name-values)) + (value (car (cdr name-values)))) + (cond ((equal value "") + nil) + ((mh-position-on-field field-name) + (insert " " value)) + (t + (insert field-name " " value "\n"))) + (setq name-values (cdr (cdr name-values))))))) + + +(defun mh-position-on-field (field &optional ignore) + ;; Move to the end of the FIELD in the header. + ;; Move to end of entire header if FIELD not found. + ;; Returns non-nil iff FIELD was found. + ;; The optional second arg is for pre-version 4 compatibility. + (let ((case-fold-search t)) + (goto-char (point-min)) + (mh-goto-header-end 0) + (if (re-search-backward (format "^%s" field) nil t) + (progn + (forward-line 1) + (while (looking-at "^[ \t]") + (forward-line 1)) + (backward-char 1) ;to end of previous line + t) + nil))) + + +(defun mh-goto-header-end (arg) + ;; Find the end of the message header in the current buffer and position + ;; the cursor at the ARG'th newline after the header. + (if (re-search-forward "^$\\|^-+$" nil nil) + (forward-line arg))) + + +(defun mh-read-address (prompt) + ;; Read a To: or Cc: address, prompting in the minibuffer with PROMPT. + ;; May someday do completion on aliases. + (read-string prompt)) + + + +;;; Mode for composing and sending a draft message. + +(defvar mh-sent-from-folder nil + "Folder of msg associated with this letter.") + +(defvar mh-sent-from-msg nil + "Number of msg associated with this letter.") + +(defvar mh-send-args nil + "Extra arguments to pass to \"send\" command.") + +(defvar mh-annotate-char nil + "Character to use to annotate mh-sent-from-msg.") + +(defvar mh-annotate-field nil + "Field name for message annotation.") + +(put 'mh-letter-mode 'mode-class 'special) + +;;;###autoload +(defun mh-letter-mode () + "Mode for composing letters in mh-e.\\<mh-letter-mode-map> +When you have finished composing, type \\[mh-send-letter] to send the letter. + +\\{mh-letter-mode-map} + +Variables controlling this mode (defaults in parentheses): + + mh-delete-yanked-msg-window (nil) + If non-nil, \\[mh-yank-cur-msg] will delete any windows displaying + the yanked message. + + mh-yank-from-start-of-msg (t) + If non-nil, \\[mh-yank-cur-msg] will include the entire message. + If `body', just yank the body (no header). + If nil, only the portion of the message following the point will be yanked. + If there is a region, this variable is ignored. + + mh-signature-file-name (\"~/.signature\") + File to be inserted into message by \\[mh-insert-signature]. + +Upon invoking mh-letter-mode, text-mode-hook and mh-letter-mode-hook are +invoked with no args, if those values are non-nil." + + (interactive) + (or mh-user-path (mh-find-path)) + (kill-all-local-variables) + (make-local-variable 'paragraph-start) + (setq paragraph-start (concat "^[ \t]*[-_][-_][-_]+$\\|" paragraph-start)) + (make-local-variable 'paragraph-separate) + (setq paragraph-separate + (concat "^[ \t]*[-_][-_][-_]+$\\|" paragraph-separate)) + (make-local-variable 'mh-send-args) + (make-local-variable 'mh-annotate-char) + (make-local-variable 'mh-annotate-field) + (make-local-variable 'mh-previous-window-config) + (make-local-variable 'mh-sent-from-folder) + (make-local-variable 'mh-sent-from-msg) + (make-local-variable 'mail-header-separator) + (setq mail-header-separator "--------") ;for Hyperbole + (use-local-map mh-letter-mode-map) + (setq major-mode 'mh-letter-mode) + (mh-set-mode-name "MH-Letter") + (set-syntax-table mh-letter-mode-syntax-table) + (run-hooks 'text-mode-hook) + ;; if text-mode-hook turned on auto-fill, tune it for messages + (cond ((and (boundp 'auto-fill-hook) auto-fill-hook) ;emacs 18 + (make-local-variable 'auto-fill-hook) + (setq auto-fill-hook 'mh-auto-fill-for-letter))) + (cond ((and (boundp 'auto-fill-function) auto-fill-function) ;emacs 19 + (make-local-variable 'auto-fill-function) + (setq auto-fill-function 'mh-auto-fill-for-letter))) + (run-hooks 'mh-letter-mode-hook)) + + +(defun mh-auto-fill-for-letter () + ;; Auto-fill in letters treats the header specially by inserting a tab + ;; before continuation line. + (do-auto-fill) + (if (mh-in-header-p) + (save-excursion + (beginning-of-line nil) + (insert-char ?\t 1)))) + + +(defun mh-in-header-p () + ;; Return non-nil if the point is in the header of a draft message. + (save-excursion + (let ((cur-point (point))) + (goto-char (point-min)) + (re-search-forward "^-*$" nil t) + (< cur-point (point))))) + + +(defun mh-to-field () + "Move point to the end of a specified header field. +The field is indicated by the previous keystroke (the last keystroke +of the command) according to the list in mh-to-field-choices. +Create the field if it does not exist. Set the mark to point before moving." + (interactive) + (expand-abbrev) + (let ((target (cdr (assoc (logior last-input-char ?`) mh-to-field-choices))) + (case-fold-search t)) + (push-mark) + (cond ((mh-position-on-field target) + (let ((eol (point))) + (skip-chars-backward " \t") + (delete-region (point) eol)) + (if (and (not (eq (logior last-input-char ?`) ?s)) + (save-excursion + (backward-char 1) + (not (looking-at "[:,]")))) + (insert ", ") + (insert " "))) + (t + (if (mh-position-on-field "To:") + (forward-line 1)) + (insert (format "%s \n" target)) + (backward-char 1))))) + + +(defun mh-to-fcc (&optional folder) + "Insert an Fcc: FOLDER field in the current message. +Prompt for the field name with a completion list of the current folders." + (interactive) + (or folder + (setq folder (mh-prompt-for-folder + "Fcc" + (or (and mh-msg-folder-hook + (save-excursion + (goto-char (point-min)) + (funcall mh-msg-folder-hook))) + "") + t))) + (let ((last-input-char ?\C-f)) + (expand-abbrev) + (save-excursion + (mh-to-field) + (insert (if (mh-folder-name-p folder) + (substring folder 1) + folder))))) + + +(defun mh-insert-signature () + "Insert the file named by mh-signature-file-name at the current point." + (interactive) + (insert-file-contents mh-signature-file-name) + (set-buffer-modified-p (buffer-modified-p))) ; force mode line update + + +(defun mh-check-whom () + "Verify recipients of the current letter." + (interactive) + (let ((file-name (buffer-file-name))) + (save-buffer) + (message "Checking recipients...") + (mh-in-show-buffer ("*Recipients*") + (bury-buffer (current-buffer)) + (erase-buffer) + (mh-exec-cmd-output "whom" t file-name)) + (message "Checking recipients...done"))) + + + +;;; Routines to compose and send a letter. + +(defun mh-compose-and-send-mail (draft send-args + sent-from-folder sent-from-msg + to subject cc + annotate-char annotate-field + config) + ;; Edit and compose a draft message in buffer DRAFT and send or save it. + ;; SENT-FROM-FOLDER is buffer containing scan listing of current folder, or + ;; nil if none exists. + ;; SENT-FROM-MSG is the message number or sequence name or nil. + ;; SEND-ARGS is an optional argument passed to the send command. + ;; The TO, SUBJECT, and CC fields are passed to the + ;; mh-compose-letter-function. + ;; If ANNOTATE-CHAR is non-null, it is used to notate the scan listing of the + ;; message. In that case, the ANNOTATE-FIELD is used to build a string + ;; for mh-annotate-msg. + ;; CONFIG is the window configuration to restore after sending the letter. + (pop-to-buffer draft) + (mh-letter-mode) + (setq mh-sent-from-folder sent-from-folder) + (setq mh-sent-from-msg sent-from-msg) + (setq mh-send-args send-args) + (setq mh-annotate-char annotate-char) + (setq mh-annotate-field annotate-field) + (setq mh-previous-window-config config) + (setq mode-line-buffer-identification (list "{%b}")) + (if (and (boundp 'mh-compose-letter-function) + (symbol-value 'mh-compose-letter-function)) + ;; run-hooks will not pass arguments. + (let ((value (symbol-value 'mh-compose-letter-function))) + (if (and (listp value) (not (eq (car value) 'lambda))) + (while value + (funcall (car value) to subject cc) + (setq value (cdr value))) + (funcall mh-compose-letter-function to subject cc))))) + + +(defun mh-send-letter (&optional arg) + "Send the draft letter in the current buffer. +If optional prefix argument is provided, monitor delivery. +Run mh-before-send-letter-hook before doing anything." + (interactive "P") + (run-hooks 'mh-before-send-letter-hook) + (set-buffer-modified-p t) ; Make sure buffer is written + (save-buffer) + (message "Sending...") + (let ((draft-buffer (current-buffer)) + (file-name (buffer-file-name)) + (config mh-previous-window-config)) + (cond (arg + (pop-to-buffer "MH mail delivery") + (erase-buffer) + (mh-exec-cmd-output mh-send-prog t "-watch" "-nopush" + "-nodraftfolder" mh-send-args file-name) + (goto-char (point-max)) ; show the interesting part + (recenter -1) + (set-buffer draft-buffer)) ; for annotation below + (t + (mh-exec-cmd-daemon mh-send-prog "-nodraftfolder" "-noverbose" + mh-send-args file-name))) + (if mh-annotate-char + (mh-annotate-msg mh-sent-from-msg + mh-sent-from-folder + mh-annotate-char + "-component" mh-annotate-field + "-text" (format "\"%s %s\"" + (mh-get-field "To:") + (mh-get-field "Cc:")))) + + (cond ((or (not arg) + (y-or-n-p "Kill draft buffer? ")) + (kill-buffer draft-buffer) + (if config + (set-window-configuration config)))) + (if arg + (message "Sending...done") + (message "Sending...backgrounded")))) + + +(defun mh-insert-letter (msg folder verbatum) + "Insert a MESSAGE from any FOLDER into the current letter. +Removes the message's headers using mh-invisible-headers. +Prefixes each non-blank line with mh-ins-buf-prefix (default \"> \"). +If prefix argument VERBATUM provided, do not indent and do not delete +headers. Leaves the mark before the letter and point after it." + (interactive + (list (read-input (format "Message number%s: " + (if mh-sent-from-msg + (format " [%d]" mh-sent-from-msg) + ""))) + (mh-prompt-for-folder "Message from" mh-sent-from-folder nil) + current-prefix-arg)) + (save-restriction + (narrow-to-region (point) (point)) + (let ((start (point-min))) + (if (equal msg "") (setq msg (int-to-string mh-sent-from-msg))) + (mh-exec-lib-cmd-output "mhl" "-nobell" "-noclear" + (expand-file-name msg + (mh-expand-file-name folder))) + (cond ((not verbatum) + (mh-clean-msg-header start mh-invisible-headers mh-visible-headers) + (set-mark start) ; since mh-clean-msg-header moves it + (mh-insert-prefix-string mh-ins-buf-prefix)))))) + + +(defun mh-yank-cur-msg () + "Insert the current message into the draft buffer. +Prefix each non-blank line in the message with the string in +`mh-ins-buf-prefix'. If a region is set in the message's buffer, then +only the region will be inserted. Otherwise, the entire message will +be inserted if `mh-yank-from-start-of-msg' is non-nil. If this variable +is nil, the portion of the message following the point will be yanked. +If `mh-delete-yanked-msg-window' is non-nil, any window displaying the +yanked message will be deleted." + (interactive) + (if (and mh-sent-from-folder mh-sent-from-msg) + (let ((to-point (point)) + (to-buffer (current-buffer))) + (set-buffer mh-sent-from-folder) + (if mh-delete-yanked-msg-window + (delete-windows-on mh-show-buffer)) + (set-buffer mh-show-buffer) ; Find displayed message + (let ((mh-ins-str (cond ((if (boundp 'mark-active) + mark-active ;Emacs 19 + (mark)) ;Emacs 18 + (buffer-substring (region-beginning) + (region-end))) + ((eq 'body mh-yank-from-start-of-msg) + (buffer-substring + (save-excursion + (goto-char (point-min)) + (mh-goto-header-end 1) + (point)) + (point-max))) + (mh-yank-from-start-of-msg + (buffer-substring (point-min) (point-max))) + (t + (buffer-substring (point) (point-max)))))) + (set-buffer to-buffer) + (narrow-to-region to-point to-point) + (push-mark) + (insert mh-ins-str) + (mh-insert-prefix-string mh-ins-buf-prefix) + (insert "\n") + (widen))) + (error "There is no current message"))) + + +(defun mh-insert-prefix-string (mh-ins-string) + ;; Run MAIL-CITATION-HOOK to insert a prefix string before each line + ;; in the buffer. Generality for supercite users. + (save-excursion + (set-mark (point-max)) + (goto-char (point-min)) + (cond (mail-citation-hook + (run-hooks 'mail-citation-hook)) + (mh-yank-hooks ;old hook name + (run-hooks 'mh-yank-hooks)) + (t + (or (bolp) (forward-line 1)) + (while (< (point) (mark)) + (insert mh-ins-string) + (forward-line 1)))))) + + +(defun mh-fully-kill-draft () + "Kill the draft message file and the draft message buffer. +Use \\[kill-buffer] if you don't want to delete the draft message file." + (interactive) + (if (y-or-n-p "Kill draft message? ") + (let ((config mh-previous-window-config)) + (if (file-exists-p (buffer-file-name)) + (delete-file (buffer-file-name))) + (set-buffer-modified-p nil) + (kill-buffer (buffer-name)) + (message "") + (if config + (set-window-configuration config))) + (error "Message not killed"))) + +;;; Build the letter-mode keymap: + +(define-key mh-letter-mode-map "\C-c\C-f\C-b" 'mh-to-field) +(define-key mh-letter-mode-map "\C-c\C-f\C-c" 'mh-to-field) +(define-key mh-letter-mode-map "\C-c\C-f\C-f" 'mh-to-fcc) +(define-key mh-letter-mode-map "\C-c\C-f\C-s" 'mh-to-field) +(define-key mh-letter-mode-map "\C-c\C-f\C-t" 'mh-to-field) +(define-key mh-letter-mode-map "\C-c\C-fb" 'mh-to-field) +(define-key mh-letter-mode-map "\C-c\C-fc" 'mh-to-field) +(define-key mh-letter-mode-map "\C-c\C-ff" 'mh-to-fcc) +(define-key mh-letter-mode-map "\C-c\C-fs" 'mh-to-field) +(define-key mh-letter-mode-map "\C-c\C-ft" 'mh-to-field) +(define-key mh-letter-mode-map "\C-c\C-q" 'mh-fully-kill-draft) +(define-key mh-letter-mode-map "\C-c\C-w" 'mh-check-whom) +(define-key mh-letter-mode-map "\C-c\C-i" 'mh-insert-letter) +(define-key mh-letter-mode-map "\C-c\C-y" 'mh-yank-cur-msg) +(define-key mh-letter-mode-map "\C-c\C-s" 'mh-insert-signature) +(define-key mh-letter-mode-map "\C-c\C-c" 'mh-send-letter) +(define-key mh-letter-mode-map "\C-c\C-m\C-f" 'mh-mhn-compose-forw) +(define-key mh-letter-mode-map "\C-c\C-m\C-e" 'mh-mhn-compose-anon-ftp) +(define-key mh-letter-mode-map "\C-c\C-m\C-t" 'mh-mhn-compose-external-compressed-tar) +(define-key mh-letter-mode-map "\C-c\C-m\C-i" 'mh-mhn-compose-insertion) +(define-key mh-letter-mode-map "\C-c\C-e" 'mh-edit-mhn) +(define-key mh-letter-mode-map "\C-c\C-m\C-u" 'mh-revert-mhn-edit) + + +;;; autoloads from mh-mime + +(autoload 'mh-mhn-compose-insertion "mh-mime" + "Add a directive to insert a message part from a file." t) +(autoload 'mh-mhn-compose-anon-ftp "mh-mime" + "Add a directive for an anonymous ftp external body part." t) +(autoload 'mh-mhn-compose-external-compressed-tar "mh-mime" + "Add a directive to include a reference to a compressed tar file." t) +(autoload 'mh-mhn-compose-forw "mh-mime" + "Add a forw directive to this message." t) +(autoload 'mh-edit-mhn "mh-mime" + "Filter the current draft through the mhn program for MIME formatting. +Using directives already inserted in the draft, fills in +all the MIME components and header fields. +This step should be done last just before sending the message. +The mhn program is part of MH version 6.8 or later. +The `\\[mh-revert-mhn-edit]' command undoes this command. +For assistance with creating MIME directives to insert +various types of components in a message, see +\\[mh-mhn-compose-insertion] (generic insertion from a file), +\\[mh-mhn-compose-anon-ftp] (external reference to file via anonymous ftp), +\\[mh-mhn-compose-external-compressed-tar] \ +\(reference to compressed tar file via anonymous ftp), and +\\[mh-mhn-compose-forw] (forward message)." t) + +(autoload 'mh-revert-mhn-edit "mh-mime" + "Undoes the effect of \\[mh-edit-mhn] by reverting to the backup file." t)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lisp/mail/mh-e.el Tue Mar 15 06:16:30 1994 +0000 @@ -0,0 +1,1334 @@ +;;; mh-e.el --- GNU Emacs interface to the MH mail system + +;;; Copyright 1985,86,87,88,90,92,93 Free Software Foundation + +(defconst mh-e-time-stamp "Time-stamp: <94/03/14 18:34:22 gildea>") +(defconst mh-e-version "4.0" + "Version numbers of this version of mh-e.") + +;; Maintainer: Stephen Gildea <gildea@lcs.mit.edu> +;; Version: 4.0 +;; Keywords: mail + +;; mh-e is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 2, or (at your option) +;; any later version. + +;; mh-e is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with mh-e; see the file COPYING. If not, write to +;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + +;;; Commentary: + +;;; HOW TO USE: +;;; M-x mh-rmail to read mail. Type C-h m there for a list of commands. +;;; C-u M-x mh-rmail to visit any folder. +;;; M-x mh-smail to send mail. From within the mail reader, "m" works, too. +;;; Your .emacs might benefit from these bindings: +;;; (global-set-key "\C-cr" 'mh-rmail) +;;; (global-set-key "\C-xm" 'mh-smail) +;;; (global-set-key "\C-x4m" 'mh-smail-other-window) + +;;; MH (Message Handler) is a powerful mail reader. The MH newsgroup +;;; is comp.mail.mh; the mailing list is mh-users@ics.uci.edu (send to +;;; mh-users-request to be added). See the monthly Frequently Asked +;;; Questions posting there for information on getting MH. + +;;; mh-e works with Emacs 18 or 19, and MH 5 or 6. + +;;; NB. MH must have been compiled with the MHE compiler flag or several +;;; features necessary mh-e will be missing from MH commands, specifically +;;; the -build switch to repl and forw. + +;;; Change Log: + +;;; Original version for Gosling emacs by Brian Reid, Stanford, 1982. +;;; Modified by James Larus, BBN, July 1984 and UCB, 1984 & 1985. +;;; Rewritten for GNU Emacs, James Larus 1985. larus@ginger.berkeley.edu +;;; Modified by Stephen Gildea 1988. gildea@lcs.mit.edu +(defconst mh-e-RCS-id "$Header: mh-e.el,v 3.14 94/03/14 18:34:49 gildea Exp $") + +;;; Code: + +(provide 'mh-e) +(require 'mh-utils) + + +;;; Site customization: + +;;; Set for local environment: +;;; mh-progs and mh-lib used to be set in paths.el, which tried to +;;; figure out at build time which of several possible directories MH +;;; was installed into. But if you installed MH after building Emacs, +;;; this would almost certainly be wrong, so now we do it at run time. + +(defvar mh-progs nil + "Directory containing MH commands, such as inc, repl, and rmm.") + +(defvar mh-lib nil + "Directory containing the MH library. +This directory contains, among other things, +the mhl program and the components file.") + +(defvar mh-redist-full-contents nil + "Non-nil if the `dist' command needs whole letter for redistribution. +This is the case when `send' is compiled with the BERK option. +If MH will not allow you to redist a previously redist'd msg, set to nil.") + +;;; Hooks: + +(defvar mh-folder-mode-hook nil + "Invoked in `mh-folder mode' on a new folder.") + +(defvar mh-inc-folder-hook nil + "Invoked by \\<mh-folder-mode-map>`\\[mh-inc-folder]' after incorporating mail into a folder.") + +(defvar mh-show-hook nil + "Invoked after \\<mh-folder-mode-map>`\\[mh-show]' shows a message.") + +(defvar mh-show-mode-hook nil + "Invoked in mh-show mode in each message.") + +(defvar mh-delete-msg-hook nil + "Invoked after marking each message for deletion.") + +(defvar mh-refile-msg-hook nil + "Invoked after marking each message for refiling.") + +(defvar mh-before-quit-hook nil + "Invoked by \\<mh-folder-mode-map>`\\[mh-quit]' before quitting mh-e. See also mh-quit-hook.") + +(defvar mh-quit-hook nil + "Invoked after \\<mh-folder-mode-map>`\\[mh-quit]' quits mh-e. See also mh-before-quit-hook.") + + + +;;; Personal preferences: + +(defvar mh-lpr-command-format "lpr -p -J '%s'" + "*Format for Unix command that prints a message. +The string should be a Unix command line, with the string '%s' where +the job's name (folder and message number) should appear. The formatted +message text is piped to this command when you type \\<mh-folder-mode-map>`\\[mh-print-msg]'.") + +(defvar mh-scan-prog "scan" + "*Program to run to generate one-line-per-message listing of a folder. +Normally \"scan\" or a file name linked to scan. This file is searched +for relative to the mh-progs directory unless it is an absolute pathname. +Automatically becomes buffer-local when set in any fashion.") +(make-variable-buffer-local 'mh-scan-prog) + +(defvar mh-inc-prog "inc" + "*Program to run to incorporate new mail into a folder. +Normally \"inc\". This file is searched for relative to +the mh-progs directory unless it is an absolute pathname.") + +(defvar mh-print-background nil + "*Print messages in the background if non-nil. +WARNING: do not delete the messages until printing is finished; +otherwise, your output may be truncated.") + +(defvar mh-recenter-summary-p nil + "*Recenter summary window when the show window is toggled off if non-nil.") + +(defvar mh-ins-buf-prefix "> " + "*String to put before each non-blank line of a yanked or inserted message. +\\<mh-letter-mode-map>Used when the message is inserted into an outgoing letter +by \\[mh-insert-letter] or \\[mh-yank-cur-msg].") + +(defvar mh-do-not-confirm nil + "*Non-nil means do not prompt for confirmation before some mh-e commands. +Affects non-recoverable commands such as mh-kill-folder and mh-undo-folder.") + +(defvar mh-store-default-directory nil + "*Last directory used by \\[mh-store-msg]; default for next store. +A directory name string, or nil to use current directory.") + +;;; Parameterize mh-e to work with different scan formats. The defaults work +;;; with the standard MH scan listings, in which the first 4 characters on +;;; the line are the message number, followed by two places for notations. + +(defvar mh-good-msg-regexp "^....[^D^]" + "Regexp specifiying the scan lines that are 'good' messages.") + +(defvar mh-deleted-msg-regexp "^....D" + "Regexp matching scan lines of deleted messages.") + +(defvar mh-refiled-msg-regexp "^....\\^" + "Regexp matching scan lines of refiled messages.") + +(defvar mh-valid-scan-line "^ *[0-9]" + "Regexp matching scan lines for messages (not error messages).") + +(defvar mh-flagged-scan-msg-regexp "^....\\D\\|^....\\^\\|^....\\+\\|^.....%" + "Regexp matching flagged scan lines. +Matches lines marked as deleted, refiled, in a sequence, or the cur message.") + +(defvar mh-cur-scan-msg-regexp "^....\\+" + "Regexp matching scan line for the cur message.") + +(defvar mh-show-buffer-mode-line-buffer-id "{show-%s} %d" + "Format string to produce `mode-line-buffer-identification' for show buffers. +First argument is folder name. Second is message number.") + +(defvar mh-partial-folder-mode-line-annotation "select" + "Annotation when displaying part of a folder. +The string is displayed after the folder's name. NIL for no annotation.") + + +;;; Internal variables: + +(defvar mh-last-destination nil + "Destination of last refile or write command.") + +(defvar mh-folder-mode-map (make-keymap) + "Keymap for MH folders.") + +(defvar mh-next-seq-num nil + "Index of free sequence id.") + +(defvar mh-delete-list nil + "List of msg numbers to delete.") + +(defvar mh-refile-list nil + "List of folder names in mh-seq-list.") + +(defvar mh-next-direction 'forward + "Direction to move to next message.") + +(defvar mh-narrowed-to-seq nil + "Sequence display is narrowed to.") + +(defvar mh-first-msg-num nil + "Number of first msg in buffer.") + +(defvar mh-last-msg-num nil + "Number of last msg in buffer.") + + +;;; Macros and generic functions: + +(defun mh-mapc (func list) + (while list + (funcall func (car list)) + (setq list (cdr list)))) + + + +;;; Entry points: + +;;;###autoload +(defun mh-rmail (&optional arg) + "Inc(orporate) new mail with MH, or, with arg, scan an MH mail folder. +This function is an entry point to mh-e, the Emacs front end +to the MH mail system." + (interactive "P") + (mh-find-path) + (if arg + (call-interactively 'mh-visit-folder) + (mh-inc-folder))) + + +;;; mh-smail and mh-smail-other-window have been moved to the new file +;;; mh-comp.el, but Emacs 18 still looks for them here, so provide a +;;; definition here, too, for a while. + +(defun mh-smail () + "Compose and send mail with the MH mail system. +This function is an entry point to mh-e, the Emacs front end +to the MH mail system." + (interactive) + (mh-find-path) + (require 'mh-comp) + (call-interactively 'mh-send)) + + +(defun mh-smail-other-window () + "Compose and send mail in other window with the MH mail system. +This function is an entry point to mh-e, the Emacs front end +to the MH mail system." + (interactive) + (mh-find-path) + (require 'mh-comp) + (call-interactively 'mh-send-other-window)) + + + +;;; User executable mh-e commands: + + +(defun mh-delete-msg (msg-or-seq) + "Mark the specified MESSAGE(s) for subsequent deletion and move to the next. +Default is the displayed message. If optional prefix argument is +given then prompt for the message sequence." + (interactive (list (if current-prefix-arg + (mh-read-seq-default "Delete" t) + (mh-get-msg-num t)))) + (mh-delete-msg-no-motion msg-or-seq) + (mh-next-msg)) + + +(defun mh-delete-msg-no-motion (msg-or-seq) + "Mark the specified MESSAGE(s) for subsequent deletion. +Default is the displayed message. If optional prefix argument is +provided, then prompt for the message sequence." + (interactive (list (if current-prefix-arg + (mh-read-seq-default "Delete" t) + (mh-get-msg-num t)))) + (if (numberp msg-or-seq) + (mh-delete-a-msg msg-or-seq) + (mh-map-to-seq-msgs 'mh-delete-a-msg msg-or-seq))) + + +(defun mh-execute-commands () + "Process outstanding delete and refile requests." + (interactive) + (if mh-narrowed-to-seq (mh-widen)) + (mh-process-commands mh-current-folder) + (mh-set-scan-mode) + (mh-goto-cur-msg) ; after mh-set-scan-mode for efficiency + (mh-make-folder-mode-line) + t) ; return t for write-file-hooks + + +(defun mh-first-msg () + "Move to the first message." + (interactive) + (goto-char (point-min))) + + +(defun mh-header-display () + "Show the current message with all its headers. +Displays headers that might have been suppressed by mh-clean-message-header, +mhl-formfile, or the fallback behavior of scrolling uninteresting headers +off the top of the window. Type \"\\[mh-show]\" to show the message +normally again." + (interactive) + (and (not mh-showing-with-headers) + (or mhl-formfile mh-clean-message-header) + (mh-invalidate-show-buffer)) + (let ((mhl-formfile nil) + (mh-clean-message-header nil)) + (mh-show-msg nil) + (mh-in-show-buffer (mh-show-buffer) + (goto-char (point-min)) + (mh-recenter 0)) + (setq mh-showing-with-headers t))) + + +(defun mh-inc-folder (&optional maildrop-name) + "Inc(orporate)s new mail into +inbox. +Optional prefix argument specifies an alternate maildrop from the default. +If this is given, incorporates mail into the current folder, rather +than +inbox. Runs `mh-inc-folder-hook' after incorporating new mail. +Do not call this function from outside mh-e; use \\[mh-rmail] instead." + (interactive (list (if current-prefix-arg + (expand-file-name + (read-file-name "inc mail from file: " + mh-user-path))))) + (let ((config (current-window-configuration))) + (if (not maildrop-name) + (cond ((not (get-buffer "+inbox")) + (mh-make-folder "+inbox") + (setq mh-previous-window-config config)) + ((not (eq (current-buffer) (get-buffer "+inbox"))) + (switch-to-buffer "+inbox") + (setq mh-previous-window-config config))))) + (mh-get-new-mail maildrop-name) + (run-hooks 'mh-inc-folder-hook)) + + +(defun mh-last-msg () + "Move to the last message." + (interactive) + (goto-char (point-max)) + (while (and (not (bobp)) (looking-at "^$")) + (forward-line -1))) + + +(defun mh-next-undeleted-msg (&optional arg) + "Move to next undeleted message in window." + (interactive "P") + (forward-line (prefix-numeric-value arg)) + (setq mh-next-direction 'forward) + (cond ((re-search-forward mh-good-msg-regexp nil 0 arg) + (beginning-of-line) + (mh-maybe-show)) + (t + (forward-line -1) + (if (get-buffer mh-show-buffer) + (delete-windows-on mh-show-buffer))))) + + +(defun mh-refile-msg (msg-or-seq dest) + "Refile MESSAGE(s) (default: displayed message) in FOLDER. +If optional prefix argument provided, then prompt for message sequence." + (interactive + (list (if current-prefix-arg + (mh-read-seq-default "Refile" t) + (mh-get-msg-num t)) + (intern + (mh-prompt-for-folder + "Destination" + (or (and mh-msg-folder-hook + (let ((file-name (mh-msg-filename (mh-get-msg-num t)))) + (save-excursion + (set-buffer (get-buffer-create " *mh-temp*")) + (erase-buffer) + (insert-file-contents file-name) + (let ((buffer-file-name file-name)) + (funcall mh-msg-folder-hook))))) + (and (eq 'refile (car mh-last-destination)) + (symbol-name (cdr mh-last-destination))) + "") + t)))) + (setq mh-last-destination (cons 'refile dest)) + (if (numberp msg-or-seq) + (mh-refile-a-msg msg-or-seq dest) + (mh-map-to-seq-msgs 'mh-refile-a-msg msg-or-seq dest)) + (mh-next-msg)) + + +(defun mh-refile-or-write-again (msg) + "Re-execute the last refile or write command on the given MESSAGE. +Default is the displayed message. Use the same folder or file as the +previous refile or write command." + (interactive (list (mh-get-msg-num t))) + (if (null mh-last-destination) + (error "No previous refile or write")) + (cond ((eq (car mh-last-destination) 'refile) + (mh-refile-a-msg msg (cdr mh-last-destination)) + (message "Destination folder: %s" (cdr mh-last-destination))) + (t + (apply 'mh-write-msg-to-file msg (cdr mh-last-destination)) + (message "Destination: %s" (cdr mh-last-destination)))) + (mh-next-msg)) + + +(defun mh-quit () + "Quit mh-e. +Start by running mh-before-quit-hook. Restore the previous window +configuration, if one exists. Finish by running mh-quit-hook." + (interactive) + (run-hooks 'mh-before-quit-hook) + (mh-update-unseen) + (mh-invalidate-show-buffer) + (bury-buffer (current-buffer)) + (if (get-buffer mh-show-buffer) + (bury-buffer mh-show-buffer)) + (if mh-previous-window-config + (set-window-configuration mh-previous-window-config)) + (run-hooks 'mh-quit-hook)) + +(defun mh-page-msg (&optional arg) + "Page the displayed message forwards. +Scrolls ARG lines or a full screen if no argument is supplied." + (interactive "P") + (scroll-other-window arg)) + + +(defun mh-previous-page (&optional arg) + "Page the displayed message backwards. +Scrolls ARG lines or a full screen if no argument is supplied." + (interactive "P") + (mh-in-show-buffer (mh-show-buffer) + (scroll-down arg))) + + +(defun mh-previous-undeleted-msg (&optional arg) + "Move to previous undeleted message in window." + (interactive "p") + (setq mh-next-direction 'backward) + (beginning-of-line) + (cond ((re-search-backward mh-good-msg-regexp nil 0 arg) + (mh-maybe-show)) + (t + (if (get-buffer mh-show-buffer) + (delete-windows-on mh-show-buffer))))) + + +(defun mh-rescan-folder (&optional range) + "Rescan a folder after optionally processing the outstanding commands. +If optional prefix argument is provided, prompt for the range of +messages to display. Otherwise show the entire folder." + (interactive (list (if current-prefix-arg + (mh-read-msg-range "Range to scan [all]? ") + nil))) + (setq mh-next-direction 'forward) + (mh-scan-folder mh-current-folder (or range "all"))) + + +(defun mh-write-msg-to-file (msg file no-headers) + "Append MESSAGE to the end of a FILE. +If NO-HEADERS (prefix argument) is provided, write only the message body. +Otherwise send the entire message including the headers." + (interactive + (list (mh-get-msg-num t) + (let ((default-dir (if (eq 'write (car mh-last-destination)) + (file-name-directory (car (cdr mh-last-destination))) + default-directory))) + (read-file-name "Save message in file: " default-dir + (expand-file-name "mail.out" default-dir))) + current-prefix-arg)) + (let ((file-name (mh-msg-filename msg)) + (output-file (mh-expand-file-name file))) + (setq mh-last-destination (list 'write file no-headers)) + (save-excursion + (set-buffer (get-buffer-create " *mh-temp*")) + (erase-buffer) + (insert-file-contents file-name) + (goto-char (point-min)) + (if no-headers (search-forward "\n\n")) + (append-to-file (point) (point-max) output-file)))) + + +(defun mh-toggle-showing () + "Toggle the scanning mode/showing mode of displaying messages." + (interactive) + (if mh-showing + (mh-set-scan-mode) + (mh-show))) + + +(defun mh-undo (msg-or-seq) + "Undo the deletion or refile of the specified MESSAGE(s). +Default is the displayed message. If optional prefix argument is +provided, then prompt for the message sequence." + (interactive (list (if current-prefix-arg + (mh-read-seq-default "Undo" t) + (mh-get-msg-num t)))) + (cond ((numberp msg-or-seq) + (let ((original-position (point))) + (beginning-of-line) + (while (not (or (looking-at mh-deleted-msg-regexp) + (looking-at mh-refiled-msg-regexp) + (and (eq mh-next-direction 'forward) (bobp)) + (and (eq mh-next-direction 'backward) + (save-excursion (forward-line) (eobp))))) + (forward-line (if (eq mh-next-direction 'forward) -1 1))) + (if (or (looking-at mh-deleted-msg-regexp) + (looking-at mh-refiled-msg-regexp)) + (progn + (mh-undo-msg (mh-get-msg-num t)) + (mh-maybe-show)) + (goto-char original-position) + (error "Nothing to undo")))) + (t + (mh-mapc (function mh-undo-msg) (mh-seq-to-msgs msg-or-seq)))) + ;; update the mh-refile-list so mh-outstanding-commands-p will work + (mh-mapc (function + (lambda (elt) + (if (not (mh-seq-to-msgs elt)) + (setq mh-refile-list (delq elt mh-refile-list))))) + mh-refile-list) + (if (not (mh-outstanding-commands-p)) + (mh-set-folder-modified-p nil))) + + +(defun mh-version () + "Display version information about mh-e and MH." + (interactive) + (mh-find-progs) + (set-buffer (get-buffer-create " *mh-temp*")) + (erase-buffer) + (insert " mh-e info:\n\nversion: " mh-e-version "\n" mh-e-time-stamp + "\nEmacs: " emacs-version " on " (symbol-name system-type) " ") + (condition-case () + (call-process "uname" nil t nil "-a") + (file-error)) + (insert "\n\n MH info:\n\n" (expand-file-name "inc" mh-progs) ":\n") + (let ((help-start (point))) + (condition-case err-data + (mh-exec-cmd-output "inc" nil "-help") + (file-error (insert (mapconcat 'concat (cdr err-data) ": ")))) + (goto-char help-start) + (search-forward "version: " nil t) + (beginning-of-line) + (delete-region help-start (point)) + (goto-char (point-min))) + (display-buffer " *mh-temp*")) + + +(defun mh-visit-folder (folder &optional range) + "Visits FOLDER and displays RANGE of messages. +Assumes mh-e has already been initialized. +Do not call this function from outside mh-e; see \\[mh-rmail] instead." + (interactive (list (mh-prompt-for-folder "Visit" "+inbox" t) + (mh-read-msg-range "Range [all]? "))) + (let ((config (current-window-configuration))) + (mh-scan-folder folder (or range "all")) + (setq mh-previous-window-config config)) + nil) + + +(defun mh-compat-quit () + "\"b\" reserved for future use as mh-burst-digest; will assume you want \"\\[mh-quit]\" ..." + ;; This is a temporary compatibility function + (interactive) + (message "%s" (documentation this-command)) + (sit-for 1) + (call-interactively 'mh-quit)) + + + +;;; Support routines. + +(defun mh-delete-a-msg (msg) + ;; Delete the MESSAGE. + (save-excursion + (mh-goto-msg msg nil t) + (if (looking-at mh-refiled-msg-regexp) + (error "Message %d is refiled. Undo refile before deleting." msg)) + (if (looking-at mh-deleted-msg-regexp) + nil + (mh-set-folder-modified-p t) + (setq mh-delete-list (cons msg mh-delete-list)) + (mh-add-msgs-to-seq msg 'deleted t) + (mh-notate msg ?D mh-cmd-note) + (run-hooks 'mh-delete-msg-hook)))) + +(defun mh-refile-a-msg (msg destination) + ;; Refile MESSAGE in FOLDER. FOLDER is a symbol, not a string. + (save-excursion + (mh-goto-msg msg nil t) + (cond ((looking-at mh-deleted-msg-regexp) + (error "Message %d is deleted. Undo delete before moving." msg)) + ((looking-at mh-refiled-msg-regexp) + (if (y-or-n-p + (format "Message %d already refiled. Copy to %s as well? " + msg destination)) + (mh-exec-cmd "refile" (mh-get-msg-num t) "-link" + "-src" mh-current-folder + (symbol-name destination)) + (message "Message not copied."))) + (t + (mh-set-folder-modified-p t) + (if (not (memq destination mh-refile-list)) + (setq mh-refile-list (cons destination mh-refile-list))) + (if (not (memq msg (mh-seq-to-msgs destination))) + (mh-add-msgs-to-seq msg destination t)) + (mh-notate msg ?^ mh-cmd-note) + (run-hooks 'mh-refile-msg-hook))))) + + +(defun mh-next-msg () + ;; Move backward or forward to the next undeleted message in the buffer. + (if (eq mh-next-direction 'forward) + (mh-next-undeleted-msg 1) + (mh-previous-undeleted-msg 1))) + + +(defun mh-set-scan-mode () + ;; Display the scan listing buffer, but do not show a message. + (if (get-buffer mh-show-buffer) + (delete-windows-on mh-show-buffer)) + (setq mh-showing nil) + (set-buffer-modified-p (buffer-modified-p)) ;force mode line update + (if mh-recenter-summary-p + (mh-recenter nil))) + + +(defun mh-undo-msg (msg) + ;; Undo the deletion or refile of one MESSAGE. + (cond ((memq msg mh-delete-list) + (setq mh-delete-list (delq msg mh-delete-list)) + (mh-delete-msg-from-seq msg 'deleted t)) + (t + (mh-mapc (function (lambda (dest) + (mh-delete-msg-from-seq msg dest t))) + mh-refile-list))) + (mh-notate msg ? mh-cmd-note)) + + + + +;;; The folder data abstraction. + +(defun mh-make-folder (name) + ;; Create and initialize a new mail folder called NAME and make it the + ;; current folder. + (switch-to-buffer name) + (setq buffer-read-only nil) + (erase-buffer) + (setq buffer-read-only t) + (mh-folder-mode) + (mh-set-folder-modified-p nil) + (setq buffer-file-name mh-folder-filename)) + + +;;; Ensure new buffers won't get this mode if default-major-mode is nil. +(put 'mh-folder-mode 'mode-class 'special) + +(defun mh-folder-mode () + "Major mh-e mode for \"editing\" an MH folder scan listing.\\<mh-folder-mode-map> +You can show the message the cursor is pointing to, and step through the +messages. Messages can be marked for deletion or refiling into another +folder; these commands are executed all at once with a separate command. + +A prefix argument (\\[universal-argument]) to delete, refile, list, or undo +applies the action to a message sequence. + +Here is a list of the standard keys for mh-e commands, grouped by function. +This list is purposefully not customized; mh-e has a long history, and many +alternate key bindings as a result. This list is to encourage users to use +standard keys so the other keys can perhaps someday be put to new uses. + +t toggle show or scan-only mode +. show message, or back to top if already showing + +SPC page forward +DEL page back + +n next message +p previous message +j jump to message by number + +d mark for deletion +o, ^ mark for output (refile) to another folder +? show folder of pending refile +u undo delete or refile marking + +x execute marked deletes and refiles +i incorporate new mail + +m mail a new message +r reply to a message +f forward a message + +q quit mh-e + +M-f visit new folder +M-r rescan this folder + +Here are all the commands with their current binding, listed in key order: +\\{mh-folder-mode-map} + +Variables controlling mh-e operation are (defaults in parentheses): + + mh-recursive-folders (nil) + Non-nil means commands which operate on folders do so recursively. + + mh-bury-show-buffer (t) + Non-nil means that the buffer used to display message is buried. + It will never be offered as the default other buffer. + + mh-clean-message-header (nil) + Non-nil means remove header lines matching the regular expression + specified in mh-invisible-headers from messages. + + mh-visible-headers (nil) + If non-nil, it contains a regexp specifying the headers that are shown in + a message if mh-clean-message-header is non-nil. Setting this variable + overrides mh-invisible-headers. + + mh-do-not-confirm (nil) + Non-nil means do not prompt for confirmation before executing some + non-recoverable commands such as mh-kill-folder and mh-undo-folder. + + mhl-formfile (nil) + Name of format file to be used by mhl to show messages. + A value of T means use the default format file. + Nil means don't use mhl to format messages. + + mh-lpr-command-format (\"lpr -p -J '%s'\") + Format for command used to print a message on a system printer. + + mh-scan-prog (\"scan\") + Program to run to generate one-line-per-message listing of a folder. + Normally \"scan\" or a file name linked to scan. This file is searched + for relative to the mh-progs directory unless it is an absolute pathname. + Automatically becomes buffer-local when set in any fashion. + + mh-print-background (nil) + Print messages in the background if non-nil. + WARNING: do not delete the messages until printing is finished; + otherwise, your output may be truncated. + + mh-recenter-summary-p (nil) + If non-nil, then the scan listing is recentered when the window displaying + a messages is toggled off. + + mh-summary-height (4) + Number of lines in the summary window including the mode line. + + mh-ins-buf-prefix (\"> \") + String to insert before each non-blank line of a message as it is + inserted in a draft letter. + +The value of mh-folder-mode-hook is called when a new folder is set up." + + (kill-all-local-variables) + (use-local-map mh-folder-mode-map) + (setq major-mode 'mh-folder-mode) + (mh-set-mode-name "MH-Folder") + (make-local-vars + 'mh-current-folder (buffer-name) ; Name of folder, a string + 'mh-show-buffer (format "show-%s" (buffer-name)) ; Buffer that displays msgs + 'mh-folder-filename ; e.g. "/usr/foobar/Mail/inbox/" + (file-name-as-directory (mh-expand-file-name (buffer-name))) + 'mh-showing nil ; Show message also? + 'mh-next-seq-num 0 ; Index of free sequence id + 'mh-delete-list nil ; List of msgs nums to delete + 'mh-refile-list nil ; List of folder names in mh-seq-list + 'mh-seq-list nil ; Alist of (seq . msgs) nums + 'mh-seen-list nil ; List of displayed messages + 'mh-next-direction 'forward ; Direction to move to next message + 'mh-narrowed-to-seq nil ; Sequence display is narrowed to + 'mh-first-msg-num nil ; Number of first msg in buffer + 'mh-last-msg-num nil ; Number of last msg in buffer + 'mh-previous-window-config nil) ; Previous window configuration + (setq truncate-lines t) + (auto-save-mode -1) + (setq buffer-offer-save t) + (make-local-variable 'write-file-hooks) + (setq write-file-hooks '(mh-execute-commands)) + (make-local-variable 'revert-buffer-function) + (setq revert-buffer-function 'mh-undo-folder) + (or (assq 'mh-showing minor-mode-alist) + (setq minor-mode-alist + (cons '(mh-showing " Show") minor-mode-alist))) + (run-hooks 'mh-folder-mode-hook)) + + +(defun make-local-vars (&rest pairs) + ;; Take VARIABLE-VALUE pairs and makes local variables initialized to the + ;; value. + (while pairs + (make-variable-buffer-local (car pairs)) + (set (car pairs) (car (cdr pairs))) + (setq pairs (cdr (cdr pairs))))) + + +(defun mh-scan-folder (folder range) + ;; Scan the FOLDER over the RANGE. Return in the folder's buffer. + (cond ((null (get-buffer folder)) + (mh-make-folder folder)) + (t + (mh-process-or-undo-commands folder) + (switch-to-buffer folder))) + (mh-regenerate-headers range) + (cond ((zerop (buffer-size)) + (if (equal range "all") + (message "Folder %s is empty" folder) + (message "No messages in %s, range %s" folder range)) + (sit-for 5))) + (mh-goto-cur-msg)) + + +(defun mh-regenerate-headers (range) + ;; Replace buffer with scan of its contents over range RANGE. + (let ((folder mh-current-folder)) + (message "Scanning %s..." folder) + (with-mh-folder-updating (nil) + (erase-buffer) + (mh-exec-cmd-output mh-scan-prog nil + "-noclear" "-noheader" + "-width" (window-width) + folder range) + (goto-char (point-min)) + (cond ((looking-at "scan: no messages in") + (keep-lines mh-valid-scan-line)) ; Flush random scan lines + ((looking-at "scan: ")) ; Keep error messages + (t + (keep-lines mh-valid-scan-line))) ; Flush random scan lines + (mh-delete-seq-locally 'cur) ; To pick up new one + (setq mh-seq-list (mh-read-folder-sequences folder nil)) + (mh-notate-user-sequences) + (mh-make-folder-mode-line (if (equal range "all") + nil + mh-partial-folder-mode-line-annotation))) + (message "Scanning %s...done" folder))) + + +(defun mh-get-new-mail (maildrop-name) + ;; Read new mail from a maildrop into the current buffer. + ;; Return in the current buffer. + (let ((point-before-inc (point)) + (folder mh-current-folder) + (new-mail-p nil)) + (with-mh-folder-updating (t) + (message (if maildrop-name + (format "inc %s -file %s..." folder maildrop-name) + (format "inc %s..." folder))) + (setq mh-next-direction 'forward) + (goto-char (point-max)) + (let ((start-of-inc (point))) + (if maildrop-name + (mh-exec-cmd-output mh-inc-prog nil folder + "-file" (expand-file-name maildrop-name) + "-width" (window-width) + "-truncate") + (mh-exec-cmd-output "inc" nil + "-width" (window-width))) + (message + (if maildrop-name + (format "inc %s -file %s...done" folder maildrop-name) + (format "inc %s...done" folder))) + (goto-char start-of-inc) + (cond ((looking-at "inc: no mail") + (message "No new mail%s%s" (if maildrop-name " in " "") + (if maildrop-name maildrop-name ""))) + ((re-search-forward "^inc:" nil t) ; Error messages + (error "inc error")) + (t + ;; remove old cur notation (cf mh-goto-cur-msg code) + (let ((cur-msg (car (mh-seq-to-msgs 'cur)))) + (save-excursion + (and cur-msg + (mh-goto-msg cur-msg t nil) + (looking-at mh-cur-scan-msg-regexp) + (mh-notate nil ? mh-cmd-note)))) + (setq new-mail-p t))) + (keep-lines mh-valid-scan-line) ; Flush random scan lines + (mh-delete-seq-locally 'cur) ; To pick up new one + (setq mh-seq-list (mh-read-folder-sequences folder t)) + (mh-notate-user-sequences) + (if new-mail-p + (progn + (mh-goto-cur-msg) + (mh-make-folder-mode-line)) + (goto-char point-before-inc)))))) + + +(defun mh-make-folder-mode-line (&optional annotation) + ;; Set the fields of the mode line for a folder buffer. + ;; The optional ANNOTATION string is displayed after the folder's name. + (save-excursion + (mh-first-msg) + (setq mh-first-msg-num (mh-get-msg-num nil)) + (mh-last-msg) + (setq mh-last-msg-num (mh-get-msg-num nil)) + (let ((lines (count-lines (point-min) (point-max)))) + (setq mode-line-buffer-identification + (list (format "{%%b%s} %d msg%s" + (if annotation (format "/%s" annotation) "") + lines + (if (zerop lines) + "s" + (if (> lines 1) + (format "s (%d-%d)" mh-first-msg-num + mh-last-msg-num) + (format " (%d)" mh-first-msg-num))))))))) + + +(defun mh-unmark-all-headers (remove-all-flags) + ;; Remove all '+' flags from the headers, and if called with a non-nil + ;; argument, remove all 'D', '^' and '%' flags too. + ;; Optimized for speed (i.e., no regular expressions). + (save-excursion + (let ((case-fold-search nil) + (last-line (- (point-max) mh-cmd-note)) + char) + (mh-first-msg) + (while (<= (point) last-line) + (forward-char mh-cmd-note) + (setq char (following-char)) + (if (or (and remove-all-flags + (or (eql char ?D) + (eql char ?^) + (eql char ?%))) + (eql char ?+)) + (progn + (delete-char 1) + (insert " "))) + (forward-line))))) + + +(defun mh-goto-cur-msg () + ;; Position the cursor at the current message. + (let ((cur-msg (car (mh-seq-to-msgs 'cur)))) + (cond ((and cur-msg + (mh-goto-msg cur-msg t nil)) + (mh-notate nil ?+ mh-cmd-note) + (mh-recenter 0) + (mh-maybe-show cur-msg)) + (t + (mh-last-msg) + (message "No current message"))))) + + +(defun mh-process-or-undo-commands (folder) + ;; If FOLDER has outstanding commands, then either process or discard them. + ;; Called by functions like mh-sort-folder, so also invalidate show buffer. + (set-buffer folder) + (if (mh-outstanding-commands-p) + (if (or mh-do-not-confirm + (y-or-n-p + "Process outstanding deletes and refiles (or lose them)? ")) + (mh-process-commands folder) + (mh-undo-folder))) + (mh-update-unseen) + (mh-invalidate-show-buffer)) + + +(defun mh-process-commands (folder) + ;; Process outstanding commands for the folder FOLDER. + (message "Processing deletes and refiles for %s..." folder) + (set-buffer folder) + (with-mh-folder-updating (nil) + ;; Update the unseen sequence if it exists + (mh-update-unseen) + + ;; Then refile messages + (mh-mapc + (function + (lambda (dest) + (let ((msgs (mh-seq-to-msgs dest))) + (cond (msgs + (apply 'mh-exec-cmd "refile" + "-src" folder (symbol-name dest) msgs) + (mh-delete-scan-msgs msgs)))))) + mh-refile-list) + (setq mh-refile-list nil) + + ;; Now delete messages + (cond (mh-delete-list + (apply 'mh-exec-cmd "rmm" folder mh-delete-list) + (mh-delete-scan-msgs mh-delete-list) + (setq mh-delete-list nil))) + + ;; Don't need to remove sequences since delete and refile do so. + + ;; Mark cur message + (if (> (buffer-size) 0) + (mh-define-sequence 'cur (or (mh-get-msg-num nil) "last"))) + + (and (buffer-file-name (get-buffer mh-show-buffer)) + (not (file-exists-p (buffer-file-name (get-buffer mh-show-buffer)))) + ;; If "inc" were to put a new msg in this file, + ;; we would not notice, so mark it invalid now. + (mh-invalidate-show-buffer)) + + (setq mh-seq-list (mh-read-folder-sequences mh-current-folder nil)) + (mh-unmark-all-headers t) + (mh-notate-user-sequences) + (message "Processing deletes and refiles for %s...done" folder))) + + +(defun mh-update-unseen () + ;; Push updates to the Unseen sequence out to MH. + (if mh-seen-list + (progn + (if (mh-seq-to-msgs mh-unseen-seq) + (mh-undefine-sequence mh-unseen-seq mh-seen-list)) + (setq mh-seen-list nil)))) + + +(defun mh-delete-scan-msgs (msgs) + ;; Delete the scan listing lines for each of the msgs in the LIST. + ;; Optimized for speed (i.e., no regular expressions). + (setq msgs (sort msgs (function <))) ;okay to clobber msgs + (save-excursion + (mh-first-msg) + (while (and msgs (< (point) (point-max))) + (cond ((equal (mh-get-msg-num nil) (car msgs)) + (delete-region (point) (save-excursion (forward-line) (point))) + (setq msgs (cdr msgs))) + (t + (forward-line)))))) + + +(defun mh-outstanding-commands-p () + ;; Returns non-nil if there are outstanding deletes or refiles. + (or mh-delete-list mh-refile-list)) + + + +;;; Basic sequence handling + +(defun mh-delete-seq-locally (seq) + ;; Remove mh-e's record of SEQUENCE. + (let ((entry (mh-find-seq seq))) + (setq mh-seq-list (delq entry mh-seq-list)))) + +(defun mh-read-folder-sequences (folder save-refiles) + ;; Read and return the predefined sequences for a FOLDER. + ;; If SAVE-REFILES is non-nil, then keep the sequences + ;; that note messages to be refiled. + (let ((seqs ())) + (cond (save-refiles + (mh-mapc (function (lambda (seq) ; Save the refiling sequences + (if (mh-folder-name-p (mh-seq-name seq)) + (setq seqs (cons seq seqs))))) + mh-seq-list))) + (save-excursion + (if (eq 0 (mh-exec-cmd-quiet nil "mark" folder "-list")) + (progn + ;; look for name in line of form "cur: 4" or "myseq (private): 23" + (while (re-search-forward "^[^: ]+" nil t) + (setq seqs (cons (mh-make-seq (intern (buffer-substring + (match-beginning 0) + (match-end 0))) + (mh-read-msg-list)) + seqs))) + (delete-region (point-min) (point))))) ; avoid race with mh-process-daemon + seqs)) + +(defun mh-read-msg-list () + ;; Return a list of message numbers from the current point to the end of + ;; the line. + (let ((msgs ()) + (end-of-line (save-excursion (end-of-line) (point))) + num) + (while (re-search-forward "[0-9]+" end-of-line t) + (setq num (string-to-int (buffer-substring (match-beginning 0) + (match-end 0)))) + (cond ((looking-at "-") ; Message range + (forward-char 1) + (re-search-forward "[0-9]+" end-of-line t) + (let ((num2 (string-to-int (buffer-substring (match-beginning 0) + (match-end 0))))) + (if (< num2 num) + (error "Bad message range: %d-%d" num num2)) + (while (<= num num2) + (setq msgs (cons num msgs)) + (setq num (1+ num))))) + ((not (zerop num)) (setq msgs (cons num msgs))))) + msgs)) + +(defun mh-notate-user-sequences () + ;; Mark the scan listing of all messages in user-defined sequences. + (let ((seqs mh-seq-list) + name) + (while seqs + (setq name (mh-seq-name (car seqs))) + (if (not (mh-internal-seq name)) + (mh-notate-seq name ?% (1+ mh-cmd-note))) + (setq seqs (cdr seqs))))) + + +(defun mh-internal-seq (name) + ;; Return non-NIL if NAME is the name of an internal mh-e sequence. + (or (memq name '(answered cur deleted forwarded printed)) + (eq name mh-unseen-seq) + (eq name mh-previous-seq) + (mh-folder-name-p name))) + + +(defun mh-delete-msg-from-seq (msg seq &optional internal-flag) + "Delete MESSAGE from SEQUENCE. MESSAGE defaults to displayed message. + From Lisp, optional third arg INTERNAL non-nil means do not + inform MH of the change." + (interactive (list (mh-get-msg-num t) + (mh-read-seq-default "Delete from" t) + nil)) + (let ((entry (mh-find-seq seq))) + (cond (entry + (mh-notate-if-in-one-seq msg ? (1+ mh-cmd-note) (mh-seq-name entry)) + (if (not internal-flag) + (mh-undefine-sequence seq msg)) + (setcdr entry (delq msg (mh-seq-msgs entry))))))) + + +(defun mh-undefine-sequence (seq msgs) + ;; Remove from the SEQUENCE the MSGS, which may be a list or single msg. + (mh-exec-cmd "mark" mh-current-folder "-delete" + "-sequence" (symbol-name seq) + msgs)) + + +(defun mh-define-sequence (seq msgs) + ;; Define the SEQUENCE to contain the list of MSGS. + ;; Do not mark pseudo-sequences or empty sequences. + ;; Signals an error if SEQUENCE is an illegal name. + (if (and msgs + (not (mh-folder-name-p seq))) + (save-excursion + (mh-exec-cmd-error nil "mark" mh-current-folder "-add" "-zero" + "-sequence" (symbol-name seq) + msgs)))) + + +(defun mh-define-sequences (seq-list) + ;; Define the sequences in SEQ-LIST. + (mh-map-over-seqs 'mh-define-sequence seq-list)) + + +(defun mh-map-over-seqs (func seq-list) + ;; Apply the FUNCTION to each element in the list of SEQUENCES, + ;; passing the sequence name and the list of messages as arguments. + (while seq-list + (funcall func (mh-seq-name (car seq-list)) (mh-seq-msgs (car seq-list))) + (setq seq-list (cdr seq-list)))) + + +(defun mh-notate-if-in-one-seq (msg notation offset seq) + ;; If the MESSAGE is in only the SEQUENCE, then mark the scan listing of the + ;; message with the CHARACTER at the given OFFSET from the beginning of the + ;; listing line. + (let ((in-seqs (mh-seq-containing-msg msg))) + (if (and (eq seq (car in-seqs)) (null (cdr in-seqs))) + (mh-notate msg notation offset)))) + + +(defun mh-seq-containing-msg (msg) + ;; Return a list of the sequences containing MESSAGE. + (let ((l mh-seq-list) + (seqs ())) + (while l + (if (memq msg (mh-seq-msgs (car l))) + (setq seqs (cons (mh-seq-name (car l)) seqs))) + (setq l (cdr l))) + seqs)) + + + + +;;; User prompting commands. + + +(defun mh-read-msg-range (prompt) + ;; Read a list of blank-separated items. + (let* ((buf (read-string prompt)) + (buf-size (length buf)) + (start 0) + (input ())) + (while (< start buf-size) + (let ((next (read-from-string buf start buf-size))) + (setq input (cons (car next) input)) + (setq start (cdr next)))) + (nreverse input))) + + + +;;; Build the folder-mode keymap: + +(suppress-keymap mh-folder-mode-map) +(define-key mh-folder-mode-map "q" 'mh-quit) +(define-key mh-folder-mode-map "b" 'mh-compat-quit) +(define-key mh-folder-mode-map "?" 'mh-msg-is-in-seq) +(define-key mh-folder-mode-map "%" 'mh-put-msg-in-seq) +(define-key mh-folder-mode-map "|" 'mh-pipe-msg) +(define-key mh-folder-mode-map "\ea" 'mh-edit-again) +(define-key mh-folder-mode-map "\e%" 'mh-delete-msg-from-seq) +(define-key mh-folder-mode-map "\e#" 'mh-delete-seq) +(define-key mh-folder-mode-map "\C-xn" 'mh-narrow-to-seq) +(define-key mh-folder-mode-map "\C-xw" 'mh-widen) +(define-key mh-folder-mode-map "\eb" 'mh-burst-digest) +(define-key mh-folder-mode-map "\eu" 'mh-undo-folder) +(define-key mh-folder-mode-map "\e " 'mh-page-digest) +(define-key mh-folder-mode-map "\e\177" 'mh-page-digest-backwards) +(define-key mh-folder-mode-map "\ed" 'mh-redistribute) +(define-key mh-folder-mode-map "\ee" 'mh-extract-rejected-mail) +(define-key mh-folder-mode-map "\ef" 'mh-visit-folder) +(define-key mh-folder-mode-map "\ek" 'mh-kill-folder) +(define-key mh-folder-mode-map "\el" 'mh-list-folders) +(define-key mh-folder-mode-map "\en" 'mh-store-msg) +(define-key mh-folder-mode-map "\ep" 'mh-pack-folder) +(define-key mh-folder-mode-map "\eq" 'mh-list-sequences) +(define-key mh-folder-mode-map "\es" 'mh-search-folder) +(define-key mh-folder-mode-map "\er" 'mh-rescan-folder) +(define-key mh-folder-mode-map "l" 'mh-print-msg) +(define-key mh-folder-mode-map "t" 'mh-toggle-showing) +(define-key mh-folder-mode-map "c" 'mh-copy-msg) +(define-key mh-folder-mode-map "i" 'mh-inc-folder) +(define-key mh-folder-mode-map "x" 'mh-execute-commands) +(define-key mh-folder-mode-map "e" 'mh-execute-commands) +(define-key mh-folder-mode-map "f" 'mh-forward) +(define-key mh-folder-mode-map "m" 'mh-send) +(define-key mh-folder-mode-map "s" 'mh-send) +(define-key mh-folder-mode-map "r" 'mh-reply) +(define-key mh-folder-mode-map "a" 'mh-reply) +(define-key mh-folder-mode-map "j" 'mh-goto-msg) +(define-key mh-folder-mode-map "g" 'mh-goto-msg) +(define-key mh-folder-mode-map "\e>" 'mh-last-msg) +(define-key mh-folder-mode-map "\177" 'mh-previous-page) +(define-key mh-folder-mode-map " " 'mh-page-msg) +(define-key mh-folder-mode-map "." 'mh-show) +(define-key mh-folder-mode-map "," 'mh-header-display) +(define-key mh-folder-mode-map "u" 'mh-undo) +(define-key mh-folder-mode-map "d" 'mh-delete-msg) +(define-key mh-folder-mode-map "\C-d" 'mh-delete-msg-no-motion) +(define-key mh-folder-mode-map "p" 'mh-previous-undeleted-msg) +(define-key mh-folder-mode-map "n" 'mh-next-undeleted-msg) +(define-key mh-folder-mode-map "o" 'mh-refile-msg) +(define-key mh-folder-mode-map "^" 'mh-refile-msg) +(define-key mh-folder-mode-map "\C-o" 'mh-write-msg-to-file) +(define-key mh-folder-mode-map ">" 'mh-write-msg-to-file) +(define-key mh-folder-mode-map "!" 'mh-refile-or-write-again) + + + +;;;autoload the other mh-e parts + +;;; mh-comp + +(autoload 'mh-smail "mh-comp" + "Compose and send mail with the MH mail system." t) +(autoload 'mh-smail-other-window "mh-comp" + "Compose and send mail in other window with the MH mail system." t) +(autoload 'mh-edit-again "mh-comp" + "Clean-up a draft or a message previously sent and make it resendable." t) +(autoload 'mh-extract-rejected-mail "mh-comp" + "Extract a letter returned by the mail system and make it resendable." t) +(autoload 'mh-forward "mh-comp" + "Forward MESSAGE(s) (default: displayed message)." t) +(autoload 'mh-redistribute "mh-comp" + "Redistribute a letter." t) +(autoload 'mh-reply "mh-comp" + "Reply to a MESSAGE (default: displayed message)." t) +(autoload 'mh-send "mh-comp" + "Compose and send a letter." t) +(autoload 'mh-send-other-window "mh-comp" + "Compose and send a letter in another window." t) +(autoload 'mh-letter-mode "mh-comp" + "Mode for composing letters in mh-e." t) + + +;;; mh-funcs + +(autoload 'mh-burst-digest "mh-funcs" + "Burst apart the current message, which should be a digest." t) +(autoload 'mh-copy-msg "mh-funcs" + "Copy specified MESSAGE(s) to another FOLDER without deleting them." t) +(autoload 'mh-kill-folder "mh-funcs" + "Remove the current folder." t) +(autoload 'mh-list-folders "mh-funcs" + "List mail folders." t) +(autoload 'mh-pack-folder "mh-funcs" + "Renumber the messages of a folder to be 1..n." t) +(autoload 'mh-pipe-msg "mh-funcs" + "Pipe the current message through the given shell COMMAND." t) +(autoload 'mh-page-digest "mh-funcs" + "Advance displayed message to next digested message." t) +(autoload 'mh-page-digest-backwards "mh-funcs" + "Back up displayed message to previous digested message." t) +(autoload 'mh-print-msg "mh-funcs" + "Print MESSAGE(s) (default: displayed message) on a line printer." t) +(autoload 'mh-sort-folder "mh-funcs" + "Sort the messages in the current folder by date." t) +(autoload 'mh-undo-folder "mh-funcs" + "Undo all commands in current folder." t) +(autoload 'mh-store-msg "mh-funcs" + "Store the file(s) contained in the current message." t) + + +;;; mh-pick + +(autoload 'mh-search-folder "mh-pick" + "Search FOLDER for messages matching a pattern." t) + +;;; mh-seq + +(autoload 'mh-put-msg-in-seq "mh-seq" + "Add MESSAGE(s) (default: displayed message) to SEQUENCE." t) +(autoload 'mh-delete-seq "mh-seq" + "Delete the SEQUENCE." t) +(autoload 'mh-list-sequences "mh-seq" + "List the sequences defined in FOLDER." t) +(autoload 'mh-msg-is-in-seq "mh-seq" + "Display the sequences that contain MESSAGE (default: displayed message)." t) +(autoload 'mh-narrow-to-seq "mh-seq" + "Restrict display of this folder to just messages in a sequence." t) +(autoload 'mh-widen "mh-seq" + "Remove restrictions from current folder, thereby showing all messages." t) +(autoload 'mh-rename-seq "mh-seq" + "Rename a SEQUENCE to have a new NAME." t) + +;;; mh-e.el ends here
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lisp/mail/mh-funcs.el Tue Mar 15 06:16:30 1994 +0000 @@ -0,0 +1,311 @@ +;;; mh-funcs --- mh-e functions not everyone will use right away +;; Time-stamp: <94/03/08 16:00:54 gildea> + +;; Copyright 1993 Free Software Foundation, Inc. + +;; This file is part of mh-e. + +;; mh-e is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 2, or (at your option) +;; any later version. + +;; mh-e is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with mh-e; see the file COPYING. If not, write to +;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + +;;; Commentary: + +;;; Internal support for mh-e package. +;;; Putting these functions in a separate file lets mh-e start up faster, +;;; since less Lisp code needs to be loaded all at once. + +;;; Code: + +(provide 'mh-funcs) +(require 'mh-e) + +(defvar mh-sortm-args nil + "Extra arguments to have \\[mh-sort-folder] pass to the \"sortm\" command. +For example, '(\"-nolimit\" \"-textfield\" \"subject\") is a useful setting.") + +(defun mh-burst-digest () + "Burst apart the current message, which should be a digest. +The message is replaced by its table of contents and the letters from the +digest are inserted into the folder after that message." + (interactive) + (let ((digest (mh-get-msg-num t))) + (mh-process-or-undo-commands mh-current-folder) + (mh-set-folder-modified-p t) ; lock folder while bursting + (message "Bursting digest...") + (mh-exec-cmd "burst" mh-current-folder digest "-inplace") + (mh-scan-folder mh-current-folder (format "%d-last" mh-first-msg-num)) + (message "Bursting digest...done"))) + + +(defun mh-copy-msg (dest msg-or-seq) + "Copy to another FOLDER the specified MESSAGE(s) without deleting them. +Default is the displayed message. If optional prefix argument is +provided, then prompt for the message sequence." + (interactive (list (mh-prompt-for-folder "Copy to" "" t) + (if current-prefix-arg + (mh-read-seq-default "Copy" t) + (mh-get-msg-num t)))) + (mh-exec-cmd "refile" msg-or-seq "-link" "-src" mh-current-folder dest) + (if (numberp msg-or-seq) + (mh-notate msg-or-seq ?C mh-cmd-note) + (mh-notate-seq msg-or-seq ?C mh-cmd-note))) + +(defun mh-kill-folder () + "Remove the current folder." + (interactive) + (if (or mh-do-not-confirm + (yes-or-no-p (format "Remove folder %s? " mh-current-folder))) + (let ((folder mh-current-folder)) + (if (null mh-folder-list) + (mh-set-folder-list)) + (mh-set-folder-modified-p t) ; lock folder to kill it + (mh-exec-cmd-daemon "rmf" folder) + (setq mh-folder-list + (delq (assoc folder mh-folder-list) mh-folder-list)) + (message "Folder %s removed" folder) + (mh-set-folder-modified-p nil) ; so kill-buffer doesn't complain + (if (get-buffer mh-show-buffer) + (kill-buffer mh-show-buffer)) + (kill-buffer folder)) + (message "Folder not removed"))) + + +(defun mh-list-folders () + "List mail folders." + (interactive) + (with-output-to-temp-buffer " *mh-temp*" + (save-excursion + (switch-to-buffer " *mh-temp*") + (erase-buffer) + (message "Listing folders...") + (mh-exec-cmd-output "folders" t (if mh-recursive-folders + "-recurse" + "-norecurse")) + (goto-char (point-min)) + (message "Listing folders...done")))) + + +(defun mh-pack-folder (range) + "Renumber the messages of a folder to be 1..n. +First, offer to execute any outstanding commands for the current folder. +If optional prefix argument provided, prompt for the range of messages +to display after packing. Otherwise, show the entire folder." + (interactive (list (if current-prefix-arg + (mh-read-msg-range + "Range to scan after packing [all]? ") + "all"))) + (mh-pack-folder-1 range) + (mh-goto-cur-msg) + (message "Packing folder...done")) + + +(defun mh-pack-folder-1 (range) + ;; Close and pack the current folder. + (mh-process-or-undo-commands mh-current-folder) + (message "Packing folder...") + (mh-set-folder-modified-p t) ; lock folder while packing + (save-excursion + (mh-exec-cmd-quiet t "folder" mh-current-folder "-pack")) + (mh-regenerate-headers range)) + + +(defun mh-pipe-msg (command include-headers) + "Pipe the current message through the given shell COMMAND. +If INCLUDE-HEADERS (prefix argument) is provided, send the entire message. +Otherwise just send the message's body without the headers." + (interactive + (list (read-string "Shell command on message: ") current-prefix-arg)) + (let ((file-name (mh-msg-filename (mh-get-msg-num t)))) + (save-excursion + (set-buffer (get-buffer-create " *mh-temp*")) + (erase-buffer) + (insert-file-contents file-name) + (goto-char (point-min)) + (if (not include-headers) (search-forward "\n\n")) + (shell-command-on-region (point) (point-max) command nil)))) + + +(defun mh-page-digest () + "Advance displayed message to next digested message." + (interactive) + (mh-in-show-buffer (mh-show-buffer) + ;; Go to top of screen (in case user moved point). + (move-to-window-line 0) + (let ((case-fold-search nil)) + ;; Search for blank line and then for From: + (or (and (search-forward "\n\n" nil t) + (search-forward "From:" nil t)) + (error "No more messages in digest"))) + ;; Go back to previous blank line, then forward to the first non-blank. + (search-backward "\n\n" nil t) + (forward-line 2) + (mh-recenter 0))) + + +(defun mh-page-digest-backwards () + "Back up displayed message to previous digested message." + (interactive) + (mh-in-show-buffer (mh-show-buffer) + ;; Go to top of screen (in case user moved point). + (move-to-window-line 0) + (let ((case-fold-search nil)) + (beginning-of-line) + (or (and (search-backward "\n\n" nil t) + (search-backward "From:" nil t)) + (error "No previous message in digest"))) + ;; Go back to previous blank line, then forward to the first non-blank. + (if (search-backward "\n\n" nil t) + (forward-line 2)) + (mh-recenter 0))) + + +(defun mh-print-msg (msg-or-seq) + "Print MESSAGE(s) (default: displayed message) on printer. +If optional prefix argument provided, then prompt for the message sequence. +The variable mh-lpr-command-format is used to generate the print command. +The messages are formatted by mhl. See the variable mhl-formfile." + (interactive (list (if current-prefix-arg + (reverse (mh-seq-to-msgs + (mh-read-seq-default "Print" t))) + (mh-get-msg-num t)))) + (if (numberp msg-or-seq) + (message "Printing message...") + (message "Printing sequence...")) + (let ((print-command + (if (numberp msg-or-seq) + (format "%s -nobell -clear %s %s | %s" + (expand-file-name "mhl" mh-lib) + (mh-msg-filename msg-or-seq) + (if (stringp mhl-formfile) + (format "-form %s" mhl-formfile) + "") + (format mh-lpr-command-format + (if (numberp msg-or-seq) + (format "%s/%d" mh-current-folder + msg-or-seq) + (format "Sequence from %s" mh-current-folder)))) + (format "(scan -clear %s ; %s -nobell -clear %s %s) | %s" + (mapconcat (function (lambda (msg) msg)) msg-or-seq " ") + (expand-file-name "mhl" mh-lib) + (if (stringp mhl-formfile) + (format "-form %s" mhl-formfile) + "") + (mh-msg-filenames msg-or-seq) + (format mh-lpr-command-format + (if (numberp msg-or-seq) + (format "%s/%d" mh-current-folder + msg-or-seq) + (format "Sequence from %s" + mh-current-folder))))))) + (if mh-print-background + (mh-exec-cmd-daemon shell-file-name "-c" print-command) + (call-process shell-file-name nil nil nil "-c" print-command)) + (if (numberp msg-or-seq) + (mh-notate msg-or-seq ?P mh-cmd-note) + (mh-notate-seq msg-or-seq ?P mh-cmd-note)) + (mh-add-msgs-to-seq msg-or-seq 'printed t) + (if (numberp msg-or-seq) + (message "Printing message...done") + (message "Printing sequence...done")))) + + +(defun mh-msg-filenames (msgs &optional folder) + ;; Return a list of file names for MSGS in FOLDER (default current folder). + (mapconcat (function (lambda (msg) (mh-msg-filename msg folder))) msgs " ")) + + +(defun mh-sort-folder (&optional no-args) + "Sort the messages in the current folder by date. +Calls the MH program sortm to do the work. +The arguments in the list mh-sortm-args are passed to sortm +unless this function is passed an argument." + (interactive "P") + (mh-process-or-undo-commands mh-current-folder) + (setq mh-next-direction 'forward) + (mh-set-folder-modified-p t) ; lock folder while sorting + (message "Sorting folder...") + (mh-exec-cmd "sortm" mh-current-folder (if (not no-args) mh-sortm-args)) + (message "Sorting folder...done") + (mh-scan-folder mh-current-folder "all")) + + +(defun mh-undo-folder (&rest ignore) + "Undo all commands in current folder." + (interactive) + (cond ((or mh-do-not-confirm + (yes-or-no-p "Undo all commands in folder? ")) + (setq mh-delete-list nil + mh-refile-list nil + mh-seq-list nil + mh-next-direction 'forward) + (with-mh-folder-updating (nil) + (mh-unmark-all-headers t))) + (t + (message "Commands not undone.") + (sit-for 2)))) + + +(defun mh-store-msg (dir) + "Store the file(s) contained in the current message into DIRECTORY. +The message can contain a shar file or uuencoded file. +Default directory is the last directory used, or initially the value of +mh-store-default-directory or the current directory." + (interactive (list (let ((udir (or mh-store-default-directory default-directory))) + (read-file-name "Store message in directory: " + udir udir nil)))) + (let ((file-name (mh-msg-filename (mh-get-msg-num t)))) + (save-excursion + (set-buffer (get-buffer-create " *mh-temp*")) + (erase-buffer) + (insert-file-contents file-name) + (mh-store-buffer dir)))) + +(defun mh-store-buffer (dir) + "Store the file(s) contained in the current buffer into DIRECTORY. +The buffer can contain a shar file or uuencoded file. +Default directory is the last directory used, or initially the value of +`mh-store-default-directory' or the current directory." + (interactive (list (let ((udir (or mh-store-default-directory default-directory))) + (read-file-name "Store buffer in directory: " + udir udir nil)))) + (let ((store-directory (expand-file-name dir)) + (start (save-excursion + (goto-char (point-min)) + (if (or (re-search-forward "^#![ \t]*/bin/sh" nil t) + (and (re-search-forward "^[^a-z0-9\"]*cut here\\b" nil t) + (forward-line 1)) + (re-search-forward "^#" nil t) + (re-search-forward "^: " nil t)) + (progn (beginning-of-line) (point))))) + (log-buffer (get-buffer-create "*Store Output*")) + (command "sh")) + (save-excursion + (set-buffer log-buffer) + (erase-buffer) + (if (not (file-directory-p store-directory)) + (progn + (insert "mkdir " dir "\n") + (call-process "mkdir" nil log-buffer t store-directory))) + (insert "cd " dir "\n") + (if (not start) + (progn + (setq command "uudecode") + (insert "uudecoding...\n")))) + (set-window-start (display-buffer log-buffer) 0) ;watch progress + (let ((default-directory (file-name-as-directory store-directory))) + (call-process-region start (point-max) command nil log-buffer t)) + (setq mh-store-default-directory dir) + (set-buffer log-buffer) + (insert "\n(mh-store finished)\n"))) +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lisp/mail/mh-mime.el Tue Mar 15 06:16:30 1994 +0000 @@ -0,0 +1,209 @@ +;;; mh-mime --- mh-e support for composing MIME messages +;; Time-stamp: <94/03/08 08:41:27 gildea> + +;; Copyright 1993 Free Software Foundation, Inc. + +;; This file is part of mh-e. + +;; mh-e is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 2, or (at your option) +;; any later version. + +;; mh-e is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with mh-e; see the file COPYING. If not, write to +;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + +;;; Commentary: + +;;; Internal support for mh-e package. +;;; Support for generating an mhn composition file. +;;; MIME is supported only by MH 6.8 or later. + +;;; Code: + +(provide 'mh-mime) +(require 'mh-comp) + + +;; To do: +;; paragraph code should not fill # lines if MIME enabled. +;; implement mh-auto-edit-mhn (if non-nil, \\[mh-send-letter] +;; invokes mh-edit-mhn automatically before sending.) +;; actually, instead of mh-auto-edit-mhn, +;; should read automhnproc from profile +;; MIME option to mh-forward +;; command to move to content-description insertion point + +(defvar mh-mime-content-types + '(("text/plain") ("text/richtext") + ("multipart/mixed") ("multipart/alternative") ("multipart/digest") + ("multipart/parallel") + ("message/rfc822") ("message/partial") ("message/external-body") + ("application/octet-stream") ("application/postscript") + ("image/jpeg") ("image/gif") + ("audio/basic") + ("video/mpeg")) + "Legal MIME content types.") + +(defun mh-mhn-compose-insertion (pathname type description) + "Add a directive to insert a message part from a file. +This is the typical way to insert non-text parts in a message. +See also \\[mh-edit-mhn]." + (interactive (list + (read-file-name "Insert contents of: ") + (completing-read "Content-type: " + mh-mime-content-types nil nil nil) + (read-string "Content-description: "))) + (mh-mhn-compose-type pathname type description)) + +(defun mh-mhn-compose-type (pathname type + &optional description attributes comment) + (beginning-of-line) + (insert "#" type) + (and attributes + (insert "; " attributes)) + (and comment + (insert " (" comment ")")) + (insert " [") + (and description + (insert description)) + (insert "] " (expand-file-name pathname)) + (insert "\n")) + + +(defun mh-mhn-compose-anon-ftp (host pathname type description) + "Add a directive for an anonymous ftp external body part. +This directive tells MH to include a reference to a message/external-body part +retrievable by anonymous FTP. See also \\[mh-edit-mhn]." + (interactive (list + (read-string "Remote host: ") + (read-string "Remote pathname: ") + (completing-read "External Content-type: " + mh-mime-content-types nil nil nil) + (read-string "External Content-description: "))) + (mh-mhn-compose-external-type "anon-ftp" host pathname + type description)) + +(defun mh-mhn-compose-external-compressed-tar (host pathname description) + "Add a directive to include a reference to a compressed tar file. +The file should be available via anonymous ftp. +This directive tells MH to include a reference to a message/external-body part. +See also \\[mh-edit-mhn]." + (interactive (list + (read-string "Remote host: ") + (read-string "Remote pathname: ") + (read-string "Tar file Content-description: "))) + (mh-mhn-compose-external-type "anon-ftp" host pathname + "application/octet-stream" + description + "type=tar; conversions=x-compress" + "mode=image")) + + +(defun mh-mhn-compose-external-type (access-type host pathname type + &optional description + attributes extra-params comment) + (beginning-of-line) + (insert "#@" type) + (and attributes + (insert "; " attributes)) + (and comment + (insert " (" comment ") ")) + (insert " [") + (and description + (insert description)) + (insert "] ") + (insert "access-type=" access-type "; ") + (insert "site=" host) + (insert "; name=" (file-name-nondirectory pathname)) + (insert "; directory=\"" (file-name-directory pathname) "\"") + (and extra-params + (insert "; " extra-params)) + (insert "\n")) + +(defun mh-mhn-compose-forw (&optional description msgs folder) + "Add a forw directive to this message. +This directive tells MH to include the named messages in this one. +Arguments are DESCRIPTION, a line of text for the Content-description header, +MESSAGES and FOLDER, which name the message(s) to be forwarded. +See also \\[mh-edit-mhn]." + (interactive (list + (read-string "Forw Content-description: ") + (read-string (format "Messages%s: " + (if mh-sent-from-msg + (format " [%d]" mh-sent-from-msg) + ""))) + (mh-prompt-for-folder "Message from" mh-sent-from-folder nil))) + (beginning-of-line) + (insert "#forw [") + (and description + (not (string= description "")) + (insert description)) + (insert "]") + (and folder + (not (string= folder "")) + (insert " " folder)) + (if (and msgs + (not (string= msgs ""))) + (let ((start (point))) + (insert " " msgs) + (subst-char-in-region start (point) ?, ? )) + (if mh-sent-from-msg + (insert " " (int-to-string mh-sent-from-msg)))) + (insert "\n")) + +(defun mh-edit-mhn () + "Filter the current draft through the mhn program for MIME formatting. +Using directives already inserted in the draft, fills in +all the MIME components and header fields. +This step should be done last just before sending the message. +The mhn program is part of MH version 6.8 or later. +The `\\[mh-revert-mhn-edit]' command undoes this command. +For assistance with creating MIME directives to insert +various types of components in a message, see +\\[mh-mhn-compose-insertion] (generic insertion from a file), +\\[mh-mhn-compose-anon-ftp] (external reference to file via anonymous ftp), +\\[mh-mhn-compose-external-compressed-tar] \ +\(reference to compressed tar file via anonymous ftp), and +\\[mh-mhn-compose-forw] (forward message)." + (interactive "*") + (save-buffer) + (message "mhn editing...") + (mh-exec-cmd-error (format "mhdraft=%s" (buffer-file-name)) + "mhn" (buffer-file-name)) + (revert-buffer t t) + (message "mhn editing...done")) + + +(defun mh-revert-mhn-edit (noconfirm) + "Undoes the effect of \\[mh-edit-mhn] by reverting to the backup file. +Argument (optional) non-nil means don't ask for confirmation." + (interactive "*P") + (if (null buffer-file-name) + (error "Buffer does not seem to be associated with any file")) + (let ((backup-strings '("," "#")) + backup-file) + (while (and backup-strings + (not (file-exists-p + (setq backup-file + (concat (file-name-directory buffer-file-name) + (car backup-strings) + (file-name-nondirectory buffer-file-name) + ".orig"))))) + (setq backup-strings (cdr backup-strings))) + (or backup-strings + (error "mhn backup file for %s no longer exists!" buffer-file-name)) + (or noconfirm + (yes-or-no-p (format "Revert buffer from file %s? " + backup-file)) + (error "mhn edit revert not confirmed.")) + (let ((buffer-read-only nil)) + (erase-buffer) + (insert-file-contents backup-file)) + (after-find-file nil)))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lisp/mail/mh-pick.el Tue Mar 15 06:16:30 1994 +0000 @@ -0,0 +1,177 @@ +;;; mh-pick --- make a search pattern and search for a message in mh-e +;; Time-stamp: <93/08/22 22:56:53 gildea> + +;; Copyright 1993 Free Software Foundation, Inc. + +;; This file is part of mh-e. + +;; mh-e is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 2, or (at your option) +;; any later version. + +;; mh-e is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with mh-e; see the file COPYING. If not, write to +;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + +;;; Commentary: + +;; Internal support for mh-e package. + +;;; Code: + +(provide 'mh-pick) +(require 'mh-e) + +(defvar mh-pick-mode-map (make-sparse-keymap) + "Keymap for searching folder.") + +(defvar mh-pick-mode-hook nil + "Invoked in `mh-pick-mode' on a new pattern.") + +(defvar mh-searching-folder nil + "Folder this pick is searching.") + +(defun mh-search-folder (folder) + "Search FOLDER for messages matching a pattern." + (interactive (list (mh-prompt-for-folder "Search" + mh-current-folder + t))) + (switch-to-buffer-other-window "pick-pattern") + (if (or (zerop (buffer-size)) + (not (y-or-n-p "Reuse pattern? "))) + (mh-make-pick-template) + (message "")) + (setq mh-searching-folder folder)) + +(defun mh-make-pick-template () + ;; Initialize the current buffer with a template for a pick pattern. + (erase-buffer) + (insert "From: \n" + "To: \n" + "Cc: \n" + "Date: \n" + "Subject: \n" + "---------\n") + (mh-pick-mode) + (goto-char (point-min)) + (end-of-line)) + +(put 'mh-pick-mode 'mode-class 'special) + +(defun mh-pick-mode () + "Mode for creating search templates in mh-e.\\<mh-pick-mode-map> +After each field name, enter the pattern to search for. To search +the entire message, supply the pattern in the \"body\" of the template. +When you have finished, type \\[mh-do-pick-search] to do the search. +\\{mh-pick-mode-map} +Turning on mh-pick-mode calls the value of the variable mh-pick-mode-hook +if that value is non-nil." + (interactive) + (kill-all-local-variables) + (make-local-variable 'mh-searching-folder) + (use-local-map mh-pick-mode-map) + (setq major-mode 'mh-pick-mode) + (mh-set-mode-name "MH-Pick") + (run-hooks 'mh-pick-mode-hook)) + + +(defun mh-do-pick-search () + "Find messages that match the qualifications in the current pattern buffer. +Messages are searched for in the folder named in mh-searching-folder. +Add messages found to the sequence named `search'." + (interactive) + (let ((pattern-buffer (buffer-name)) + (searching-buffer mh-searching-folder) + range msgs + (pattern nil) + (new-buffer nil)) + (save-excursion + (cond ((get-buffer searching-buffer) + (set-buffer searching-buffer) + (setq range (format "%d-%d" mh-first-msg-num mh-last-msg-num))) + (t + (mh-make-folder searching-buffer) + (setq range "all") + (setq new-buffer t)))) + (message "Searching...") + (goto-char (point-min)) + (while (setq pattern (mh-next-pick-field pattern-buffer)) + (setq msgs (mh-seq-from-command searching-buffer + 'search + (nconc (cons "pick" pattern) + (list searching-buffer + range + "-sequence" "search" + "-list")))) + (setq range "search")) + (message "Searching...done") + (if new-buffer + (mh-scan-folder searching-buffer msgs) + (switch-to-buffer searching-buffer)) + (delete-other-windows) + (mh-notate-seq 'search ?% (1+ mh-cmd-note)))) + + +(defun mh-seq-from-command (folder seq seq-command) + ;; In FOLDER, make a sequence named SEQ by executing COMMAND. + ;; COMMAND is a list. The first element is a program name + ;; and the subsequent elements are its arguments, all strings. + (let ((msg) + (msgs ()) + (case-fold-search t)) + (save-excursion + (save-window-excursion + (if (eq 0 (apply 'mh-exec-cmd-quiet nil seq-command)) + (while (setq msg (car (mh-read-msg-list))) + (setq msgs (cons msg msgs)) + (forward-line 1)))) + (set-buffer folder) + (setq msgs (nreverse msgs)) ; Put in ascending order + (setq mh-seq-list (cons (mh-make-seq seq msgs) mh-seq-list)) + msgs))) + + +(defun mh-next-pick-field (buffer) + ;; Return the next piece of a pick argument that can be extracted from the + ;; BUFFER. Returns nil if no pieces remain. + (set-buffer buffer) + (let ((case-fold-search t)) + (cond ((eobp) + nil) + ((re-search-forward "^\\([a-z][^: \t\n]*\\):[ \t]*\\([a-z0-9].*\\)$" nil t) + (let* ((component + (format "--%s" + (downcase (buffer-substring (match-beginning 1) + (match-end 1))))) + (pat (buffer-substring (match-beginning 2) (match-end 2)))) + (forward-line 1) + (list component pat))) + ((re-search-forward "^-*$" nil t) + (forward-char 1) + (let ((body (buffer-substring (point) (point-max)))) + (if (and (> (length body) 0) (not (equal body "\n"))) + (list "-search" body) + nil))) + (t + nil)))) + +;;; Build the pick-mode keymap: + +(define-key mh-pick-mode-map "\C-c\C-c" 'mh-do-pick-search) +(define-key mh-pick-mode-map "\C-c\C-f\C-b" 'mh-to-field) +(define-key mh-pick-mode-map "\C-c\C-f\C-c" 'mh-to-field) +(define-key mh-pick-mode-map "\C-c\C-f\C-f" 'mh-to-field) +(define-key mh-pick-mode-map "\C-c\C-f\C-s" 'mh-to-field) +(define-key mh-pick-mode-map "\C-c\C-f\C-t" 'mh-to-field) +(define-key mh-pick-mode-map "\C-c\C-fb" 'mh-to-field) +(define-key mh-pick-mode-map "\C-c\C-fc" 'mh-to-field) +(define-key mh-pick-mode-map "\C-c\C-ff" 'mh-to-field) +(define-key mh-pick-mode-map "\C-c\C-fs" 'mh-to-field) +(define-key mh-pick-mode-map "\C-c\C-ft" 'mh-to-field) +(define-key mh-pick-mode-map "\C-c\C-w" 'mh-check-whom)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lisp/mail/mh-seq.el Tue Mar 15 06:16:30 1994 +0000 @@ -0,0 +1,222 @@ +;;; mh-seq --- mh-e sequences support +;; Time-stamp: <93/12/02 09:36:09 gildea> + +;; Copyright 1993 Free Software Foundation, Inc. + +;; This file is part of mh-e. + +;; mh-e is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 2, or (at your option) +;; any later version. + +;; mh-e is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with mh-e; see the file COPYING. If not, write to +;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + +;;; Commentary: + +;; Internal support for mh-e package. + +;;; Code: + +(provide 'mh-seq) +(require 'mh-e) + +(defvar mh-last-seq-used nil + "Name of the sequence to which a message was last added.") + + +(defun mh-delete-seq (seq) + "Delete the SEQUENCE." + (interactive (list (mh-read-seq-default "Delete" t))) + (mh-map-to-seq-msgs 'mh-notate-if-in-one-seq seq ? (1+ mh-cmd-note) seq) + (mh-undefine-sequence seq "all") + (mh-delete-seq-locally seq)) + + +(defun mh-list-sequences (folder) + "List the sequences defined in FOLDER." + (interactive (list (mh-prompt-for-folder "List sequences in" + mh-current-folder t))) + (let ((temp-buffer " *mh-temp*") + (seq-list mh-seq-list)) + (with-output-to-temp-buffer temp-buffer + (save-excursion + (set-buffer temp-buffer) + (erase-buffer) + (message "Listing sequences ...") + (insert "Sequences in folder " folder ":\n") + (while seq-list + (let ((name (mh-seq-name (car seq-list))) + (sorted-seq-msgs + (sort (copy-sequence (mh-seq-msgs (car seq-list))) '<)) + (last-col (- (window-width) 4)) + name-spec) + (insert (setq name-spec (format "%20s:" name))) + (while sorted-seq-msgs + (if (> (current-column) last-col) + (progn + (insert "\n") + (move-to-column (length name-spec)))) + (insert (format " %s" (car sorted-seq-msgs))) + (setq sorted-seq-msgs (cdr sorted-seq-msgs))) + (insert "\n")) + (setq seq-list (cdr seq-list))) + (goto-char (point-min)) + (message "Listing sequences...done"))))) + + +(defun mh-msg-is-in-seq (msg) + "Display the sequences that contain MESSAGE (default: displayed message)." + (interactive (list (mh-get-msg-num t))) + (message "Message %d is in sequences: %s" + msg + (mapconcat 'concat + (mh-list-to-string (mh-seq-containing-msg msg)) + " "))) + + +(defun mh-narrow-to-seq (seq) + "Restrict display of this folder to just messages in a sequence. +Reads which sequence.\\<mh-folder-mode-map> Use \\[mh-widen] to undo this command." + (interactive (list (mh-read-seq "Narrow to" t))) + (let ((eob (point-max))) + (with-mh-folder-updating (t) + (cond ((mh-seq-to-msgs seq) + (mh-copy-seq-to-point seq eob) + (narrow-to-region eob (point-max)) + (mh-make-folder-mode-line (symbol-name seq)) + (mh-recenter nil) + (setq mh-narrowed-to-seq seq)) + (t + (error "No messages in sequence `%s'" (symbol-name seq))))))) + + +(defun mh-put-msg-in-seq (msg-or-seq to) + "Add MESSAGE(s) (default: displayed message) to SEQUENCE. +If optional prefix argument provided, then prompt for the message sequence." + (interactive (list (if current-prefix-arg + (mh-read-seq-default "Add messages from" t) + (mh-get-msg-num t)) + (mh-read-seq-default "Add to" nil))) + (setq mh-last-seq-used to) + (mh-add-msgs-to-seq (if (numberp msg-or-seq) + msg-or-seq + (mh-seq-to-msgs msg-or-seq)) + to)) + + +(defun mh-widen () + "Remove restrictions from current folder, thereby showing all messages." + (interactive) + (if mh-narrowed-to-seq + (with-mh-folder-updating (t) + (delete-region (point-min) (point-max)) + (widen) + (mh-make-folder-mode-line))) + (setq mh-narrowed-to-seq nil)) + + + +;;; Commands to manipulate sequences. Sequences are stored in an alist +;;; of the form: +;;; ((seq-name msgs ...) (seq-name msgs ...) ...) + + +(defun mh-read-seq-default (prompt not-empty) + ;; Read and return sequence name with default narrowed or previous sequence. + (mh-read-seq prompt not-empty (or mh-narrowed-to-seq mh-last-seq-used))) + + +(defun mh-read-seq (prompt not-empty &optional default) + ;; Read and return a sequence name. Prompt with PROMPT, raise an error + ;; if the sequence is empty and the NOT-EMPTY flag is non-nil, and supply + ;; an optional DEFAULT sequence. + ;; A reply of '%' defaults to the first sequence containing the current + ;; message. + (let* ((input (completing-read (format "%s %s %s" prompt "sequence:" + (if default + (format "[%s] " default) + "")) + (mh-seq-names mh-seq-list))) + (seq (cond ((equal input "%") (mh-msg-to-seq (mh-get-msg-num t))) + ((equal input "") default) + (t (intern input)))) + (msgs (mh-seq-to-msgs seq))) + (if (and (null msgs) not-empty) + (error (format "No messages in sequence `%s'" seq))) + seq)) + + +(defun mh-msg-to-seq (msg) + ;; Given a MESSAGE number, return the first sequence in which it occurs. + (car (mh-seq-containing-msg msg))) + + +(defun mh-seq-names (seq-list) + ;; Return an alist containing the names of the SEQUENCES. + (mapcar (function (lambda (entry) (list (symbol-name (mh-seq-name entry))))) + seq-list)) + + +(defun mh-rename-seq (seq new-name) + "Rename a SEQUENCE to have a new NAME." + (interactive (list (mh-read-seq "Old" t) + (intern (read-string "New sequence name: ")))) + (let ((old-seq (mh-find-seq seq))) + (or old-seq + (error "Sequence %s does not exist" seq)) + ;; create new seq first, since it might raise an error. + (mh-define-sequence new-name (mh-seq-msgs old-seq)) + (mh-undefine-sequence seq (mh-seq-msgs old-seq)) + (rplaca old-seq new-name))) + + +(defun mh-map-to-seq-msgs (func seq &rest args) + ;; Invoke the FUNCTION at each message in the SEQUENCE, passing the + ;; remaining ARGS as arguments. + (save-excursion + (let ((msgs (mh-seq-to-msgs seq))) + (while msgs + (if (mh-goto-msg (car msgs) t t) + (apply func (car msgs) args)) + (setq msgs (cdr msgs)))))) + + +(defun mh-notate-seq (seq notation offset) + ;; Mark the scan listing of all messages in the SEQUENCE with the CHARACTER + ;; at the given OFFSET from the beginning of the listing line. + (mh-map-to-seq-msgs 'mh-notate seq notation offset)) + + +(defun mh-add-to-sequence (seq msgs) + ;; Add to a SEQUENCE each message the list of MSGS. + (if (not (mh-folder-name-p seq)) + (if msgs + (apply 'mh-exec-cmd "mark" mh-current-folder "-add" + "-sequence" (symbol-name seq) + msgs)))) + + +(defun mh-copy-seq-to-point (seq location) + ;; Copy the scan listing of the messages in SEQUENCE to after the point + ;; LOCATION in the current buffer. + (mh-map-to-seq-msgs 'mh-copy-line-to-point seq location)) + + +(defun mh-copy-line-to-point (msg location) + ;; Copy the current line to the LOCATION in the current buffer. + (beginning-of-line) + (let ((beginning-of-line (point))) + (forward-line 1) + (copy-region-as-kill beginning-of-line (point)) + (goto-char location) + (yank) + (goto-char beginning-of-line))) +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lisp/mail/mh-utils.el Tue Mar 15 06:16:30 1994 +0000 @@ -0,0 +1,816 @@ +;;; mh-utils.el --- mh-e code needed for both sending and reading +;; Time-stamp: <93/12/26 18:50:51 gildea> + +;; Copyright 1993 Free Software Foundation, Inc. + +;; This file is part of mh-e. + +;; mh-e is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 2, or (at your option) +;; any later version. + +;; mh-e is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with mh-e; see the file COPYING. If not, write to +;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + +;;; Commentary: + +;; Internal support for mh-e package. + +;;; Code: + +;;; mh-e macros + +(defmacro with-mh-folder-updating (save-modification-flag-p &rest body) + ;; Format is (with-mh-folder-updating (SAVE-MODIFICATION-FLAG-P) &body BODY). + ;; Execute BODY, which can modify the folder buffer without having to + ;; worry about file locking or the read-only flag, and return its result. + ;; If SAVE-MODIFICATION-FLAG-P is non-nil, the buffer's modification + ;; flag is unchanged, otherwise it is cleared. + (setq save-modification-flag-p (car save-modification-flag-p)) ; CL style + (` (let (, (if save-modification-flag-p '((mh-folder-updating-mod-flag (buffer-modified-p))))) + (prog1 + (let ((buffer-read-only nil) + (buffer-file-name nil)) ; don't let the buffer get locked + (,@ body)) + (, (if save-modification-flag-p + '(mh-set-folder-modified-p mh-folder-updating-mod-flag) + '(mh-set-folder-modified-p nil))))))) + +(put 'with-mh-folder-updating 'lisp-indent-hook 1) + +(defmacro mh-in-show-buffer (show-buffer &rest body) + ;; Format is (mh-in-show-buffer (show-buffer) &body BODY). + ;; Display buffer SHOW-BUFFER in other window and execute BODY in it. + ;; Stronger than save-excursion, weaker than save-window-excursion. + (setq show-buffer (car show-buffer)) ; CL style + (` (let ((mh-in-show-buffer-saved-window (selected-window))) + (switch-to-buffer-other-window (, show-buffer)) + (if mh-bury-show-buffer (bury-buffer (current-buffer))) + (unwind-protect + (progn + (,@ body)) + (select-window mh-in-show-buffer-saved-window))))) + +(put 'mh-in-show-buffer 'lisp-indent-hook 1) + +(defmacro mh-seq-name (pair) (list 'car pair)) + +(defmacro mh-seq-msgs (pair) (list 'cdr pair)) + + +(defvar mh-auto-folder-collect t + "*Whether to start collecting MH folder names immediately in the background. +Non-nil means start a background process collecting the names of all +folders as soon as mh-e is loaded.") + +(defvar mh-recursive-folders nil + "*If non-nil, then commands which operate on folders do so recursively.") + +(defvar mh-clean-message-header nil + "*Non-nil means clean headers of messages that are displayed or inserted. +The variables `mh-visible-headers' and `mh-invisible-headers' control what +is removed.") + +(defvar mh-visible-headers nil + "*If non-nil, contains a regexp specifying the headers to keep when cleaning. +Only used if `mh-clean-message-header' is non-nil. Setting this variable +overrides `mh-invisible-headers'.") + +(defvar mh-invisible-headers + "^Received: \\|^Message-Id: \\|^Remailed-\\|^Via: \\|^Mail-from: \\|^Return-Path: \\|^In-Reply-To: \\|^Resent-" + "Regexp matching lines in a message header that are not to be shown. +If `mh-visible-headers' is non-nil, it is used instead to specify what +to keep.") + +(defvar mh-bury-show-buffer t + "*Non-nil means that the displayed show buffer for a folder is buried.") + +(defvar mh-summary-height 4 + "*Number of lines in MH-Folder window (including the mode line).") + +(defvar mh-msg-number-regexp "^ *\\([0-9]+\\)" + "Regexp to find the number of a message in a scan line. +The message's number must be surrounded with \\( \\)") + +(defvar mh-msg-search-regexp "^[^0-9]*%d[^0-9]" + "Format string containing a regexp matching the scan listing for a message. +The desired message's number will be an argument to format.") + +(defvar mhl-formfile nil + "*Name of format file to be used by mhl to show and print messages. +A value of T means use the default format file. +Nil means don't use mhl to format messages when showing; mhl is still used, +with the default format file, to format messages when printing them. +The format used should specify a non-zero value for overflowoffset so +the message continues to conform to RFC 822 and mh-e can parse the headers.") + +(defvar mh-msg-folder-hook nil + "Select a default folder for refiling or Fcc. +Called by `\\[mh-refile-msg]' and `\\[mh-to-fcc]' to get a default +when prompting the user for a folder. Called from within a save-excursion, +with point at the start of the message. Should return the folder to offer +as the refile or Fcc folder, as a string with a leading `+' sign.") + + +(defvar mh-cmd-note 4 + "Offset to insert notation.") + +(defvar mh-folder-list nil + "List of folder names for completion.") + +(defvar mh-user-path nil + "User's mail folder directory.") + +(defvar mh-draft-folder nil + "Name of folder containing draft messages. +NIL means do not use draft folder.") + +(defvar mh-previous-window-config nil + "Window configuration before mh-e command.") + +(defvar mh-current-folder nil + "Name of current folder, a string.") + +(defvar mh-folder-filename nil + "Full path of directory for this folder.") + +(defvar mh-show-buffer nil + "Buffer that displays mesage for this folder.") + +(defvar mh-unseen-seq nil + "Name of the Unseen sequence.") + +(defvar mh-previous-seq nil + "Name of the Previous sequence.") + +(defvar mh-seen-list nil + "List of displayed messages.") + +(defvar mh-seq-list nil + "Alist of (seq . msgs) numbers.") + +(defvar mh-showing nil + "If non-nil, show the message in a separate window.") + +(defvar mh-showing-with-headers nil + "If non-nil, show buffer contains message with all headers. +If nil, show buffer contains message processed normally.") + + +;;; Ensure new buffers won't get this mode if default-major-mode is nil. +(put 'mh-show-mode 'mode-class 'special) + +(defun mh-show-mode () + "Major mode for showing messages in mh-e. +The value of mh-show-mode-hook is called when a new message is displayed." + (kill-all-local-variables) + (setq major-mode 'mh-show-mode) + (mh-set-mode-name "MH-Show") + (run-hooks 'mh-show-mode-hook)) + + +(defun mh-maybe-show (&optional msg) + ;; If in showing mode, then display the message pointed to by the cursor. + (if mh-showing (mh-show msg))) + +(defun mh-show (&optional msg) + "Show MESSAGE (default: displayed message). +Forces a two-window display with the folder window on top (size +mh-summary-height) and the show buffer below it. +If the message is already visible, display the start of the message." + (interactive) + (and mh-showing-with-headers + (or mhl-formfile mh-clean-message-header) + (mh-invalidate-show-buffer)) + (mh-show-msg msg)) + + +(defun mh-show-msg (msg) + (if (not msg) + (setq msg (mh-get-msg-num t))) + (setq mh-showing t) + (let ((folder mh-current-folder) + (clean-message-header mh-clean-message-header) + (show-window (get-buffer-window mh-show-buffer))) + (if (not (eql (next-window (minibuffer-window)) (selected-window))) + (delete-other-windows)) ; force ourself to the top window + (mh-in-show-buffer (mh-show-buffer) + (if (and show-window + (equal (mh-msg-filename msg folder) buffer-file-name)) + (progn ;just back up to start + (goto-char (point-min)) + (if (not clean-message-header) + (mh-start-of-uncleaned-message))) + (mh-display-msg msg folder)))) + (if (not (= (1+ (window-height)) (screen-height))) ;not horizontally split + (shrink-window (- (window-height) mh-summary-height))) + (mh-recenter nil) + (if (not (memq msg mh-seen-list)) (setq mh-seen-list (cons msg mh-seen-list))) + (run-hooks 'mh-show-hook)) + + +(defun mh-display-msg (msg-num folder) + ;; Display message NUMBER of FOLDER. + ;; Sets the current buffer to the show buffer. + (set-buffer folder) + ;; Bind variables in folder buffer in case they are local + (let ((formfile mhl-formfile) + (clean-message-header mh-clean-message-header) + (invisible-headers mh-invisible-headers) + (visible-headers mh-visible-headers) + (msg-filename (mh-msg-filename msg-num)) + (show-buffer mh-show-buffer)) + (if (not (file-exists-p msg-filename)) + (error "Message %d does not exist" msg-num)) + (set-buffer show-buffer) + (cond ((not (equal msg-filename buffer-file-name)) + ;; Buffer does not yet contain message. + (clear-visited-file-modtime) + (unlock-buffer) + (setq buffer-file-name nil) ; no locking during setup + (erase-buffer) + (if formfile + (mh-exec-lib-cmd-output "mhl" "-nobell" "-noclear" + (if (stringp formfile) + (list "-form" formfile)) + msg-filename) + (insert-file-contents msg-filename)) + (goto-char (point-min)) + (cond (clean-message-header + (mh-clean-msg-header (point-min) + invisible-headers + visible-headers) + (goto-char (point-min))) + (t + (mh-start-of-uncleaned-message))) + (set-buffer-modified-p nil) + (or (eq buffer-undo-list t) ;don't save undo info for prev msgs + (setq buffer-undo-list nil)) + (setq buffer-file-name msg-filename) + (set-mark nil) + (mh-show-mode) + (setq mode-line-buffer-identification + (list (format mh-show-buffer-mode-line-buffer-id + folder msg-num))) + (set-buffer folder) + (setq mh-showing-with-headers nil))))) + +(defun mh-start-of-uncleaned-message () + ;; position uninteresting headers off the top of the window + (let ((case-fold-search t)) + (re-search-forward + "^To:\\|^From:\\|^Subject:\\|^Date:" nil t) + (beginning-of-line) + (mh-recenter 0))) + + +(defun mh-invalidate-show-buffer () + ;; Invalidate the show buffer so we must update it to use it. + (if (get-buffer mh-show-buffer) + (save-excursion + (set-buffer mh-show-buffer) + (setq buffer-file-name nil)))) + + +(defun mh-get-msg-num (error-if-no-message) + ;; Return the message number of the displayed message. If the argument + ;; ERROR-IF-NO-MESSAGE is non-nil, then complain if the cursor is not + ;; pointing to a message. + (save-excursion + (beginning-of-line) + (cond ((looking-at mh-msg-number-regexp) + (string-to-int (buffer-substring (match-beginning 1) + (match-end 1)))) + (error-if-no-message + (error "Cursor not pointing to message")) + (t nil)))) + + +(defun mh-msg-filename (msg &optional folder) + ;; Return the file name of MESSAGE in FOLDER (default current folder). + (expand-file-name (int-to-string msg) + (if folder + (mh-expand-file-name folder) + mh-folder-filename))) + + +(defun mh-clean-msg-header (start invisible-headers visible-headers) + ;; Flush extraneous lines in a message header, from the given POINT to the + ;; end of the message header. If VISIBLE-HEADERS is non-nil, it contains a + ;; regular expression specifying the lines to display, otherwise + ;; INVISIBLE-HEADERS contains a regular expression specifying lines to + ;; delete from the header. + (let ((case-fold-search t)) + (save-restriction + (goto-char start) + (if (search-forward "\n\n" nil 'move) + (backward-char 1)) + (narrow-to-region start (point)) + (goto-char (point-min)) + (if visible-headers + (while (< (point) (point-max)) + (cond ((looking-at visible-headers) + (forward-line 1) + (while (looking-at "[ \t]") (forward-line 1))) + (t + (mh-delete-line 1) + (while (looking-at "[ \t]") + (mh-delete-line 1))))) + (while (re-search-forward invisible-headers nil t) + (beginning-of-line) + (mh-delete-line 1) + (while (looking-at "[ \t]") + (mh-delete-line 1)))) + (unlock-buffer)))) + + +(defun mh-recenter (arg) + ;; Like recenter but with two improvements: nil arg means recenter, + ;; and only does anything if the current buffer is in the selected + ;; window. (Commands like save-some-buffers can make this false.) + (if (eql (get-buffer-window (current-buffer)) + (selected-window)) + (recenter (if arg arg '(t))))) + + +(defun mh-delete-line (lines) + ;; Delete version of kill-line. + (delete-region (point) (save-excursion (forward-line lines) (point)))) + + +(defun mh-get-field (field) + ;; Find and return the value of field FIELD in the current buffer. + ;; Returns the empty string if the field is not in the message. + (let ((case-fold-search t)) + (goto-char (point-min)) + (cond ((not (re-search-forward (format "^%s" field) nil t)) "") + ((looking-at "[\t ]*$") "") + (t + (re-search-forward "[\t ]*\\([^\t \n].*\\)$" nil t) + (let ((start (match-beginning 1))) + (forward-line 1) + (while (looking-at "[ \t]") + (forward-line 1)) + (buffer-substring start (1- (point)))))))) + + +(defun mh-notate (msg notation offset) + ;; Marks MESSAGE with the character NOTATION at position OFFSET. + ;; Null MESSAGE means the message that the cursor points to. + (save-excursion + (if (or (null msg) + (mh-goto-msg msg t t)) + (with-mh-folder-updating (t) + (beginning-of-line) + (forward-char offset) + (delete-char 1) + (insert notation))))) + + +(defun mh-goto-msg (number &optional no-error-if-no-message dont-show) + "Position the cursor at message NUMBER. +Non-nil second argument means do not signal an error if message does not exist. +Non-nil third argument means not to show the message. +Return non-nil if cursor is at message." + (interactive "NJump to message: ") + (let ((cur-msg (mh-get-msg-num nil)) + (starting-place (point)) + (msg-pattern (mh-msg-search-pat number))) + (cond ((cond ((and cur-msg (= cur-msg number)) t) + ((and cur-msg + (< cur-msg number) + (re-search-forward msg-pattern nil t)) t) + ((and cur-msg + (> cur-msg number) + (re-search-backward msg-pattern nil t)) t) + (t ; Do thorough search of buffer + (goto-char (point-max)) + (re-search-backward msg-pattern nil t))) + (beginning-of-line) + (if (not dont-show) (mh-maybe-show number)) + t) + (t + (goto-char starting-place) + (if (not no-error-if-no-message) + (error "No message %d" number)) + nil)))) + +(defun mh-msg-search-pat (n) + ;; Return a search pattern for message N in the scan listing. + (format mh-msg-search-regexp n)) + + +(defun mh-find-path () + ;; Set mh-progs and mh-lib. + ;; (This step is necessary if MH was installed after this Emacs was dumped.) + ;; Set mh-user-path, mh-draft-folder, + ;; mh-unseen-seq, and mh-previous-seq from profile file. + (mh-find-progs) + (save-excursion + ;; Be sure profile is fully expanded before switching buffers + (let ((profile (expand-file-name (or (getenv "MH") "~/.mh_profile")))) + (set-buffer (get-buffer-create " *mh-temp*")) + (setq buffer-offer-save nil) ;for people who set default to t + (erase-buffer) + (condition-case err + (insert-file-contents profile) + (file-error + (mh-install profile err))) + (setq mh-draft-folder (mh-get-field "Draft-Folder:")) + (cond ((equal mh-draft-folder "") + (setq mh-draft-folder nil)) + ((not (mh-folder-name-p mh-draft-folder)) + (setq mh-draft-folder (format "+%s" mh-draft-folder)))) + (setq mh-user-path (mh-get-field "Path:")) + (if (equal mh-user-path "") + (setq mh-user-path "Mail")) + (setq mh-user-path + (file-name-as-directory + (expand-file-name mh-user-path (expand-file-name "~")))) + (if (and mh-draft-folder + (not (file-exists-p (mh-expand-file-name mh-draft-folder)))) + (error "Draft folder \"%s\" not found. Create it and try again." + (mh-expand-file-name mh-draft-folder))) + (setq mh-unseen-seq (mh-get-field "Unseen-Sequence:")) + (if (equal mh-unseen-seq "") + (setq mh-unseen-seq 'unseen) ;old MH default? + (setq mh-unseen-seq (intern mh-unseen-seq))) + (setq mh-previous-seq (mh-get-field "Previous-Sequence:")) + (if (equal mh-previous-seq "") + (setq mh-previous-seq nil) + (setq mh-previous-seq (intern mh-previous-seq)))))) + +(defun mh-find-progs () + (or (file-exists-p (expand-file-name "inc" mh-progs)) + (setq mh-progs + (or (mh-path-search exec-path "inc") + (mh-path-search '("/usr/bin/mh/" ;Ultrix 4.2 + "/usr/new/mh/" ;Ultrix <4.2 + "/usr/local/bin/mh/" + "/usr/local/mh/") + "inc") + "/usr/local/bin/"))) + (or (file-exists-p (expand-file-name "mhl" mh-lib)) + (setq mh-lib + (or (mh-path-search '("/usr/lib/mh/" ;Ultrix 4.2 + "/usr/new/lib/mh/" ;Ultrix <4.2 + "/usr/local/lib/mh/") + "mhl") + (mh-path-search exec-path "mhl") ;unlikely + "/usr/local/bin/mh/")))) + +(defun mh-path-search (path file) + ;; Search PATH, a list of directory names, for FILE. + ;; Returns the element of PATH that contains FILE, or nil if not found. + (while (and path + (not (file-exists-p (expand-file-name file (car path))))) + (setq path (cdr path))) + (car path)) + +(defun mh-install (profile error-val) + ;; Called to do error recovery if we fail to read the profile file. + ;; If possible, initialize the MH environment. + (if (or (getenv "MH") + (file-exists-p profile)) + (error "Cannot read MH profile \"%s\": %s" + profile (car (cdr (cdr error-val))))) + ;; The "install-mh" command will output a short note which + ;; mh-exec-cmd will display to the user. + (mh-exec-cmd (expand-file-name "install-mh" mh-lib) "-auto") + ;; now try again to read the profile file + (erase-buffer) + (condition-case err + (insert-file-contents profile) + (file-error + (error "Cannot read MH profile \"%s\": %s" + profile (car (cdr (cdr err))))))) + + +(defun mh-set-folder-modified-p (flag) + "Mark current folder as modified or unmodified according to FLAG." + (set-buffer-modified-p flag)) + + +(defun mh-find-seq (name) (assoc name mh-seq-list)) + +(defun mh-make-seq (name msgs) (cons name msgs)) + +(defun mh-seq-to-msgs (seq) + "Return a list of the messages in SEQUENCE." + (mh-seq-msgs (mh-find-seq seq))) + + +(defun mh-add-msgs-to-seq (msgs seq &optional internal-flag) + ;; Add MESSAGE(s) to the SEQUENCE. If optional FLAG is non-nil, do not mark + ;; the message in the scan listing or inform MH of the addition. + (let ((entry (mh-find-seq seq))) + (if (and msgs (atom msgs)) (setq msgs (list msgs))) + (if (null entry) + (setq mh-seq-list (cons (mh-make-seq seq msgs) mh-seq-list)) + (if msgs (setcdr entry (append msgs (cdr entry))))) + (cond ((not internal-flag) + (mh-add-to-sequence seq msgs) + (mh-notate-seq seq ?% (1+ mh-cmd-note)))))) + +(autoload 'mh-add-to-sequence "mh-seq") +(autoload 'mh-notate-seq "mh-seq") +(autoload 'mh-read-seq-default "mh-seq") +(autoload 'mh-map-to-seq-msgs "mh-seq") + + +(defun mh-set-mode-name (mode-name-string) + ;; Set the mode-name and ensure that the mode line is updated. + (setq mode-name mode-name-string) + ;; Force redisplay of all buffers' mode lines to be considered. + (save-excursion (set-buffer (other-buffer))) + (set-buffer-modified-p (buffer-modified-p))) + + +(defun mh-prompt-for-folder (prompt default can-create) + ;; Prompt for a folder name with PROMPT. Returns the folder's name as a + ;; string. DEFAULT is used if the folder exists and the user types return. + ;; If the CAN-CREATE flag is t, then a non-existent folder is made. + (if (null default) + (setq default "")) + (let* ((prompt (format "%s folder%s" prompt + (if (equal "" default) + "? " + (format " [%s]? " default)))) + read-name folder-name) + (if (null mh-folder-list) + (mh-set-folder-list)) + (while (and (setq read-name (completing-read prompt mh-folder-list + nil nil "+")) + (equal read-name "") + (equal default ""))) + (cond ((or (equal read-name "") (equal read-name "+")) + (setq read-name default)) + ((not (mh-folder-name-p read-name)) + (setq read-name (format "+%s" read-name)))) + (setq folder-name read-name) + (cond ((and (> (length folder-name) 0) + (eql (aref folder-name (1- (length folder-name))) ?/)) + (setq folder-name (substring folder-name 0 -1)))) + (let ((new-file-p (not (file-exists-p (mh-expand-file-name folder-name))))) + (cond ((and new-file-p + (y-or-n-p + (format "Folder %s does not exist. Create it? " folder-name))) + (message "Creating %s" folder-name) + (call-process "mkdir" nil nil nil (mh-expand-file-name folder-name)) + (message "Creating %s...done" folder-name) + (setq mh-folder-list (cons (list read-name) mh-folder-list))) + (new-file-p + (error "Folder %s is not created" folder-name)) + ((and (null (assoc read-name mh-folder-list)) + (null (assoc (concat read-name "/") mh-folder-list))) + (setq mh-folder-list (cons (list read-name) mh-folder-list))))) + folder-name)) + + +(defvar mh-make-folder-list-process nil + "The background process collecting the folder list.") + +(defvar mh-folder-list-temp nil + "mh-folder-list as it is being built.") + +(defvar mh-folder-list-partial-line "" + "Start of last incomplete line from folder process.") + +(defun mh-set-folder-list () + "Sets mh-folder-list correctly. +A useful function for the command line or for when you need to sync by hand. +Format is in a form suitable for completing read." + (message "Collecting folder names...") + (if (not mh-make-folder-list-process) + (mh-make-folder-list-background)) + (while (eq (process-status mh-make-folder-list-process) 'run) + (accept-process-output mh-make-folder-list-process)) + (setq mh-folder-list mh-folder-list-temp) + (setq mh-folder-list-temp nil) + (delete-process mh-make-folder-list-process) + (setq mh-make-folder-list-process nil) + (message "Collecting folder names...done")) + +(defun mh-make-folder-list-background () + "Start a background process to compute a list of the user's folders. +Call mh-set-folder-list to wait for the result." + (cond + ((not mh-make-folder-list-process) + (mh-find-progs) + (let ((process-connection-type nil)) + (setq mh-make-folder-list-process + (start-process "folders" nil (expand-file-name "folders" mh-progs) + "-fast" + (if mh-recursive-folders + "-recurse" + "-norecurse"))) + (set-process-filter mh-make-folder-list-process + 'mh-make-folder-list-filter) + (process-kill-without-query mh-make-folder-list-process))))) + +(defun mh-make-folder-list-filter (process output) + ;; parse output from "folders -fast" + (let ((position 0) + (line-end t) + new-folder) + (while line-end + (setq line-end (string-match "\n" output position)) + (cond + (line-end ;make sure got complete line + (setq new-folder (format "+%s%s" + mh-folder-list-partial-line + (substring output position line-end))) + (setq mh-folder-list-partial-line "") + ;; is new folder a subfolder of previous? + (if (and mh-folder-list-temp + (string-match (regexp-quote + (concat (car (car mh-folder-list-temp)) "/")) + new-folder)) + ;; append slash to parent folder for better completion + ;; (undone by mh-prompt-for-folder) + (setq mh-folder-list-temp + (cons (list new-folder) + (cons + (list (concat (car (car mh-folder-list-temp)) "/")) + (cdr mh-folder-list-temp)))) + (setq mh-folder-list-temp + (cons (list new-folder) + mh-folder-list-temp))) + (setq position (1+ line-end))))) + (setq mh-folder-list-partial-line (substring output position)))) + + +(defun mh-folder-name-p (name) + ;; Return non-NIL if NAME is possibly the name of a folder. + ;; A name (a string or symbol) can be a folder name if it begins with "+". + (if (symbolp name) + (eql (aref (symbol-name name) 0) ?+) + (and (> (length name) 0) + (eql (aref name 0) ?+)))) + + +;;; Issue commands to MH. + + +(defun mh-exec-cmd (command &rest args) + ;; Execute mh-command COMMAND with ARGS. + ;; Any output is assumed to be an error and is shown to the user. + (save-excursion + (set-buffer (get-buffer-create " *mh-temp*")) + (erase-buffer) + (apply 'call-process + (expand-file-name command mh-progs) nil t nil + (mh-list-to-string args)) + (if (> (buffer-size) 0) + (save-window-excursion + (switch-to-buffer-other-window " *mh-temp*") + (sit-for 5))))) + + +(defun mh-exec-cmd-error (env command &rest args) + ;; In environment ENV, execute mh-command COMMAND with args ARGS. + ;; ENV is nil or a string of space-separated "var=value" elements. + ;; Signals an error if process does not complete successfully. + (save-excursion + (set-buffer (get-buffer-create " *mh-temp*")) + (erase-buffer) + (let ((status + (if env + ;; the shell hacks necessary here shows just how broken Unix is + (apply 'call-process "/bin/sh" nil t nil "-c" + (format "%s %s ${1+\"$@\"}" + env + (expand-file-name command mh-progs)) + command + (mh-list-to-string args)) + (apply 'call-process + (expand-file-name command mh-progs) nil t nil + (mh-list-to-string args))))) + (mh-handle-process-error command status)))) + + +(defun mh-exec-cmd-daemon (command &rest args) + ;; Execute MH command COMMAND with ARGS. Any output from command is + ;; displayed in an asynchronous pop-up window. + (save-excursion + (set-buffer (get-buffer-create " *mh-temp*")) + (erase-buffer)) + (let* ((process-connection-type nil) + (process (apply 'start-process + command nil + (expand-file-name command mh-progs) + (mh-list-to-string args)))) + (set-process-filter process 'mh-process-daemon))) + +(defun mh-process-daemon (process output) + ;; Process daemon that puts output into a temporary buffer. + (set-buffer (get-buffer-create " *mh-temp*")) + (insert-before-markers output) + (display-buffer " *mh-temp*")) + + +(defun mh-exec-cmd-quiet (raise-error command &rest args) + ;; Args are RAISE-ERROR, COMMANDS, ARGS.... + ;; Execute MH command COMMAND with ARGS. ARGS is a list of strings. + ;; Return at start of mh-temp buffer, where output can be parsed and used. + ;; Returns value of call-process, which is 0 for success, + ;; unless RAISE-ERROR is non-nil, in which case an error is signaled + ;; if call-process returns non-0. + (set-buffer (get-buffer-create " *mh-temp*")) + (erase-buffer) + (let ((value + (apply 'call-process + (expand-file-name command mh-progs) nil t nil + args))) + (goto-char (point-min)) + (if raise-error + (mh-handle-process-error command value) + value))) + + +(defun mh-exec-cmd-output (command display &rest args) + ;; Execute MH command COMMAND with DISPLAY flag and ARGS. + ;; Put the output into buffer after point. Set mark after inserted text. + (push-mark (point) t) + (apply 'call-process + (expand-file-name command mh-progs) nil t display + (mh-list-to-string args)) + (exchange-point-and-mark)) + + +(defun mh-exec-lib-cmd-output (command &rest args) + ;; Execute MH library command COMMAND with ARGS. + ;; Put the output into buffer after point. Set mark after inserted text. + (apply 'mh-exec-cmd-output (expand-file-name command mh-lib) nil args)) + + +(defun mh-handle-process-error (command status) + ;; Raise error if COMMAND returned non-0 STATUS, otherwise return STATUS. + ;; STATUS is return value from call-process. + ;; Program output is in current buffer. + ;; If output is too long ot include in error message, display the bufffer. + (cond ((eql status 0) ;success + status) + ((stringp status) ;kill string + (error (format "%s: %s" command status))) + (t ;exit code + (cond + ((= (buffer-size) 0) ;program produced no error message + (error (format "%s: exit code %d" command status))) + (t + ;; will error message fit on one line? + (goto-line 2) + (if (and (< (buffer-size) (screen-width)) + (eobp)) + (error (buffer-substring 1 (progn (goto-char 1) + (end-of-line) + (point)))) + (display-buffer (current-buffer)) + (error (format + "%s failed with status %d. See error message in other window." + command status)))))))) + + +(defun mh-expand-file-name (filename &optional default) + "Just like `expand-file-name', but also handles MH folder names. +Assumes that any filename that starts with '+' is a folder name." + (if (mh-folder-name-p filename) + (expand-file-name (substring filename 1) mh-user-path) + (expand-file-name filename default))) + + +(defun mh-list-to-string (l) + ;; Flattens the list L and makes every element of the new list into a string. + (nreverse (mh-list-to-string-1 l))) + +(defun mh-list-to-string-1 (l) + (let ((new-list nil)) + (while l + (cond ((null (car l))) + ((symbolp (car l)) + (setq new-list (cons (symbol-name (car l)) new-list))) + ((numberp (car l)) + (setq new-list (cons (int-to-string (car l)) new-list))) + ((equal (car l) "")) + ((stringp (car l)) (setq new-list (cons (car l) new-list))) + ((listp (car l)) + (setq new-list (nconc (mh-list-to-string-1 (car l)) + new-list))) + (t (error "Bad element in mh-list-to-string: %s" (car l)))) + (setq l (cdr l))) + new-list)) + +(provide 'mh-utils) + +(and (not noninteractive) + mh-auto-folder-collect + (mh-make-folder-list-background)) + +;;; mh-utils.el ends here