# Versions of forw

This section has one version of forw that calls a specialized editor script to edit a message before it's forwarded. The second MH version is actually a version of repl, acting like forw to work around a problem with MIME forwarding.

## Use forw to Resend a Returned Message

You've probably received a few returned mail messages like the one below. Usually, after you figure out what went wrong, you want to resend the message. The resend program helps you do that. It's a version of the forw command. It has an -editor shell script called resend.fixmsg that removes everything from the forwarded draft except the original message, then puts you into an editor to do any other cleanup. The resend.fixmsg script is in this book's online archive.

How well does it work? I've used resend for about four years now, and it works quite well at the sites where I've tried it. You may have to tweak it for your site. But, when it doesn't work, ed (the editor it uses to clean up the draft noninteractively) usually just prints a question mark (`?`) and leaves the forwarded draft alone -- resend.fixmsg pops me into vi, I edit the draft by hand and send it. Here is an example of resend:

        % comp
                ...
        What now? push
        %
                ...Time passes...
        You have new mail.
        % inc
          45+ 01/09 MAILER-DAEMON      Returned mail: Host unknown
        % show
                ...Nasty-gram from MAILER-DAEMON...
        % resend
                ...My editor (vi) starts...
                ...I fix the address...
        What now? push
        % rmm
        %

The resend.fixmsg script is in this book's online archive. See the Section Explanation of resend for details.

## Filter Forwarded MIME Messages: mforw

The forw -mime option creates a draft message with mhn or mhbuild `#forw` directives. When you process the directives through mhn or mhbuild, it will include all of the fields from the forwarded message headers -- including fields like `Received:` that people usually don't want to see. The forw switches -filter and -format, which can remove these fields, don't work with -mime.

The mforw command version lets you use -filter with -mime. Unlike forw, mforw can forward only one message at a time. This is because mforw actually uses repl, not forw, to forward the message. mforw uses an mhl filter file named mforwfilt to include the parts you choose of the original message; it adds a `#<message/rfc822` MIME directive above the forwarded message. You can type notes before the message you forward. (But, to type notes after the message you forward, you'll need to add an `#<text` directive before your notes.)

For example:

        % mforw
        To: ehuser
        cc:
        Subject: About the meeting on Friday
        ------
        Emma, here's a note from Al about the meeting.
        See you there!

        CTRL-D

        What now? list    ...to see draft...

        To: ehuser
        Subject: About the meeting on Friday
        ------
        Emma, here's a note from Al about the meeting.
        See you there!
        #<message/rfc822 [Forwarded message]
        Date: Mon, 09 Jan 1995 09:49:08 -0500
        From:  Al Bok <al@phl.ph.com>
        To: jpeek@jpeek.com
        Subject: The idea I'd like to discuss Friday

        Jerry,
            ...

        What now? e mhn        (...in nmh, mime)

        What now? s

Of course, if you've set an automhnproc (or automimeproc in nmh), you won't need to type `edit mhn`. Here's how to add mforw:

1. Make a file named mforwfilt in your MH directory. (You can also get this file from the book's online archive. It's in examples/mh/Mail/mforwfilt.)

             ; filter file for mforw (version of repl)
             :#<message/rfc822 [Forwarded message]
             nocomponent,width=10000
             ignores=return-path,message-id,received,replied,forwarded,resent
             extras:
             :
             body:

   You may want to edit the `ignores=` variable to change the header fields that mforw excludes. The Section Formatting the Message Header covers that part of mhl.
2. To make mforw as a version of repl (note: not a version of forw!), see the Section Making a New Command Version. Or, to make an alias or function, see the Section Writing Command Versions as Aliases or Functions.

   Add this entry to your MH profile, or add the arguments to your alias or function:

             mforw: -filter mforwfilt -form forwcomps

3. mforw requires prompter -prepend. If you've added the `-noprepend` switch to your `prompter:` profile entry, and you want prompter to stay that way by default, you'll also need to create a version of prompter that uses -prepend. (Otherwise, skip this step.) For instance, you could make a version named prompter.pre by following the steps in the Section Append Text with prompter.nopre and using the `-prepend` switch in the `prompter.pre:` profile entry. Then add `-editor prompter.pre` to your `mforw:` profile entry.

## forwr: Format forw Headers using repl

The forw command uses a template draft header file named forwcomps. Unlike the replcomps file for repl, there's no special MH-format processing done on the header of the draft message.

The forwr command version ("forward with repl") lets you use MH formatting on forw headers. Unlike forw, forwr can forward only one message at a time. This is because forwr actually uses repl, not forw, to forward the message. Instead of forwcomps, forwr has a forwrcomps template draft header file that uses MH formatting. You can customize it, of course. The default forwrcomps uses the `Subject:` of the original message on the forwarded message:

        To:
        cc:
        Fcc:
        %<{subject}Subject: %{subject}%>
        --------

forwr uses an mhl filter file named forwrfilt to include the original message and make the usual "Forwarded Message" separator lines around it:

        ; filter file for "forwr" version of "repl"
        :
        :----- Forwarded Message
        :
        extras:nocomponent
        :
        body:nocomponent
        :
        :----- End of Forwarded Message
        :

Here's how to add forwr:

1. Put the forwrfilt and forwrcomps files in your MH directory. (You can get these files from the book's online archive in examples/mh/Mail/forwrfilt and examples/mh/Mail/forwrcomps.)

   If you want to include both the sender's name and subject in the forwarded message's subject field, like this:

             Subject: [Sara Stevens: Incredible Free Pizzas!!]

   change the `Subject:` line in forwrcomps to look like this:

             %<{subject}Subject: [%(lit)%(pers{from})%<(nonnull)%|%{from}%>: %{subject}]%>

   You may also want to add an `ignores=` variable to control the header fields that forwrfilt excludes. The Section Formatting the Message Header covers that part of mhl.

2. To make forwr as a version of repl (note: not a version of forw!), see the Section Making a New Command Version. Or, to make an alias or function, see the Section Writing Command Versions as Aliases or Functions.

   Add this entry to your MH profile, or add the arguments to your alias or function:

             #: Use repl to forward one message:
             forwr: -form forwrcomps -filter forwrfilt

3. When you use forwr, you'll probably want prompter -prepend to type your text before the forwarded message. If you've added the `-noprepend` switch to your `prompter:` profile entry, and you want prompter to stay that way by default, you'll also need to create a version of prompter that uses -prepend. (Otherwise, skip this step.) For instance, you could make a version named prompter.pre by following the steps in the Section Append Text with prompter.nopre and using the `-prepend` switch in the `prompter.pre:` profile entry. Then add `-editor prompter.pre` to your `forwr:` profile entry.