sendmail: Should I use $*, $+ or $- ?

When writing a rule, you can use some operators on the left hand side, like $- (match exactly one token), $+ (match one or more tokens) and $* (match zero or more tokens). You may find yourself in a situation where for example you want to use a certain delivery agent for some of your users. Normally you would write something like the following:

Kmitsos btree -m -a.mitsos /etc/mail/mitsosusers

R$-  < @ $=w . > $*              $: $(mitsos $1 $)  $3
R$- . mitsos  $*     $#mitsos $: $1

The above example seems to be correct, right? But what if you have a user in mitsosusers that contains a dot (.) in the user name (for example yiorgos.adamopoulos)? Because the . is a token separator (see the OperatorChars definition in your, $- will not match the name. So the correct ruleset in this case is:

R$+  < @ $=w . > $*              $: $(mitsos $1 $)  $3
R$+ . mitsos  $*     $#mitsos $: $1

I got bitten by this sometime ago, and that is why I am sharing it.

2 thoughts on “sendmail: Should I use $*, $+ or $- ?

  1. :)

    I was using an alpha version of Postfix 10+ years ago, right after being renamed to Postfix from VMailer.

    I am very fond of it, and even recommend it for new installations when asked, but switching to it? That would take considerable effort for our infrastructure.

    Plus, I highly doubt that many people write local rulesets anymore, which makes a default .mc configuration as easy as 7 lines:

    VERSIONID(`some info here’)dnl
    DAEMON_OPTIONS(`Name=MTA, Port=smtp’)dnl

    (or use sendmail.conf and sendmailconfig in Debian and so on…)

    [ Thanks for the /. pointer; I’ve seen that it references my own post ]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s