Doc Walker writes:
The following is one of the criteria in my .mailfilter:
# File Courier-Maildrop mailing list messages:
if (/^List-ID:.*courier-maildrop/)
{
xfilter "${REFORMAIL} -A 'X-WVFans-Mailfilter: 0x0301'"
MATCH=escape(${MATCH})
xfilter "${REFORMAIL} -A 'X-WVFans-Match: ${MATCH}'"
to "$DEFAULT/.Doc.WVFans_net.Courier-Maildrop.Inbox"
}
I add a header to mail delivered with Maildrop indicating which rule was
used to move the file, in this case #0x0301, as well as the regular
expression that satisfied the criteria. I'm running into an error with
the mail received from the Maildrop mailing list because the $MATCH
expression contains a single apostrophe (') in the regular expression. I
get the following error in my mail.log:
unexpected EOF while looking for matching `''
It appears that $MATCH is replaced with the actual expression as the
.mailfilter is parsed and the single quote is not matched, giving the
above error.
How do I work around this? I've tried various combinations of quotes,
braces, and brackets, but with no success. I realize that I can change
my regexp criteria, knowing that the single quote will cause my header
addition to fail, but I would like to learn more how I can safely add
text headers to an email message. I believe this is one of the purposes
of the escape() function.
Try this:
Get rid of escape(). Change the command to:
xfilter '$REFORMAIL -A "X-WVFans-Match: $MATCH"'
All maildrop variables are exported in the environment. The above string
gets evaluated by maildrop as:
No variable substitution occurs inside apostrophes. The above string is
passed verbatim to the shell, to execute.
All maildrop variables are now in the environment, and the shell will
perform variable expansion.