$book = '..'?>include "$book/mh.php"; includeHeader('e-recomp.html', 'e-rfl.html'); ?>
The Section Use forw to Resend a Returned Message gives an overview of this script. You'll be installing the file resend.fixmsg; see the Section Programs in This Book's Archive. Here is the resend.fixmsg script (you might want to open it in a separate browser window). After you install resend.fixmsg, make a version of forw named resend (for directions, see the Section Making a New Command Version). Finally, put one of the following entries in your MH profile. The first one is for nmh version 0.26 and above. The second entry is for earlier nmh versions, as well as MH:
resend: -editor resend.fixmsg -nodashstuffing resend: -editor resend.fixmsg -nodashmunging -filter mhl.noformatThe Section Leave My Dashes Alone explains the nmh -nodashstuffing switch and the undocumented MH -nodashmunging switch. The mhl.noformat file, shown in the same section, is there because -nodashstuffing requires either -filter or -format. (If you normally use forw -mime, any forw: -mime entry in your MH profile won't affect resend because resend has its own profile entry.)
How does this mess work? When you type resend, it runs the same executable code that the forw program uses. This makes a draft message that's a copy of your forwcomps file with the returned message below it. (In the draft, the returned message will have lines around it that say Forwarded Message and End of Forwarded Message.) We could have used a special draft template form file and an mhl filter file to delete a lot of the garbage lines, but we'd still end up with some text to delete. The executing code sees that it was called with the name resend (not forw), so it reads your resend: profile entry.
Your profile entry has -editor resend.fixmsg; this starts your editor script to clean up the draft. First, the ed(1) editor reads a list of editing commands (from its standard input) redirected with a here document (<< "END"). These remove most of the boilerplate error text added by the system MTA when it bounced the message. Of course, your MTA may be different. And if you get a bounced message from a remote system, it will probably have some other format. So you should customize these editing commands for your local MTA. (Eventually, as more systems generate standard delivery failure notices in MIME format, the resend.fixmsg script can be simplified to extract the returned message with mhn -store -part. If you're using nmh, that's mhstore -part.)
After the ed script finishes, an interactive editor starts to let you clean up the stuff that ed didn't. Because the shell running resend.fixmsg would exit after the interactive editor finishes, and do nothing in the meantime, an exec command overlays the shell process with the interactive editor. That trick isn't especially useful on modern UNIX systems, but it saved precious memory on older UNIXes.
Here's a sample returned mail message that the resend version of forw has made into a draft. The resend.fixmsg editor edits this. The draft is shown with line numbers (actually, letters) to the left of each line; they are not part of the draft, but are for reference only.
A> To: B> cc: C> Subject: D> ------- E> F> ------- Forwarded Message G> H> Date: Mon, 09 Jan 1995 06:57:36 EST I> From: MAILER-DAEMON (Mail Delivery Subsystem) J> Received: by mysun.csa.syr.edu (5.54/CSA) K> id AA04361; Mon, 09 Jan 1995 06:57:36 EST L> Subject: Returned mail: Host unknown M> Message-Id: <9003071157.AA04361@mysun.csa.syr.edu> N> To: <ehuser> O> P> ----- Transcript of session follows ----- Q> 550 firstname.lastname@example.org... Host unknown R> S> ----- Unsent message follows ----- T> Received: by mysun.csa.syr.edu (5.54/CSA) U> id AA04355; Mon, 09 Jan 1995 06:57:36 EST V> Message-Id: <9003071157.AA04355@mysun.csa.syr.edu> W> To: email@example.com, firstname.lastname@example.org X> Subject: Incredibly boring seminar Y> Date: Mon, 09 Jan 1995 06:57:35 -0600 Z> From: "Emma H. User" <ehuser> AA> BB> ...Body of message not shown here... XX> YY> ------- End of Forwarded Message ZZ>Lines 14-22 of resend.fixmsg are ed editor commands; they're fed to the standard input of ed by the redirection on line 13. Because the terminator in line 13 has quotes around it ("END"), none of the special characters in lines 14-20 have to be quoted to protect them from the shell.
There's not space here to explain every detail of the ed editor script. But here's what the lines do:
Don't use exec if your editor returns a nonzero status, though, because your draft could be deleted before the What now? prompt. See the Section Writing Your Own Draft Message Editor(s). includeFooter('$Date: 2006-05-31 15:13:43 -0700 (Wed, 31 May 2006) $', 'OReilly: 1991, 1992, 1995; Jerry: 1996, 1997, 1998, 1999, 2000, 2002, 2004'); ?>