[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2. Using MH-E

This chapter is the workhorse of the manual. It goes into more detail about every MH-E command. The default, or "out of the box," behavior is documented.

There are many commands, but don't get intimidated. There are command summaries at the beginning of each section. In case you have or would like to rebind the keys, the command summaries also list the associated Emacs Lisp function. Furthermore, even if you're stranded on a desert island with a laptop and are without your manuals, you can get a summary of all these commands with GNU Emacs online help: use C-h m (describe-mode) for a brief summary of commands or C-h i to read this manual via Info. The online help is quite good; try running C-h C-h C-h. This brings up a list of available help topics, one of which displays the documentation for a given key (like C-h k C-n). Another useful help feature is to view the manual section that describes a given key (such as C-h C-k i). In addition, review 1.1 GNU Emacs Terms and Conventions, if any of the GNU Emacs conventions are strange to you.

In addition to all of the commands, it is also possible to reconfigure MH-E to fit the needs of even the most demanding user. The following sections also describe all of the options, show the defaults, and make recommendations for customization.

However, when customizing your mail environment, first try to change what you want in MH, and only change MH-E if changing MH is not possible. That way you will get the same behavior inside and outside GNU Emacs. Note that MH-E does not provide hooks for customizations that can be done in MH; this omission is intentional.

Many string or integer options are easy to modify using M-x customize-option. For example, to modify the option that controls printing, you would run M-x customize-option RET mh-lpr-command-format RET. In the buffer that appears, modify the string to the right of the variable. For example, you may change the lpr command with `nenscript -G -r -2 -i'%s''. Then use the `State' combobox and select `Save for Future Sessions'. 2.4.4 Printing Your Mail talks more about this option.

Options can also hold boolean values. In Emacs Lisp, the boolean values are nil, which means false, and t, which means true. The customize-option function makes it easy to change boolean values; simply click on the toggle button in the customize buffer. For example, try setting mh-bury-show-buffer to `off' or nil to keep the MH-Show buffer at the top of the buffer stack. Use the `State' combobox and choose `Set for Current Session' to see how the option affects the show buffer. Then choose the `Erase Customization' menu item to reset the option to the default, which places the MH-Show buffer at the bottom of the buffer stack.

The text usually says to turn on an option by setting it to a non-nil value, because sometimes values other than t are meaningful (for example, see mhl-formfile, described in 2.1.1 Viewing Your Mail). Other options, such as hooks, involve a little more Emacs Lisp programming expertise.

You can browse all of the MH-E options with the customize-group function. Try entering M-x customize-group RET mh RET. The other MH-E groups include `mh-buffer', `mh-compose' and `mh-hook'. These groups are also accessible from the `mh' group buffer.

While options can be set via Emacs customization, variables must be modified using Emacs Lisp. For example:

 
(setq mh-progs "/usr/local/bin/mh/")

Any such modifications should be placed in a file called `.emacs' in your home directory (that is, `~/.emacs').

You can "preview" the effects of changing variables before committing the changes to `~/.emacs'. Variables can be changed in the current Emacs session by using M-x set-variable.

I hope I've included enough examples here to get you well on your way. If you want to explore Emacs Lisp further, a programming manual does exist, (12) and you can look at the code itself for examples. Look in the Emacs Lisp directory on your system (such as `/usr/local/lib/emacs/lisp/mail') and find all the `mh-*.el' files there. When calling MH-E and other Emacs Lisp functions directly from Emacs Lisp code, you'll need to know the correct arguments. Use the online help for this. For example, try C-h f mh-execute-commands RET. If you write your own functions, please do not prefix your symbols (variables and functions) with `mh-'. This prefix is reserved for the MH-E package. To avoid conflicts with existing MH-E symbols, use a prefix like `my-' or your initials.

Let's get started!

2.1 Reading Your Mail  
2.2 Sending Mail  
2.3 Editing a Draft  
2.4 Moving Your Mail Around  
2.5 Searching Through Messages  
2.6 Using Sequences  
2.7 Miscellaneous Commands  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.1 Reading Your Mail

The MH-E entry point for reading mail is M-x mh-rmail. This command incorporates your mail and creates a buffer called `+inbox' in MH-Folder mode. The M-x mh-rmail command shows you only new mail, not old mail. (13) The `+inbox' buffer contains scan lines, which are one-line summaries of each incorporated message. You can perform most MH commands on these messages via one- or two-letter commands discussed in this chapter. See scan(1) for a description of the contents of the scan lines, and see the Figure in 1.4 Receiving Mail, for an example.

RET
.
Display a message (mh-show).

SPC
Go to next page in message (mh-page-msg).

BS
Go to previous page in message (mh-previous-page).

, (comma)
Display a message with all header fields (mh-header-display).

n
Display next message (mh-next-undeleted-msg).

p
Display previous message (mh-previous-undeleted-msg).

g
Go to a message (mh-goto-msg).

M-<
Go to first message (mh-first-msg).

M->
Go to last message (mh-last-msg).

t
Toggle between MH-Folder and MH-Folder Show modes (mh-toggle-showing).

D SPC
Go to next message in digest (mh-page-digest).

D BS
Go to previous message in digest (mh-page-digest-backwards).

D b
Break up digest into separate messages (mh-burst-digest).

The following table lists general options and variables. Variables, which must be set with the setq function are designated as such, in contrast to options which are set via the customize interface.

mh-progs
Directory containing MH programs (default: dynamic).

mh-lib
Directory containing MH support files (default: dynamic).

mh-lib-progs
Directory containing MH support programs (default: dynamic).

The following table lists options that are used while reading mail.

mh-do-not-confirm
Don't confirm on non-reversible commands (default: nil).

mh-summary-height
Number of scan lines to show (includes mode line) (default: 4).

mh-folder-mode-hook
Functions to run in MH-Folder mode (default: nil).

mh-clean-message-header
Remove extraneous headers (default: nil).

mh-invisible-headers
Headers to hide (default: A list too long to include here).

mh-visible-headers
Headers to display (default: nil).

mhl-formfile
Format file for mhl (default: nil).

mh-show-hook
Functions to run when showing message (default: nil).

mh-show-mode-hook
Functions to run when showing message (default: nil).

mh-bury-show-buffer
Leave show buffer at bottom of stack (default: t).

mh-show-buffer-mode-line-buffer-id
Name of show buffer in mode line (default: `"{show-%s} %d"').

The variables mh-progs, mh-lib, and mh-lib-progs are used to tell MH-E where the MH programs, supporting files, and supporting programs are kept, respectively. MH-E does try to figure out where they are kept for itself by looking in common places and in the user's `PATH' environment variable, but if it cannot find the directories, or finds the wrong ones, you should set these variables. The name of the directory should be placed in double quotes, and there should be a trailing slash (`/'). See the example in 1.2 Getting Started.

If you never make mistakes, and you do not like confirmations for your actions, you can set mh-do-not-confirm to a non-nil value to disable confirmation for unrecoverable commands such as x (mh-execute-commands). (14) Here's how you set boolean values:

 
(setq mh-do-not-confirm t)

The variable mh-summary-height controls the number of scan lines displayed in the MH-Folder window, including the mode line. The default value of 4 means that 3 scan lines are displayed. Here's how you set numerical values:

 
(setq mh-summary-height 2)              ; only show the current scan line

Normally the buffer for displaying messages is buried at the bottom at the buffer stack. You may wish to disable this feature by setting mh-bury-show-buffer to nil. One advantage of not burying the show buffer is that one can delete the show buffer more easily in an electric buffer list because of its proximity to its associated MH-Folder buffer. Try running M-x electric-buffer-list to see what I mean.

The hook mh-folder-mode-hook is called when a new folder is created with MH-Folder mode. This could be used to set your own key bindings, for example:

 
(defvar my-mh-init-done nil "Non-nil when one-time MH-E settings made.")

(defun my-mh-folder-mode-hook ()
  "Hook to set key bindings in MH-Folder mode."
  (if (not my-mh-init-done)             ; only need to bind the keys once 
      (progn
        (local-set-key "/" 'search-msg)
        (local-set-key "b" 'mh-burst-digest)    ; better use of b
        (setq my-mh-init-done t))))

;;; Emacs 19
(add-hook 'mh-folder-mode-hook 'my-mh-folder-mode-hook)
;;; Emacs 18
;;;   (setq mh-folder-mode-hook (cons 'my-mh-folder-mode-hook
;;;                               mh-folder-mode-hook))

(defun search-msg ()
  "Search for a regexp in the current message."
  (interactive)                         ; user function
  (save-window-excursion
    (other-window 1)                    ; go to next window
    (isearch-forward-regexp)))          ; string search; hit return (ESC
                                        ;   in Emacs 18) when done

Create additional key bindings via mh-folder-mode-hook

Before we leave this section, I'll include a function that I use as a front end to MH-E. (15) It toggles between your working window configuration, which may be quite involved--windows filled with source, compilation output, man pages, and other documentation--and your MH-E window configuration. Like the rest of the customization described in this chapter, simply add the following code to `~/.emacs'.

 
(defvar my-mh-screen-saved nil
  "Set to non-nil when MH-E window configuration shown.")
(defvar my-normal-screen nil "Normal window configuration.")
(defvar my-mh-screen nil "MH-E window configuration.")

(defun my-mh-rmail (&optional arg)
  "Toggle between MH-E and normal screen configurations.
With non-nil or prefix argument, inc mailbox as well
when going into mail."
  (interactive "P")                 ; user callable function, P=prefix arg
  (setq my-mh-screen-saved          ; save state
        (cond
         ;; Bring up MH-E screen if arg or normal window configuration.
         ;; If arg or +inbox buffer doesn't exist, run mh-rmail.
         ((or arg (null my-mh-screen-saved))
          (setq my-normal-screen (current-window-configuration))
          (if (or arg (null (get-buffer "+inbox")))
              (mh-rmail)
            (set-window-configuration my-mh-screen))
          t)                        ; set my-mh-screen-saved to t
         ;; Otherwise, save MH-E screen and restore normal screen.
         (t
          (setq my-mh-screen (current-window-configuration))
          (set-window-configuration my-normal-screen)
          nil))))                   ; set my-mh-screen-saved to nil

(global-set-key "\C-x\r" 'my-mh-rmail)  ; call with C-x RET

Starting MH-E

If you type an argument (C-u) or if my-mh-screen-saved is nil (meaning a non-MH-E window configuration), the current window configuration is saved, either +inbox is displayed or mh-rmail is run, and the MH-E window configuration is shown. Otherwise, the MH-E window configuration is saved and the original configuration is displayed.

The functions and variables introduced here are explained in more detail in the following sections.

2.1.1 Viewing Your Mail  
2.1.2 Moving Around  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.1.1 Viewing Your Mail

The RET (mh-show) command displays the message that the cursor is on. If the message is already displayed, it scrolls to the beginning of the message. Use SPC (mh-page-msg) and BS (mh-previous-page) to move forwards and backwards one page at a time through the message. You can give either of these commands a prefix argument that specifies the number of lines to scroll (such as 10 SPC). MH-E normally hides a lot of the superfluous header fields that mailers add to a message, but if you wish to see all of them, use the , (comma; mh-header-display) command.

Several variables control what displayed messages look like. Normally messages are delivered with a handful of uninteresting header fields. You can make them go away by setting mh-clean-message-header to a non-nil value. The header can then be cleaned up in two ways. By default, the header fields in mh-invisible-headers are removed. On the other hand, you could set mh-visible-headers to the fields that you would like to see. If this variable is set, mh-invisible-headers is ignored. I suggest that you not set mh-visible-headers since if you use this variable, you might miss a lot of header fields that you'd rather not miss. As an example of how to set a string variable, mh-visible-headers can be set to show a minimum set of header fields (see (section `Syntax of Regular Expressions' in The GNU Emacs Manual, for a description of the special characters in this string):

 
(setq mh-visible-headers "^From: \\|^Subject: \\|^Date: ")

Normally MH-E takes care of displaying messages itself (rather than calling an MH program to do the work). If you'd rather have mhl display the message (within MH-E), set the variable mhl-formfile to a non-nil value. You can set this variable either to t to use the default format file or to a filename if you have your own format file (mhl(1) or section Using mhl in the MH book tells you how to write one). When writing your own format file, use a nonzero value for `overflowoffset' to ensure the header is RFC 822 compliant and parsable by MH-E. mhl is always used for printing and forwarding; in this case, the value of mhl-formfile is consulted if it is a filename.

Two hooks can be used to control how messages are displayed. The first hook, mh-show-mode-hook, is called early on in the process of displaying of messages. It is used to perform some actions on the contents of messages, such as highlighting the header fields. If you're running Emacs 19 under the X Window System, the following example will highlight the `From:' and `Subject:' header fields. This is a very nice feature indeed.

 
(defvar my-mh-keywords
   '(("^From: \\(.*\\)" 1 'bold t)
     ("^Subject: \\(.*\\)" 1 'highlight t))
  "MH-E additions for font-lock-keywords.")

(defun my-mh-show-mode-hook ()
  "Hook to turn on and customize fonts."
  (font-lock-add-keywords nil my-mh-keywords))

(add-hook 'mh-show-mode-hook 'my-mh-show-mode-hook))

Emphasize header fields in different fonts via mh-show-mode-hook

The second hook, mh-show-hook, is the last thing called after messages are displayed. It's used to affect the behavior of MH-E in general or when mh-show-mode-hook is too early. For example, if you wanted to keep MH-E in sync with MH, you could use mh-show-hook as follows:

 
(add-hook 'mh-show-hook 'mh-update-sequences)

The function mh-update-sequences is documented in 2.4.7 Finishing Up. For those who like to modify their mode lines, use mh-show-buffer-mode-line-buffer-id to modify the mode line in the MH-Show buffers. Place the two escape strings `%s' and `%d', which will display the folder name and the message number, respectively, somewhere in the string in that order. The default value of `"{show-%s} %d"' yields a mode line of

 
-----{show-+inbox} 4      (MH-Show)--Bot--------------------------------

2.1.1.1 Reading Digests  
2.1.1.2 Reading Multimedia Mail  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.1.1.1 Reading Digests

A digest is a message that contains other messages. Special MH-E commands let you read digests conveniently. You can use SPC and BS to page through the digest as if it were a normal message, but if you wish to skip to the next message in the digest, use D SPC (mh-page-digest). To return to a previous message, use D BS (mh-page-digest-backwards).

Another handy command is D b (mh-burst-digest). This command uses the MH command burst (16) to break out each message in the digest into its own message. Using this command, you can quickly delete unwanted messages, like this: Once the digest is split up, toggle out of MH-Folder Show mode with t (see section 2.1.2 Moving Around) so that the scan lines fill the screen and messages aren't displayed. Then use d (see section 2.4.2 Deleting Your Mail) to quickly delete messages that you don't want to read (based on the `Subject:' header field). You can also burst the digest to reply directly to the people who posted the messages in the digest. One problem you may encounter is that the `From:' header fields are preceded with a `>' so that your reply can't create the `To:' field correctly. In this case, you must correct the `To:' field yourself. This is described later in 2.3.1 Editing Textual Messages.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.1.1.2 Reading Multimedia Mail

MH has the ability to read MIME (Multipurpose Internet Mail Extensions) messages. Unfortunately, MH-E does not yet have this ability, so you have to use the MH commands show (17) or mhshow (18) from the shell to read MIME messages. (19)


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.1.2 Moving Around

To move on to the next message, use the n (mh-next-undeleted-msg) command; use the p (mh-previous-undeleted-msg) command to read the previous message. Both of these commands can be given a prefix argument to specify how many messages to skip (for example, 5 n). You can also move to a specific message with g (mh-goto-msg). You can enter the message number either before or after typing g. In the latter case, Emacs prompts you. Finally, you can go to the first or last message with M-< (mh-first-msg) and M-> (mh-last-msg) respectively.

You can also use the Emacs commands C-p (previous-line) and C-n (next-line) to move up and down the scan lines in the MH-Folder window. These commands can be used in conjunction with RET to look at deleted or refiled messages.

The command t (mh-toggle-showing) switches between MH-Folder mode and MH-Folder Show mode. (20) MH-Folder mode turns off the associated show buffer so that you can perform operations on the messages quickly without reading them. This is an excellent way to prune out your junk mail or to refile a group of messages to another folder for later examination.

When you use t (mh-toggle-showing) to toggle between show mode and scan mode, the MH-Show buffer is hidden and the MH-Folder buffer is left alone. Setting mh-recenter-summary-p to a non-nil value causes the toggle to display as many scan lines as possible, with the cursor at the middle. The effect of mh-recenter-summary-p is rather useful, but it can be annoying on a slow network connection.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.2 Sending Mail

You can send a mail message in several ways. You can call M-x mh-smail directly, or from the command line like this:

 
$ emacs -f mh-smail

From within MH-E's MH-Folder mode, other methods of sending mail are available as well:

m
Compose a message (mh-send).

r
Reply to a message (mh-reply).

f
Forward message(s) (mh-forward).

M-d
Redistribute a message (mh-redistribute).

E
Edit a message that was bounced by mailer (mh-extract-rejected-mail).

e
Edit a message to send it again (mh-edit-again).

From within a MH-Folder buffer, you can simply use the command m (mh-send). However you invoke mh-send, you are prompted for the `To:', `cc:', and `Subject:' header fields. Once you've specified the recipients and subject, your message appears in an Emacs buffer whose mode is MH-Letter (see the Figure in 2.2 Sending Mail to see what the buffer looks like). MH-Letter mode allows you to edit your message, to check the validity of the recipients, to insert other messages into your message, and to send the message. We'll go more into depth about editing a draft (21) (a message you're composing) in just a moment.

mh-smail always creates a two-window layout with the current buffer on top and the draft on the bottom. If you would rather preserve the window layout, use M-x mh-smail-other-window.

You may wish to start off by adding the following useful key bindings to your `.emacs' file:

 
(global-set-key "\C-xm" 'mh-smail)
(global-set-key "\C-x4m" 'mh-smail-other-window)

In addition, several variables are useful when sending mail or replying to mail. They are summarized in the following table.

mh-comp-formfile
Format file for drafts (default: `"components"').

mh-repl-formfile
Format file for replies (default: `"replcomps"').

mh-letter-mode-hook
Functions to run in MH-Letter mode (default: nil).

mh-compose-letter-function
Functions to run when starting a new draft (default: nil).

mh-reply-default-reply-to
Whom reply goes to (default: nil).

mh-forward-subject-format
Format string for forwarded message subject (default: `"%s: %s"').

mh-redist-full-contents
send requires entire message (default: nil).

mh-new-draft-cleaned-headers
Remove these header fields from re-edited draft (default: `"^Date:\\| ^Received:\\| ^Message-Id:\\| ^From:\\| ^Sender:\\|
^Delivery-Date:\\| ^Return-Path:"
').

Since MH-E does not use comp (22) to create the initial draft, you need to set mh-comp-formfile to the name of your components file if it isn't `components'. This is the name of the file that contains the form for composing messages. If it does not contain an absolute pathname, MH-E searches for the file first in your MH directory and then in the system MH library directory (such as `/usr/local/lib/mh'). Replies, on the other hand, are built using repl. (23) You can change the location of the field file from the default of `replcomps' by modifying mh-repl-formfile.

Two hooks are provided to run commands on your freshly created draft. The first hook, mh-letter-mode-hook, allows you to do some processing before editing a letter. For example, you may wish to modify the header after repl has done its work, or you may have a complicated `components' file and need to tell MH-E where the cursor should go. Here's an example of how you would use this hook--all of the other hooks are set in this fashion as well.

 
(defvar letter-mode-init-done nil
  "Non-nil when one-time MH-E settings have made.")

(defun my-mh-letter-mode-hook ()
  "Hook to prepare letter for editing."
  (if (not letter-mode-init-done)    ; only need to bind the keys once
      (progn
        (local-set-key "\C-ctb" 'add-enriched-text)
        (local-set-key "\C-cti" 'add-enriched-text)
        (local-set-key "\C-ctf" 'add-enriched-text)
        (local-set-key "\C-cts" 'add-enriched-text)
        (local-set-key "\C-ctB" 'add-enriched-text)
        (local-set-key "\C-ctu" 'add-enriched-text)
        (local-set-key "\C-ctc" 'add-enriched-text)
        (setq letter-mode-init-done t)))
  (setq fill-prefix "  ")            ; I find indented text easier to read
  (save-excursion
    (goto-char (point-max))          ; go to end of message to
    (mh-insert-signature)))          ;   insert signature

(add-hook 'mh-letter-mode-hook 'my-mh-letter-mode-hook)

Prepare draft for editing via mh-letter-mode-hook

The function, add-enriched-text is defined in the example in 2.3.2 Editing Multimedia Messages.

The second hook, a function really, is mh-compose-letter-function. Like mh-letter-mode-hook, it is called just before editing a new message; however, it is the last function called before you edit your message. The consequence of this is that you can write a function to write and send the message for you. This function is passed three arguments: the contents of the `To:', `Subject:', and `cc:' header fields.

The functions and variables introduced here are explained in more detail in the following sections.

2.2.1 Replying to Mail  
2.2.2 Forwarding Mail  
2.2.3 Redistributing Your Mail  
2.2.4 Editing Old Drafts and Bounced Messages  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.2.1 Replying to Mail

To compose a reply to a message, use the r (mh-reply) command. If you supply a prefix argument (as in C-u r), the message you are replying to is inserted in your reply after having first been run through mhl with the format file `mhl.reply'. See mhl(1) or the section Using mhl in the MH book to see how you can modify the default `mhl.reply' file.

When you reply to a message, you are first prompted with `Reply to whom?'. You have several choices here.

 
Response     Reply Goes To

from         The person who sent the message.  This is the default,
             so RET is sufficient.

to           Replies to the sender, plus all recipients in the
             `To:' header field.

all
cc           Forms a reply to the sender, plus all recipients.

Depending on your answer, repl (24) is given a different argument to form your reply. Specifically, a choice of from or none at all runs `repl -nocc all', and a choice of to runs `repl -cc to'. Finally, either cc or all runs `repl -cc all -nocc me'.

Two windows are then created. One window contains the message to which you are replying. Your draft, in MH-Letter mode (described in 2.3 Editing a Draft), is in the other window.

If you wish to customize the header or other parts of the reply draft, please see repl(1) and mh-format(5).

If you find that most of the time that you specify cc when you reply to a message, set mh-reply-default-reply-to to `cc'. This variable is normally set to nil so that you are prompted for the recipient of a reply. It can be set to one of `from', `to', or `cc'; you are then no longer prompted for the recipient(s) of your reply.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.2.2 Forwarding Mail

To forward a message, use the f (mh-forward) command. You are given a draft to edit that looks like it would if you had run the MH command forw. (25) You are given a chance to add some text (see 2.3 Editing a Draft).

You can forward several messages by using a prefix argument; in this case, you are prompted for the name of a sequence, a symbolic name that represents a list or range of message numbers (for example, C-u f forbob RET). All of the messages in the sequence are inserted into your draft. By the way, although sequences are often mentioned in this chapter, you don't have to worry about them for now; the full description of sequences in MH-E is at the end in 2.6 Using Sequences. To learn more about sequences in general, please see mh-sequence(5).

When forwarding a message, the format of the `Subject:' header field can be modified by the variable mh-forward-subject-format. This variable is a string which includes two escapes (`%s'). The first `%s' is replaced with the sender of the original message, and the second one is replaced with the original `Subject:'. The default value of `"%s: %s"' takes a message with the header:

 
To: Bill Wohler <wohler@newt.com>
Subject: Re: 49er football
From: Greg DesBrisay <gd@cellnet.com>

and creates a subject header field of:

 
Subject: Greg DesBrisay: Re: 49er football


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.2.3 Redistributing Your Mail

The command M-d (mh-redistribute) is similar in function to forwarding mail, but it does not allow you to edit the message, nor does it add your name to the `From:' header field. It appears to the recipient as if the message had come from the original sender. For more information on redistributing messages, see dist(1). Also investigate the e (mh-edit-again) command in 2.2.4 Editing Old Drafts and Bounced Messages, for another way to redistribute messages.

The variable mh-redist-full-contents must be set to non-nil if dist (26) requires the whole letter for redistribution, which is the case if send (27) is compiled with the BERK (28) option (which many people abhor). If you find that MH will not allow you to redistribute a message that has been redistributed before, this variable should be set to nil.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.2.4 Editing Old Drafts and Bounced Messages

If you don't complete a draft for one reason or another, and if the draft buffer is no longer available, you can pick your draft up again with e (mh-edit-again). If you don't use a draft folder, your last `draft' file will be used. If you use draft folders, you'll need to visit the draft folder with F v drafts RET, use n to move to the appropriate message, and then use e to prepare the message for editing.

The e command can also be used to take messages that were sent to you and to send them to more people.

Don't use e to re-edit a message from a Mailer-Daemon who complained that your mail wasn't posted for some reason or another. In this case, use E (mh-extract-rejected-mail) to prepare the message for editing by removing the Mailer-Daemon envelope and unneeded header fields. Fix whatever addressing problem you had, and send the message again with C-c C-c.

The header fields specified by mh-new-draft-cleaned-headers are removed from an old draft that has been recreated with E (mh-extract-rejected-mail) or e (mh-edit-again). If when you edit an old draft with these commands you find that there are header fields that you don't want included, you can append them to this variable. For example,

 
(setq mh-new-draft-cleaned-headers
      (concat mh-new-draft-cleaned-headers "\\|^Some-Field:"))

This appends the regular expression `\\|^Some-Field:' to the variable (see section `Syntax of Regular Expressions' in The GNU Emacs Manual). The `\\|' means or, and the `^' (caret) matches the beginning of the line. This is done to be very specific about which fields match. The literal `:' is appended for the same reason.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.3 Editing a Draft

When you edit a message that you want to send (called a draft in this case), the mode used is MH-Letter. This mode provides several commands in addition to the normal Emacs editing commands to help you edit your draft.

C-c C-y
Insert contents of message to which you're replying (mh-yank-cur-msg).

C-c C-i
Insert a message from a folder (mh-insert-letter).

C-c C-f C-t
Move to `To:' header field (mh-to-field).

C-c C-f C-c
Move to `cc:' header field (mh-to-field).

C-c C-f C-s
Move to `Subject:' header field (mh-to-field).

C-c C-f C-f
Move to `From:' header field (mh-to-field).

C-c C-f C-b
Move to `Bcc:' header field (mh-to-field).

C-c C-f C-f
Move to `Fcc:' header field (mh-to-fcc).

C-c C-f C-d
Move to `Dcc:' header field (mh-to-field).

C-c C-w
Display expanded recipient list (mh-check-whom).

C-c C-s
Insert signature in message (mh-insert-signature).

C-c C-m C-f
Include forwarded message (MIME) (mh-mhn-compose-forw).

C-c C-m C-e
Include anonymous ftp reference (MIME) (mh-mhn-compose-anon-ftp).

C-c C-m C-t
Include anonymous ftp reference to compressed tar file (MIME) (mh-mhn-compose-external-compressed-tar).

C-c C-m C-i
Include binary, image, sound, etc. (MIME) (mh-mhn-compose-insertion).

C-c C-e
Run through mhn before sending (mh-edit-mhn).

C-c C-m C-u
Undo effects of mhn (mh-revert-mhn-edit).

C-c C-c
Save draft and send message (mh-send-letter).

C-c C-q
Quit editing and delete draft message (mh-fully-kill-draft).

The functions and variables introduced here are explained in more detail in the following sections.

2.3.1 Editing Textual Messages  
2.3.2 Editing Multimedia Messages  
2.3.3 Sending a Message  
2.3.4 Killing the Draft  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.3.1 Editing Textual Messages

The following sections show you how to edit a draft. The commands described here are also applicable to messages that have multimedia components.

The following two sections include variables that customize the way you edit a draft. The discussion here applies to editing multimedia messages as well.

2.3.1.1 Inserting letter to which you're replying  
2.3.1.2 Inserting messages  
2.3.1.3 Editing the header  
2.3.1.4 Checking recipients  
2.3.1.5 Inserting your signature  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.3.1.1 Inserting letter to which you're replying

It is often useful to insert a snippet of text from a letter that someone mailed to provide some context for your reply. The command C-c C-y (mh-yank-cur-msg) does this by yanking a portion of text from the message to which you're replying and inserting `> ' before each line.

You can control how much text is included when you run this command. If you run this command right away, without entering the buffer containing the message to you, this command will yank the entire message, as is, into your reply. (29) If you enter the buffer containing the message sent to you and move the cursor to a certain point and return to your reply and run C-c C-y, then the text yanked will range from that point to the end of the message. Finally, the most common action you'll perform is to enter the message sent to you, move the cursor to the beginning of a paragraph or phrase, set the mark with C-SPC or C-@, and move the cursor to the end of the paragraph or phrase. The cursor position is called the point, and the space between the mark and point is called the region. Having done that, C-c C-y will insert the region you selected.

To control how much of the message to which you are replying is yanked by C-c C-y (mh-yank-cur-msg) into your reply, modify mh-yank-from-start-of-msg. The default value of t means that the entire message is copied. If it is set to 'body (don't forget the apostrophe), then only the message body is copied. If it is set to nil, only the part of the message following point (the current cursor position in the message's buffer) is copied. In any case, this variable is ignored if a region is set in the message you are replying to.

The string contained in mh-ins-buf-prefix is inserted before each line of a message that is inserted into a draft with C-c C-y (mh-yank-cur-msg). I suggest that you not modify this variable. The default value of `"> "' is the default string for many mailers and news readers: messages are far easier to read if several included messages have all been indented by the same string. The variable mail-citation-hook is nil by default, which means that when a message is inserted into the letter, each line is prefixed by mh-ins-buf-prefix. Otherwise, it can be set to a function that modifies an included citation. (30)

If you like to yank all the text from the message you're replying to in one go, set mh-delete-yanked-msg-window to non-nil to delete the window containing the original message after yanking it to make more room on your screen for your reply.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.3.1.2 Inserting messages

Messages can be inserted with C-c C-i (mh-insert-letter). This command prompts you for the folder and message number and inserts the message, indented by `> '. Certain undesirable header fields are removed before insertion. If given a prefix argument (like C-u C-c C-i), the header is left intact, the message is not indented, and `> ' is not inserted before each line.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.3.1.3 Editing the header

Because the header is part of the message, you can edit the header fields as you wish. However, several convenience functions exist to help you create and edit them. For example, the command C-c C-f C-t (mh-to-field; alternatively, C-c C-f t) moves the cursor to the `To:' header field, creating it if necessary. The functions to move to the `cc:', `Subject:', `From:', `Bcc:', and `Dcc:' header fields are similar.

One function behaves differently from the others, namely, C-c C-f C-f (mh-to-fcc; alternatively, C-c C-f f). This function will prompt you for the folder name in which to file a copy of the draft.

Be sure to leave a row of dashes or a blank line between the header and the body of the message.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.3.1.4 Checking recipients

The C-c C-w (mh-check-whom) command expands aliases so you can check the actual address(es) in the alias. A new buffer is created with the output of whom. (31)


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.3.1.5 Inserting your signature

You can insert your signature at the current cursor location with the C-c C-s (mh-insert-signature) command. The text of your signature is taken from the file `~/.signature'.

You can change the name of this file by changing mh-signature-file-name.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.3.2 Editing Multimedia Messages

MH-E has the capability to create multimedia messages. It uses the MIME (Multipurpose Internet Mail Extensions) protocol (32) The MIME protocol allows you to incorporate images, sound, video, binary files, and even commands that fetch a file with `ftp' when your recipient reads the message!

If you were to create a multimedia message with plain MH commands, you would use mhn. Indeed, the MH-E MIME commands, prefixed with C-c C-m and described in detail in the sub-sections that follow, merely insert mhn directives which are later expanded by mhn. One or more of these directives may be inserted into your message. Remember: you can always add mhn directives by hand. (33)

The MH-E MIME commands require a media type for each body part or attachment. Some fill in the media type for you, whereas others require you to enter one.

In the cases where MH-E can do so, it will determine the media type automatically. It uses the file command to do this. Failing that, the Emacs function mailcap-mime-types is used to provide a list from which to choose. This function usually reads the file `/etc/mime.types'. If all else fails, the list is taken from mh-mime-content-types.

The variable mh-mime-content-types (34) contains a list of the most frequently used media types. If your system does fall back to using this variable and you encounter a new media type that you want to add to the list of types available for media type completion, you can add it like this:

 
(setq mh-mime-content-types (append mh-mime-content-types
                                    '(("new/type"))))

No matter how you add the media type, use the type that seems to match best the file that you are including. In the case of binaries, the media type `application/x-executable' can be useful. If you can't find an appropriate media type, use `text/plain' for text messages and `application/octet-stream' for everything else.

You are also sometimes asked for a content description. This is simply an optional brief phrase, in your own words, that describes the object. If you don't care to enter a content description, just press return and none will be included; however, a reader may skip over multimedia fields unless the content description is compelling.

To close this section, I'll describe an Emacs function which can be used to insert enriched text directives to liven up your plain text messages with boldface, underlining, and italics.

 
(defvar enriched-text-types '(("b" . "bold") ("i" . "italic")
                              ("u" . "underline") 
                              ("s" . "smaller") ("B" . "bigger")
                              ("f" . "fixed")
                              ("c" . "center"))
  "Alist of (final-character . directive) choices for add-enriched-text.
Additional types can be found in RFC 1563.")

(defun add-enriched-text (begin end)
  "Add enriched text directives around region.
The directive used comes from the list enriched-text-types and is
specified by the last keystroke of the command.  When called from Lisp,
arguments are BEGIN and END."
  (interactive "r")
  ;; Set type to the directive indicated by the last keystroke.
  (let ((type (cdr (assoc (char-to-string (logior last-input-char ?`))
                          enriched-text-types))))
    (save-restriction              ; restores state from narrow-to-region
      (narrow-to-region begin end) ; narrow view to region
      (goto-char (point-min))      ; move to beginning of text
      (insert "<" type ">")        ; insert beginning directive
      (goto-char (point-max))      ; move to end of text
      (insert "</" type ">"))))    ; insert terminating directive

Emacs function for entering enriched text

To use the function add-enriched-text, first add it to your `.emacs' file and create keybindings for it (see section 2.2 Sending Mail).

Then, in your plain text message, set the mark with C-@ or C-SPC, type in the text to be highlighted, and type C-c t b. This adds `<bold>' where you set the mark and adds `</bold>' at the location of your cursor, giving you something like: `You should be <bold>very</bold>'.

Before sending this message, use C-c C-e (mh-edit-mhn) to add MIME header fields. Then replace `text/plain' with `text/enriched' in the `Content-Type' header field.

You may also be interested in investigating sgml-mode.

2.3.2.1 Forwarding multimedia messages  
2.3.2.2 Including an ftp reference  
2.3.2.3 Including tar files  
2.3.2.4 Including other multimedia objects  
2.3.2.5 Readying multimedia messages for sending  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.3.2.1 Forwarding multimedia messages

Mail may be forwarded with MIME using the command C-c C-m C-f (mh-mhn-compose-forw). You are prompted for a content description, the name of the folder in which the messages to forward are located, and the messages' numbers.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.3.2.2 Including an ftp reference

You can even have your message initiate an ftp transfer when the recipient reads the message. To do this, use the C-c C-m C-e (mh-mhn-compose-anon-ftp) command. You are prompted for the remote host and pathname, the media type, and the content description.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.3.2.3 Including tar files

If the remote file (see section 2.3.2.2 Including an ftp reference) is a compressed tar file, you can use C-c C-m C-t (mh-mhn-compose-external-compressed-tar). Then, in addition to retrieving the file via anonymous ftp, the file will also be uncompressed and untarred. You are prompted for the remote host and pathname and the content description. The pathname should contain at least one `/' (slash), because the pathname is broken up into directory and name components.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.3.2.4 Including other multimedia objects

Binaries, images, sound, and video can be inserted in your message with the C-c C-m C-i (mh-mhn-compose-insertion) command. You are prompted for the filename containing the object, the media type if it cannot be determined automatically, and a content description of the object. This command may have been mentioned last, but it will be the command you use most.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.3.2.5 Readying multimedia messages for sending

When you are finished editing a MIME message, it might look like this:

 
   3 t08/24  root               received fax files on Wed Aug 24 11:00:
   4+t08/24  To:wohler          Test<<This is a test message to get the





--:%%  {+inbox} 4 msgs (1-4)   (MH-Folder Show)--L4--Bot---------------
To: wohler
cc:
Subject: Test of MIME
--------
#@application/octet-stream [Nonexistent ftp test file] \
access-type=anon-ftp; site=berzerk.com; name=panacea.tar.gz; \
directory="/pub/"
#audio/basic [Test sound bite] /tmp/noise.au
--:**  {draft}   (MH-Letter)--L8--All----------------------------------

MH-E MIME draft

In versions 6.0 and later of MH-E, this message can be sent as described in 2.2 Sending Mail. However, if none of the C-c C-m commands have been used (that is, all of the mhn directives have been added by hand), or you are using an older version of MH-E, you must first convert the mhn directives to MIME directives before sending.

This is accomplished by the command C-c C-e (mh-edit-mhn), which runs mhn on the message. (35) The following screen shows what those commands look like in full MIME format. You can see why mail user agents are usually built to hide these details from the user.

 
To: wohler
cc:
Subject: Test of MIME
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
Content-ID: <1623.777796162.0@newt.com>

This is a MIME-encapsulated message

------- =_aaaaaaaaaa0
Content-Type: message/external-body; access-type="anon-ftp";
        site="berzerk.com"; name="panacea.tar.gz"; directory="/pub/"

Content-Type: application/octet-stream
Content-ID: <1623.777796162.1@newt.com>
Content-Description: Nonexistent ftp test file

------- =_aaaaaaaaaa0
Content-Type: audio/basic
Content-ID: <1623.777796162.2@newt.com>
Content-Description: Test sound bite
Content-Transfer-Encoding: base64

Q3JlYXRpdmUgVm9pY2UgRmlsZRoaAAoBKREBQh8AgwCAgH9/f35+fn59fX5+fn5+f39/f39
f4B/f39/f39/f39/f39/f39+f39+f39/f39/f4B/f39/fn5/f39/f3+Af39/f39/gH9/f39
--:--  {draft}   (MH-Letter)--L2--Top----------------------------------

MH-E MIME draft ready to send

This action can be undone by running C-c C-m C-u (mh-revert-mhn-edit). It does this by reverting to a backup file. You are prompted to confirm this action, but you can avoid the confirmation by adding an argument (for example, C-u C-c C-m C-u).

If you wish to pass additional arguments to mhn to affect how it builds your message, use the variable mh-mhn-args. For example, you can build a consistency check into the message by setting mh-mhn-args to `-check'. The recipient of your message can then run `mhn -check' on the message---mhn will complain if the message has been corrupted on the way. The C-c C-e (mh-mhn-edit) command only consults this variable when given a prefix argument.

Some mailers add a message such as "This is a MIME-encapsulated message" to the top of the message. Note that mhn does not add any messages of this sort. You can always add one yourself after incorporating the MIME body parts with C-c C-e (mh-edit-mhn). Insert your text after the blank line that separates the header from the boundary of the first MIME body part (usually `------- =_aaaaaaaaaa0'). The previous screen shows how this might look.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.3.3 Sending a Message

When you are all through editing a message, you send it with the C-c C-c (mh-send-letter) command. You can give an argument (as in C-u C-c C-c) to monitor the first stage of the delivery.

If you want to check your spelling in your message before sending, use mh-before-send-letter-hook like this:

 
(add-hook 'mh-before-send-letter-hook 'ispell-message)

In case the MH send program (36) is installed under a different name, use mh-send-prog to tell MH-E the name.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.3.4 Killing the Draft

If for some reason you are not happy with the draft, you can kill it instead with C-c C-q (mh-fully-kill-draft). Emacs then kills the draft buffer and deletes the draft message.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.4 Moving Your Mail Around

This section covers how messages and folders can be moved about or manipulated. Messages may be incorporated into your `+inbox', deleted, and refiled. Messages containing shar or uuencode output can be stored. Folders can be visited, sorted, packed, or deleted. Here's a list of the available commands to do these things:

i
Incorporate new mail into folder (mh-inc-folder).

d
Delete message (mh-delete-msg).

C-d
Delete message, don't move to next message (mh-delete-msg-no-motion).

F s
Find messages that meet search criteria (mh-search-folder).

o
Output (refile) message to folder (mh-refile-msg).

c
Copy message to folder (mh-copy-msg).

C-o
Output (write) message to file (mh-write-msg-to-file).

!
Repeat last output command (mh-refile-or-write-again).

l
Print message with lpr (mh-print-msg).

|
Pipe message through shell command (mh-pipe-msg).

X s
Unpack message created with uudecode or shar (mh-store-msg).

F l
List all folders (mh-list-folders).

F v
Visit folder (mh-visit-folder).

F r
Regenerate scan lines (mh-rescan-folder).

M-x mh-sort-folder
Sort folder.

F p
Pack folder (mh-pack-folder).

F k
Remove folder (mh-kill-folder).

x
Execute pending refiles and deletes (mh-execute-commands).

u
Undo pending refile or delete (mh-undo).

F u
Undo all pending refiles and deletes (mh-undo-folder).

q
Quit (mh-quit).

If you change the name of some of the MH programs or have your own printing programs, the following variables can help you.

mh-inc-prog
Program to incorporate mail (default: `"inc"').

mh-inc-folder-hook
Functions to run when incorporating mail (default: nil).

mh-delete-msg-hook
Functions to run when deleting messages (default: nil).

mh-print-background
Print in foreground or background (default: nil).

mh-lpr-command-format
Command used to print (default: `"lpr -J '%s'"').

mh-default-folder-for-message-function
Function to generate a default folder (default: nil).

mh-auto-folder-collect
Collect folder names in background at startup (default: t).

mh-recursive-folders
Collect nested folders (default: nil).

mh-refile-msg-hook
Functions to run when refiling message (default: nil).

mh-store-default-directory
Default directory for storing files created by uuencode or shar (default: nil).

mh-sortm-args
Additional arguments for sortm (default: nil).

mh-scan-prog
Program to scan messages (default: `"scan"').

mh-before-quit-hook
Functions to run before quitting (default: nil). See also mh-quit-hook.

mh-quit-hook
Functions to run after quitting (default: nil). See also mh-before-quit-hook.

The functions and variables introduced here are explained in more detail in the following sections.

2.4.1 Incorporating Your Mail  
2.4.2 Deleting Your Mail  
2.4.3 Organizing Your Mail with Folders  
2.4.4 Printing Your Mail  
2.4.5 Files and Pipes  
2.4.6 Scan Line Formats  
2.4.7 Finishing Up  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.4.1 Incorporating Your Mail

If at any time you receive new mail, incorporate the new mail into your `+inbox' buffer with i (mh-inc-folder). Note that i will display the `+inbox' buffer, even if there isn't any new mail. You can incorporate mail from any file into the current folder by specifying a prefix argument; you'll be prompted for the name of the file to use (for example, C-u i ~/mbox RET).

Emacs can notify you when you have new mail by displaying `Mail' in the mode line. To enable this behavior, and to have a clock in the mode line besides, add the following to `~/.emacs':

 
(display-time)

The name of the program that incorporates new mail is stored in mh-inc-prog; it is `"inc"' by default. This program generates a one-line summary for each of the new messages. Unless it is an absolute pathname, the file is assumed to be in the mh-progs directory. You may also link a file to inc that uses a different format (see `mh-profile'(5), and sections Reading Mail: inc show next prev and MH Format Strings in the MH book). You'll then need to modify several variables appropriately; see 2.4.6 Scan Line Formats below.

You can set the hook mh-inc-folder-hook, which is called after new mail is incorporated by the i (mh-inc-folder) command. A good use of this hook is to rescan the whole folder either after running M-x mh-rmail the first time or when you've changed the message numbers from outside of MH-E.

 
(defun my-mh-inc-folder-hook ()
  "Hook to rescan folder after incorporating mail."
  (if (buffer-modified-p)            ; if outstanding refiles and deletes,
      (mh-execute-commands))         ;   carry them out
  (mh-rescan-folder)                 ; synchronize with +inbox
  (mh-show))                         ; show the current message

(add-hook 'mh-inc-folder-hook 'my-mh-inc-folder-hook)

Rescan folder after incorporating new mail via mh-inc-folder-hook


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.4.2 Deleting Your Mail

To mark a message for deletion, use the d (mh-delete-msg) command. A `D' is placed by the message in the scan window, and the next undeleted message is displayed. If the previous command had been p, then the next message displayed is the first undeleted message previous to the message just deleted. Use n to force subsequent d commands to move forward to the next undeleted message after deleting the message under the cursor.

If you specify a prefix argument, you will be prompted for a sequence (see section 2.6 Using Sequences) to delete (for example, C-u d frombob RET). The x command actually carries out the deletion (see section 2.4.7 Finishing Up). C-d (mh-delete-msg-no-motion) marks the message for deletion but leaves the cursor at the current message in case you wish to perform other operations on the message.

The hook mh-delete-msg-hook is called after you mark a message for deletion. For example, the current maintainer of MH-E used this once when he kept statistics on his mail usage.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.4.3 Organizing Your Mail with Folders

MH-E has analogies for each of the MH folder and refile commands. (37) To refile a message in another folder, use the o (mh-refile-msg) (mnemonic: "output") command. You are prompted for the folder name.

If you are refiling several messages into the same folder, you can use the ! (mh-refile-or-write-again) command to repeat the last refile or write (see the description of C-o in 2.4.5 Files and Pipes). Or, place the messages into a sequence (2.6 Using Sequences) and specify a prefix argument to o, in which case you'll be prompted for the name of the sequence (for example, C-u o search RET).

If you wish to copy a message to another folder, you can use the c (mh-copy-msg) command (see the `-link' argument to refile(1)). You are prompted for a folder, and you can specify a prefix argument if you want to copy a sequence into another folder. In this case, you are then prompted for the sequence. Note that unlike the o command, the copy takes place immediately. The original copy remains in the current folder.

When you want to read the messages that you have refiled into folders, use the F v (mh-visit-folder) command to visit the folder. You are prompted for the folder name.

Other commands you can perform on folders include: F l (mh-list-folders), to list all the folders in your mail directory; F k (mh-kill-folder), to remove a folder; M-x mh-sort-folder, to sort the messages by date (see sortm(1) to see how to sort by other criteria); F p (mh-pack-folder), to pack a folder, removing gaps from the numbering sequence; and F r (mh-rescan-folder), to rescan the folder, which is useful to grab all messages in your `+inbox' after processing your new mail for the first time. If you don't want to rescan the entire folder, give F r or F p a prefix argument and you'll be prompted for a range of messages to display (for instance, C-u F r last:50 RET).

By default, operations on folders work only one level at a time. Set mh-recursive-folders to non-nil to operate on all folders. This mostly means that you'll be able to see all your folders when you press TAB when prompted for a folder name. The variable mh-auto-folder-collect is normally turned on to generate a list of folder names in the background as soon as MH-E is loaded. Otherwise, the list is generated when you need a folder name the first time (as with o (mh-refile-msg)). If you have a lot of folders and you have mh-recursive-folders set, this could take a while, which is why it's nice to do the folder collection in the background.

The function mh-default-folder-for-message-function is used by o (mh-refile-msg) and C-c C-f C-f (mh-to-fcc) to generate a default folder. The generated folder name should be a string with a `+' before it. For each of my correspondents, I use the same name for both an alias and a folder. So, I wrote a function that takes the address in the `From:' header field, finds it in my alias file, and returns the alias, which is used as a default folder name. This is the most complicated example given here, and it demonstrates several features of Emacs Lisp programming. You should be able to drop this into `~/.emacs', however. If you use this to store messages in a subfolder of your Mail directory, you can modify the line that starts `(format +%s...' and insert your subfolder after the folder symbol `+'.

 
(defun my-mh-folder-from-address ()
  "Determine folder name from address.
Takes the address in the From: header field, and returns its
corresponding alias from the user's personal aliases file. Returns
nil if the address was not found."
  (require 'rfc822)                         ; for the rfc822 functions
  (search-forward-regexp "^From: \\(.*\\)") ; grab header field contents
  (save-excursion                     ; save state
    (let ((addr (car (rfc822-addresses  ; get address
                      (buffer-substring (match-beginning 1)
                                        (match-end 1)))))
          (buffer (get-buffer-create " *temp*")) ; set local variables
          folder)
      (set-buffer buffer)             ; jump to temporary buffer
      (unwind-protect                 ; run kill-buffer when done
          (progn                      ; function grouping construct
            (insert-file-contents (expand-file-name "aliases"
                                                    mh-user-path))
            (goto-char (point-min))   ; grab aliases file and go to start
            (setq folder
                  ;; Search for the given address, even commented-out
                  ;; addresses are found!
                  ;; The function search-forward-regexp sets values that are
                  ;; later used by match-beginning and match-end.
                  (if (search-forward-regexp (format "^;*\\(.*\\):.*%s"
                                                     addr) nil t)
                      ;; NOTE WELL: this is what the return value looks like.
                      ;; You can modify the format string to match your own
                      ;; Mail hierarchy.
                      (format "+%s" (buffer-substring 
                                     (match-beginning 1)
                                     (match-end 1))))))
        (kill-buffer buffer))          ; get rid of our temporary buffer
      folder)))                        ; function's return value

(setq mh-default-folder-for-message-function 'my-mh-folder-from-address)

Creating useful default folder for refiling via mh-default-folder-for-message-function

The hook mh-refile-msg-hook is called after a message is marked to be refiled.

The variable mh-sortm-args holds extra arguments to pass on to the sortm command. (38) Note: this variable is only consulted when a prefix argument is given to M-x mh-sort-folder. It is used to override any arguments given in a `sortm:' entry in your MH profile (`~/.mh_profile').


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.4.4 Printing Your Mail

Printing mail is simple. Enter l (mh-print-msg) (for line printer or lpr). The message is formatted with mhl (39) and printed with the lpr command. You can print all the messages in a sequence by specifying a prefix argument, in which case you are prompted for the name of the sequence (as in C-u l frombob RET).

Normally messages are printed in the foreground. If this is slow on your system, you may elect to set mh-print-background to non-nil to print in the background. If you do this, do not delete the message until it is printed or else the output may be truncated. The variable mh-lpr-command-format controls how the printing is actually done. The string can contain one escape, `%s', which is filled with the name of the folder and the message number and is useful for print job names. As an example, the default is `"lpr -J '%s'"'.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.4.5 Files and Pipes

MH-E does offer a couple of commands that are not a part of MH. The first one, C-o (mh-write-msg-to-file), writes a message to a file (think of the o as in "output"). You are prompted for the filename. If the file already exists, the message is appended to it. You can also write the message to the file without the header by specifying a prefix argument (such as C-u C-o /tmp/foobar RET). Subsequent writes to the same file can be made with the ! command.

You can also pipe the message through a Unix shell command with the | (mh-pipe-msg) command. You are prompted for the Unix command through which you wish to run your message. If you give an argument to this command, the message header is included in the text passed to the command (the contrived example C-u | lpr would be done with the l command instead).

If the message is a shell archive shar or has been run through uuencode use X s (mh-store-msg) to extract the body of the message. The default directory for extraction is the current directory, and you have a chance to specify a different extraction directory. The next time you use this command, the default directory is the last directory you used.

The initial directory for the mh-store-msg command is held in mh-store-default-directory. Since I almost always run mh-store-msg on sources, I set it to my personal source directory like this:

 
(setq mh-store-default-directory (expand-file-name "~/src/"))

Subsequent incarnations of mh-store-msg offer the last directory used as the default. By the way, mh-store-msg calls the Emacs Lisp function mh-store-buffer. I mention this because you can use it directly if you're editing a buffer that contains a file that has been run through uuencode or shar. For example, you can extract the contents of the current buffer in your home directory by typing M-x mh-store-buffer RET ~ RET.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.4.6 Scan Line Formats

The name of the program that generates a listing of one line per message is held in mh-scan-prog (default: `"scan"'). Unless this variable contains an absolute pathname, it is assumed to be in the mh-progs directory. You may link another program to scan (see `mh-profile'(5)) to produce a different type of listing. (40)

If you change the format of the scan lines you'll need to tell MH-E how to parse the new format. As you see, quite a lot of variables are involved to do that. The first variable has to do with pruning out garbage.

mh-valid-scan-line
This regular expression describes a valid scan line. This is used to eliminate error messages that are occasionally produced by inc (41) or scan (default: `"^ *[0-9]"').

Next, two variables control how the message numbers are parsed.

mh-msg-number-regexp
This regular expression is used to extract the message number from a scan line. Note that the message number must be placed in quoted parentheses, (\\(...\\)), as in the default of `"^ *\\([0-9]+\\)"'.

mh-msg-search-regexp
Given a message number (which is inserted in `%d'), this regular expression will match the scan line that it represents (default: `"^[^0-9]*%d[^0-9]"').

Finally, there are a slew of variables that control how MH-E marks up the scan lines.

mh-cmd-note
Number of characters to skip over before inserting notation (default: 4). Note how it relates to the following regular expressions.

mh-deleted-msg-regexp
This regular expression describes deleted messages (default: `"^....D"'). See also mh-note-deleted.

mh-refiled-msg-regexp
This regular expression describes refiled messages (default: `"^....\\^"'). See also mh-note-refiled.

mh-cur-scan-msg-regexp
This regular expression matches the current message (default: `"^....\\+"'). See also mh-note-cur.

mh-good-msg-regexp
This regular expression describes which messages should be shown when MH-E goes to the next or previous message. Normally, deleted or refiled messages are skipped over (default: `"^....[^D^]"').

mh-note-deleted
Messages that have been deleted to are marked by this string (default: `"D"'). See also mh-deleted-msg-regexp.

mh-note-refiled
Messages that have been refiled are marked by this string (default: `"^"'). See also mh-refiled-msg-regexp.

mh-note-copied
Messages that have been copied are marked by this string (default: `"C"').

mh-note-cur
The current message (in MH, not in MH-E) is marked by this string (default: `"+"'). See also mh-cur-scan-msg-regexp.

mh-note-repl
Messages that have been replied to are marked by this string (default: `"-"').

mh-note-forw
Messages that have been forwarded are marked by this string (default: `"F"').

mh-note-dist
Messages that have been redistributed are marked by this string (default: `"R"').

mh-note-printed
Messages that have been printed are marked by this string (default: `"P"').

mh-note-seq
Messages in a sequence are marked by this string (default: `"%"').


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.4.7 Finishing Up

If you've deleted a message or refiled it, but changed your mind, you can cancel the action before you've executed it. Use u (mh-undo) to undo a refile on or deletion of a single message. You can also undo refiles and deletes for messages that belong to a given sequence by specifying a prefix argument. You'll be prompted for the name of the sequence (as in C-u u frombob RET). Alternatively, you can use F u (mh-undo-folder) to undo all refiles or deletes in the current folder.

If you've marked messages to be deleted or refiled and you want to go ahead and delete or refile the messages, use x (mh-execute-commands). Many MH-E commands that may affect the numbering of the messages (such as F r or F p) will ask if you want to process refiles or deletes first and then either run x for you or undo the pending refiles and deletes, which are lost.

When you want to quit using MH-E and go back to editing, you can use the q (mh-quit) command. This buries the buffers of the current MH-E folder and restores the buffers that were present when you first ran M-x mh-rmail. You can later restore your MH-E session by selecting the `+inbox' buffer or by running M-x mh-rmail again.

The two variables mh-before-quit-hook and mh-quit-hook are called by q (mh-quit). The former one is called before the quit occurs, so you might use it to perform any MH-E operations; you could perform some query and abort the quit or call mh-execute-commands, for example. The latter is not run in an MH-E context, so you might use it to modify the window setup. For example, if the window configuration was saved as in the example in section 2.1 Reading Your Mail, you would also want to set mh-quit-hook to the following:

 
(defun my-mh-quit-hook ()
  "Clear window configuration variables as the MH window is gone."
  (setq my-mh-screen-saved nil)
  (setq my-mh-screen nil)
  (if my-normal-screen
      (set-window-configuration my-normal-screen))
  (setq my-normal-screen nil))

Clean up window setup in mh-quit-hook


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.5 Searching Through Messages

You can search a folder for messages to or from a particular person or about a particular subject. In fact, you can also search for messages containing selected strings in any arbitrary header field or any string found within the messages. Use the F s (mh-search-folder) command. You are first prompted for the name of the folder to search and then placed in the following buffer in MH-Pick mode:

 
From: #
To:
Cc:
Date:
Subject:
--------









--:**  pick-pattern   (MH-Pick)--L1--All-------------------------------

Pick window

Edit this template by entering your search criteria in an appropriate header field that is already there, or create a new field yourself. If the string you're looking for could be anywhere in a message, then place the string underneath the row of dashes. The F s command uses the MH command pick to do the real work, so read pick(1) or the section Finding Messages with pick in the MH book to find out more about how to enter the criteria.

There are no semantics associated with the search criteria--they are simply treated as strings. Case is ignored when all lowercase is used, and regular expressions (a la ed) are available. It is all right to specify several search criteria. What happens then is that a logical and of the various fields is performed. If you prefer a logical or operation, run F s multiple times.

As an example, let's say that we want to find messages from Ginnean about horseback riding in the Kosciusko National Park (Australia) during January, 1994. Normally we would start with a broad search and narrow it down if necessary to produce a manageable amount of data, but we'll cut to the chase and create a fairly restrictive set of criteria as follows:

 
From: ginnean
To:
Cc:
Date: Jan 1994
Subject: horse.*kosciusko
--------

As with MH-Letter mode, MH-Pick provides commands like C-c C-f C-t to help you fill in the blanks.

C-c C-f C-t
Move to `To:' header field (mh-to-field).

C-c C-f C-c
Move to `cc:' header field (mh-to-field).

C-c C-f C-s
Move to `Subject:' header field (mh-to-field).

C-c C-f C-f
Move to `From:' header field (mh-to-field).

C-c C-f C-b
Move to `Bcc:' header field (mh-to-field).

C-c C-f C-f
Move to `Fcc:' header field (mh-to-field).

C-c C-f C-d
Move to `Dcc:' header field (mh-to-field).

C-c C-c
Execute the search (mh-do-pick-search).

To perform the search, type C-c C-c (mh-do-pick-search). The selected messages are placed in the search sequence, which you can use later in forwarding (see section 2.2.2 Forwarding Mail), printing (see section 2.4.4 Printing Your Mail), or narrowing your field of view (see section 2.6 Using Sequences). Subsequent searches are appended to the search sequence. If, however, you wish to start with a clean slate, first delete the search sequence (how to do this is discussed in 2.6 Using Sequences).

If you're searching in a folder that is already displayed in a MH-Folder buffer, only those messages contained in the buffer are used for the search. Therefore, if you want to search in all messages, first kill the folder's buffer with C-x k or scan the entire folder with F r.

If you find that you do the same thing over and over when editing the search template, you may wish to bind some shortcuts to keys. This can be done with the variable mh-pick-mode-hook, which is called when F s (mh-search-folder) is run on a new pattern.

The string mh-partial-folder-mode-line-annotation is used to annotate the mode line when only a portion of the folder is shown. For example, this will be displayed after running F s (mh-search-folder) to list messages based on some search criteria (see 2.5 Searching Through Messages). The default annotation of `"select"' yields a mode line that looks like:

 
--%%-{+inbox/select} 2 msgs (2-3)      (MH-Folder)--All-----------------


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.6 Using Sequences

For the whole scoop on MH sequences, refer to `mh-sequence'(5). As you've read, several of the MH-E commands can operate on a sequence, which is a shorthand for a range or group of messages. For example, you might want to forward several messages to a friend or colleague. Here's how to manipulate sequences.

S p
Put message in a sequence (mh-put-msg-in-seq).

?
Display sequences that message belongs to (mh-msg-is-in-seq).

S l
List all sequences in folder (mh-list-sequences).

S d
Remove message from sequence (mh-delete-msg-from-seq).

S k
Delete sequence (mh-delete-seq).

S n
Restrict display to messages in sequence (mh-narrow-to-seq).

S w
Remove restriction; display all messages (mh-widen).

M-x mh-update-sequences
Push MH-E's state out to MH.

To place a message in a sequence, use S p (mh-put-msg-in-seq) to do it manually, or use the MH command pick (42) or the MH-E version of pick (2.5 Searching Through Messages) which create a sequence automatically. Give S p a prefix argument and you can add all the messages in one sequence to another sequence (for example, C-u S p SourceSequence RET DestSequence RET).

Once you've placed some messages in a sequence, you may wish to narrow the field of view to just those messages in the sequence you've created. To do this, use S n (mh-narrow-to-seq). You are prompted for the name of the sequence. What this does is show only those messages that are in the selected sequence in the MH-Folder buffer. In addition, it limits further MH-E searches to just those messages. When you want to widen the view to all your messages again, use S w (mh-widen).

You can see which sequences a message is in with the S s (mh-msg-is-in-seq) command. Or, you can list all sequences in a selected folder (default is current folder) with S l (mh-list-sequences).

If you want to remove a message from a sequence, use S d (mh-delete-msg-from-seq), and if you want to delete an entire sequence, use S k (mh-delete-seq). In the latter case you are prompted for the sequence to delete. Note that this deletes only the sequence, not the messages in the sequence. If you want to delete the messages, use C-u d (see 2.4.2 Deleting Your Mail above).

Two sequences are maintained internally by MH-E and pushed out to MH when you type either the x or q command. They are the sequence specified by your `Unseen-Sequence:' profile entry and cur. However, you can also just update MH's state with the command M-x mh-update-sequences. See 2.1.1 Viewing Your Mail for an example of how this command might be used.

With the exceptions of S n and S w, the underlying MH command dealing with sequences is mark. (43)


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.7 Miscellaneous Commands

One other command worth noting is M-x mh-version. You can compare the version this command prints to the latest release (see section A.4 Getting MH-E). The output of M-x mh-version should always be included with any bug report you submit (see section A.1 Bug Reports).


[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated on March, 16 2003 using texi2html