Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Rewrite rules

9 views
Skip to first unread message

red rider

unread,
Mar 16, 2005, 10:54:02 PM3/16/05
to
After reading the Bat book I still don't quite understand the Rule sets.

The Bat book says.

Rule set 0 resolves a mail delivery agent
Rule set 1 processes sender address
Rule set 2 process recipient address
Rule set 3 preprocess all addresses
Rule set 4 postprocess all addresses
Rule set 5 rewrite unaliased local users.

As I understand it
Rule 0 determines which mda an incoming email is to use.
Rule 1 process the outgoing emails sender address
Rule 2 process an incoming email's recipient address

Rule 3 I don't quite know what this means, is the preprocessing on all
addresses for incoming and outgoing addresses?

Rule 4 What does this mean? when is the post processing done?


Please correct my misunderstanding, when exactly do the rules come into
play?
Are the rules applied to both incoming and outgoing emails?

TIA


Per Hedeland

unread,
Mar 17, 2005, 5:15:55 PM3/17/05
to
In article <ub7_d.63058$fc4.30969@edtnps89> "red rider"
<te...@microsoft.com> writes:

>After reading the Bat book I still don't quite understand the Rule sets.

Well, don't feel too bad about it, this probably the "hardest part" of
sendmail.

>The Bat book says.
>
>Rule set 0 resolves a mail delivery agent
>Rule set 1 processes sender address
>Rule set 2 process recipient address
>Rule set 3 preprocess all addresses
>Rule set 4 postprocess all addresses
>Rule set 5 rewrite unaliased local users.

The truth, but not the whole truth (I would actually assume that it says
quite a bit more).

>As I understand it
>Rule 0 determines which mda an incoming email is to use.
>Rule 1 process the outgoing emails sender address
>Rule 2 process an incoming email's recipient address

Hm, why do you "understand" something that is totally different from
what you quoted above? Don't you think "outgoing" mail needs to be
delivered? Don't you think "outgoing" mail has recipient addresses too?
Or "incoming" mail sender addresses?

First you need to realize, as was just pointed out by Neil Rickert in
another posting, that from sendmail's perspective, all mail first comes
in (to sendmail) and then goes out (from sendmail). Your concept of
"incoming" and "outgoing" probably relates to things like whether the
"local" or "smtp" mailer was chosen for delivery, but such things don't
really affect the logic of sendmail. Sendmail is a mail router, sitting
in between mailers that have a variety of delivery mechanisms, that in
principle is no concern of the processing of messages.

>Rule 3 I don't quite know what this means, is the preprocessing on all
>addresses for incoming and outgoing addresses?

Addresses are even less "incoming" and "outgoing" than messages are. It
is preprocessing of all addresses period.

>Rule 4 What does this mean? when is the post processing done?

Just before sendmail hands the message over to the chosen deilvery
agent.

>Please correct my misunderstanding, when exactly do the rules come into
>play?

That is actually a very difficult/complex question to answer. I think
Neil once posted a fairly complete truth in a very compact form - I
don't think I could do it correctly off the top of my head. But of
course you don't need to worry a whole lot about this if you stick to
the functionality and features provided by the m4/.mc config mechanism.
(You may also want to note that in a standard sendmail.cf, both ruleset
1 and 2 are empty (actuallly totally absent, but that amounts to the
same thing).

>Are the rules applied to both incoming and outgoing emails?

Of course.

--Per Hedeland
p...@hedeland.org

red rider

unread,
Mar 18, 2005, 9:25:04 AM3/18/05
to

"Per Hedeland" <p...@hedeland.org> wrote in message
news:d1cvir$1vtp$1...@hedeland.org...


Thanks for replying,

So sendmail first receives the mail and then applies the rules regardless if
the mail is from the local machine or relayed or being recieved?

Which now makes more sense.

Thanks again.


Per Hedeland

unread,
Mar 18, 2005, 6:50:39 PM3/18/05
to
In article <4xB_d.52818$KI2.9196@clgrps12> "red rider"

<te...@microsoft.com> writes:
>
>So sendmail first receives the mail and then applies the rules regardless if
>the mail is from the local machine or relayed or being recieved?

In a *very* simplified sense, yes. But there are lots of ifs and buts:
E.g. much processing is done in the mailer-specific rulesets (specified
in the S= parameter on the mail definition), and these can be and
normally are different for different mailers, e.g. "local" vs "smtp".
And some rulesets (most of the check_xxx ones) pertain to different
phases of an SMTP session, and are only called when a message is
received via SMTP. And only mailers that have the '5' flag cause ruleset
5 (localaddr) to be called - normally only used for the local mailer.
And processing of envelope addresses, and most of the SMTP check_xxx
ruleset processing, is done before the actual message is received.

--Per Hedeland
p...@hedeland.org

red rider

unread,
Mar 19, 2005, 12:17:18 AM3/19/05
to

"Per Hedeland" <p...@hedeland.org> wrote in message
news:d1fpgf$1np4$1...@hedeland.org...


Is there any good resource that explains sendmail config in simplified
manner???


red rider

unread,
Mar 19, 2005, 10:13:16 AM3/19/05
to

"red rider" <te...@microsoft.com> wrote in message
news:yBO_d.70080$gJ3.29652@clgrps13...


I tried to rewrite the from address so it looks like is from a different
domain, I know that can be done using a virtual domain, but I wanted to see
how to do it with a rewrite rule, so I tried

S3
R$*<ricktest.abc.com>$* $@ ricktest.xyz.com

But it did not change the from address.
What am I doing wrong?


Per Hedeland

unread,
Mar 19, 2005, 5:19:21 PM3/19/05
to
In article <gkX_d.66398$i6.19445@edtnps90> "red rider"

<ric...@telus.net> writes:
>
>"red rider" <te...@microsoft.com> wrote in message
>news:yBO_d.70080$gJ3.29652@clgrps13...
>>
>> Is there any good resource that explains sendmail config in simplified
>> manner???

I don't think that is possible to do. I.e., I'm interpreting your
question (based on your previous queries) to be about the logic of
sendmail.cf, which isn't really a "config file" but a very complex
program. If you want hand-holding to understand what's going on there,
your best bet is probably "the bat book".

The answer to your question as stated is that sendmail config in a
simplified manner is done via the m4/.mc system, as described in
cf/README in the distribution.

>I tried to rewrite the from address so it looks like is from a different
>domain, I know that can be done using a virtual domain, but I wanted to see
>how to do it with a rewrite rule, so I tried
>
>S3
>R$*<ricktest.abc.com>$* $@ ricktest.xyz.com
>
>But it did not change the from address.
>What am I doing wrong?

Writing a random line of code into an existing program that you haven't
even begun to understand. Sorry to sound harsh, but you won't really get
anywhere with that approach - and needless to say, you'll easily
completely break your sendmail setup, but of course that can be OK if
you're only playing around with a test system. The danger is that after
playing for a while you may have achieved something that you *think*
works right, but doesn't really, and actually take that into service.

So playing around to learn is a good idea, but stick to the m4 method
for the actual config that you use, at least until you fully understand
the details of what sendmail.cf is doing, and how it interacts with the
sendmail binary (expect this to take a few years).

A good tool for playing is -bt mode with input of '<ruleset> <address>'.
You actually almost always want to send an address through rulset 3
first, because that's what sendmail does, so you'll input something like
'3,0 user@domain' to see how the address is first transformed into
"canonical form" by ruleset 3, and then passed through ruleset 0 to make
a delivery decision.

This still only gives you fragments of the whole picture though - to
find out more about your original question, which rulesets are called in
which order etc, you can feed a complete message to sendmail with debug
options, in particular -d21.x where x is an integer that you can
increase to see more detail (start with 2 or so). You'll also want to
note that envelope and header addresses are handled differently - you
can feed in the envelope sender address with the -f option, and envelope
recipient address by simply giving it as an argument to sendmail. The
header addresses are in the header of course, i.e. From:/To: etc.

--Per Hedeland
p...@hedeland.org

0 new messages