-(defun mh-print-msg (range)
- "Print RANGE on printer.
-
-Check the documentation of `mh-interactive-range' to see how RANGE is read in
-interactive use.
-
-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 (mh-interactive-range "Print")))
- (message "Printing...")
- (let (msgs)
- ;; Gather message numbers and add them to "printed" sequence.
- (mh-iterate-on-range msg range
- (mh-add-msgs-to-seq msg 'printed t)
- (mh-notate nil mh-note-printed mh-cmd-note)
- (push msg msgs))
- (setq msgs (nreverse msgs))
- ;; Print scan listing if we have more than one message.
- (if (> (length msgs) 1)
- (let* ((msgs-string
- (mapconcat 'identity (mh-list-to-string
- (mh-coalesce-msg-list msgs)) " "))
- (lpr-command
- (format mh-lpr-command-format
- (cond ((listp range)
- (format "Folder: %s, Messages: %s"
- mh-current-folder msgs-string))
- ((symbolp range)
- (format "Folder: %s, Sequence: %s"
- mh-current-folder range)))))
- (scan-command
- (format "scan %s | %s" msgs-string lpr-command)))
- (if mh-print-background-flag
- (mh-exec-cmd-daemon shell-file-name nil "-c" scan-command)
- (call-process shell-file-name nil nil nil "-c" scan-command))))
- ;; Print the messages
- (dolist (msg msgs)
- (let* ((mhl-command (format "%s %s %s"
- (expand-file-name "mhl" mh-lib-progs)
- (if mhl-formfile
- (format " -form %s" mhl-formfile)
- "")
- (mh-msg-filename msg)))
- (lpr-command
- (format mh-lpr-command-format
- (format "%s/%s" mh-current-folder msg)))
- (print-command
- (format "%s | %s" mhl-command lpr-command)))
- (if mh-print-background-flag
- (mh-exec-cmd-daemon shell-file-name nil "-c" print-command)
- (call-process shell-file-name nil nil nil "-c" print-command)))))
- (message "Printing...done"))
+(defun mh-pipe-msg (command include-header)
+ "Pipe message through shell command COMMAND.
+
+You are prompted for the Unix command through which you wish to
+run your message. If you give a prefix argument INCLUDE-HEADER to
+this command, the message header is included in the text passed
+to the command."
+ (interactive
+ (list (read-string "Shell command on message: ") current-prefix-arg))
+ (let ((msg-file-to-pipe (mh-msg-filename (mh-get-msg-num t)))
+ (message-directory default-directory))
+ (save-excursion
+ (set-buffer (get-buffer-create mh-temp-buffer))
+ (erase-buffer)
+ (insert-file-contents msg-file-to-pipe)
+ (goto-char (point-min))
+ (if (not include-header) (search-forward "\n\n"))
+ (let ((default-directory message-directory))
+ (shell-command-on-region (point) (point-max) command nil)))))