The Section Use forw to Resend a Returned Message gives an overview of this script. You'll be installing the file resend.fixmsg; see 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 Section Making a New Command Version). Finally, put this entry in your MH profile:
resend: -editor resend.fixmsg -nodashmunging -filter mhl.noformatThe Section Leave My Dashes Alone explains the undocumented -nodashmunging switch. The mhl.noformat file, shown in the same section, is there because -nodashmunging 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.)
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 rtp@gxa.nsq.edu... 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: rtp@gxa.nsq.edu, tko@gax.nsq.edu 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).
[Table of Contents] [Index] [Previous: Explanation of recomp] [Next: Explanation of rmmer]
This file is from the third edition of the book MH & xmh: Email for Users & Programmers, ISBN 1-56592-093-7, by Jerry Peek. Copyright © 1991, 1992, 1995 by O'Reilly & Associates, Inc. This file is freely-available; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation. For more information, see the file copying.htm.
Suggestions are welcome: Jerry Peek <jerry@ora.com>
HIVE: All information for read only. Please respect copyright! |