This is a posting I made to comp.mail.sendmail
When adding a custom rule a ruleset using M4 and not using the LOCAL_RULE_* tags you do have some control over where in ruleset your rule will be added. You can add it to the beginning or the end of the ruleset. If you redefine a ruleset sendmail reopens the ruleset if it has already been defined. So if you add the rule with the tag LOCAL_CONFIG you will define your rule in ruleset S11 before the normal definition of ruleset S11, so your rule will be at the beginning. If you add your rule with the sendmail M4 macros then the rule will be added to the end of your sendmail.cf file so the rule will be added to the end of ruleset S11.
PUSHDIVERT(8) # added with `PUSHDIVERT(8)' S11 R $- $@ $1@<validhost.com> POPDIVERT
Now the / required a bit of digging on my part. M4 diversion 8 is a diversion that is not used by sendmail. Since the sendmail M4 templates do not and this diversion, I think what happens is that M4 does the (include in the output stream) at the end of the process.
Here is my M4 template:
VERSIONID(`test.mc') OSTYPE(sunos4.1) MAILER(smtp) LOCAL_CONFIG # added with `LOCAL_CONFIG' harker S11 Rlocal_config test PUSHDIVERT(8) # added with `PUSHDIVERT' harker S11 Rpushdivert test POPDIVERTHere is what ruleset S11 looks like in address test mode:
sendmail -bt -C./test.cf > =S11 (Print ruleset S11) >>> Rlocal_config test R$+ $: $> 51 $1 R$* : ; < @ > $@ R$* $: $> 61 $1 R$+ $: $> 94 $1 >>> Rpushdivert test
A detail to remeber about LOCAL_CONFIG is that this tag adds things to
the top of the sendmail.cf file, after the standard macro, class, and map
(database) definitions, but before the options, trusted users and header
definitions. In particular if you are adding additional charaters to
the option OperatorChars and you are using
those charaters in the rules you are adding, you will need to set the
option in the LOCAL_CONFIG section, before the rule you are adding:
This is needed so that sendmail knows about the new characters as being token separators before it parses the rules you are adding.
You will still need to defind the confOPERATORS M4 macro so that the option does not get reset to its normal value later on in the sendmail.cf file:
I think this counts as a "Harker's Helpful Hint" or maybe just a "Stupid sendmail pet trick" (:-)