controlled environment for regular expressions?

Warren Block wblock at wonkity.com
Tue Sep 2 13:11:47 UTC 2014


On Mon, 1 Sep 2014, David Benfell wrote:

> I've been pondering how to respond to this. It's all deeply buried in
> how I sort email, which is with my own mail delivery agent written in
> perl.
>
> The MDA provides the option to call an external program, in this case,
> grep, and sort or not sort a message into the associated Maildir based
> on the exit code.
>
> One of these instances is where I search the email headers with:
>
> /usr/bin/grep "^Subject: Cron"'

There is an extra single quote at the end of that line.

> From the command line, it matches every time on this header:
>
> Subject: Cron <benfell at home> /usr/local/bin/pycardsyncer
>
> and properly sorts the message.
>
> But when this MDA is called either from a cron job or with postfix's
> delivery instruction, it now fails every time.

To see if the problem is with cron, I'd add a test cron job that just 
manually runs the test:

echo "Subject: Cron <benfell at home> /usr/local/bin/pycardsyncer" | /usr/bin/grep -q "^Subject: Cron" && echo "matched"

If that works, it's not a problem with cron or grep, and I'd proceed to 
do that same test but piping the actual test message in another cron 
job.  Maybe also piping it to a file to see if it is being changed 
somehow in terms of whitespace or unescaped characters.

> I haven't modified this MDA in a while. I wrote it years ago. The last
> change I made to the delivery script was in 2011. I've been using it
> continuously for probably over a decade.

I would still suspect underlying things.

Other thoughts:

If the MDA is Perl, why use grep?  Also:
http://www.wonkity.com/~wblock/docs/html/maildrop.html


More information about the freebsd-questions mailing list