Purpose: Demonstrate adding an entry to the Reply menu to send a form letter.
The Reply menu is named reply.m, and is linked under a widget class of Mops. To add an extra menu entry, you can add the following to your ~/.exmh/exmh-defaults file:
(If cutting and pasting, remove leading blanks from the lines that follow.)
! Add a 'Form Letter' button to the 'Reply' menu
*Mops.reply.m.uentrylist: formletter sep help
!
! Define the label and action of the 'Form Letter' button
!
*Mops.reply.m.l_formletter: Send form letter
*Mops.reply.m.c_formletter: Msg_Reply -noedit -nocc to -nocc cc -form ~/Mail/formlettercompsWhat this does is to add an extra 'formletter' button to the menu, and associate it with the action:
Msg_Reply -nocc to -nocc cc -form ~/Mail/formlettercomps
which is the command that exmh uses internally to invoke MH's repl command.
Now, when I actually needed to do this, the form letters were being sent as replies, not to mail coming from someone's mailer, but rather to mail coming from a CGI script. The From: address and the Reply-To: address both referred to the webmaster's account; I needed to extract the real email from the body of the message. It appeared in the body on a line that looked like:
*** from: "bogus.user@no.where"
So I needed to do a little bit of Tcl code to extract this data and put it into REALSENDER to override the return address in the header. That procedure looked like:
# Send a reply to a message originating from a CGI script
proc cgi_reply args {
global env exmh mhProfile msg
# Make sure that exmh is looking at a message
if { [MsgOk $msg(id) m] } {
# Tell the user that we're doing the job
Exmh_Status "sending form letter" purple
# Blow away REALSENDER
set env(REALSENDER) {}
# Scan the message for the "*** from: " line and extract the
# sender's address from it.
# See note below - I think you can use $msg(path) here
set f [open [file join $mhProfile(path) $exmh(folder) $m] r]
while { [gets $f line] >= 0 } {
if { [regexp {^[*][*][*] from: "(.*)"} $line \
junk env(REALSENDER)] } {
break
}
}
close $f
# Send the reply along
eval Msg_Reply $args
# For good measure, mark the message for deletion
Msg_Remove
}
return
}That went into a file called
~/.tk/exmh/cgireply.tcl
or
~/.exmh/lib/cgireply.tcl
Then the stuff in ~/.exmh/exmh-defaults got changed to:
! Add a 'Form Letter' button to the 'Reply' menu
*Mops.reply.m.uentrylist: formletter sep help
!
! Define the label and action of the 'Form Letter' button
!
*Mops.reply.m.l_formletter: Send form letter
*Mops.reply.m.c_formletter: cgi_reply -noedit -nocc to -nocc cc -form ~/Mail/formlettercompsand I was a happy camper. I got multiple messages from people typing contact information into a CGI, and was able to send off a form letter to each one with a single menu selection.
Brent Good stuff. I'll note that $msg(path) is available and is the same as
file join $mhProfile(path) $exmh(folder) $msg(id)
Also, if you drop the -noedit then your editor is pulled up on the form letter. I generally do that when I'm trying out something new to make sure it looks OK before I start dispatching them via autopilot.