Domain rewrite rules play two important roles:
Rewrite addresses into their proper form.
Determine to which channels a message should be enqueued. The determination of which channel to enqueue a message is made by rewriting its envelope To: address.
Each rewrite rule appears on a single line in the upper half of the imta.cnf file.
For additional information about configuring rewrite rules, refer to Chapter 11, Configuring Rewrite Rules, in Sun Java System Messaging Server 6 2005Q4 Administration Guide.
Rewrite rules appear in the upper-half of the MTA configuration file, imta.cnf. Each rule in the configuration file appears on a single line. Comments, but not blank lines, are allowed between the rules. The rewrite rules end with a blank line, after which the channel definitions follow. Example 4–1shows the rewrite rule section of a partial configuration file.
! test.cnf - An example configuration file. ! ! This is only an example of a configuration file. It serves ! no useful purpose and should not be used in a real system. ! a $U@a-host b $U@b-host c $U%c@b-daemon d $U%d@a-daemon ! Begin channel definitions Simple Configuration File - Rewrite Rules |
Rewrite rules consist of two parts: a pattern, followed by an equivalence string or template. The two parts must be separated by spaces, although spaces are not allowed within the parts themselves. The structure for rewrite rules is as follows:
pattern template |
pattern
Indicates the string to search for in the domain name. In Example 4–1, the patterns are a, b, c, and d.
If the pattern matches the domain part of the address, the rewrite rule is applied to the address. A blank space must separate the pattern from the template. For more information about pattern syntax, see Rewrite Rule Patterns and Tags.
template
Is one of the following. For more information about template syntax, see Rewrite Rule Templates.
UserTemplate%DomainTemplate@ChannelTag[controls] UserTemplate@ChannelTag[controls] UserTemplate%DomainTemplate[controls] UserTemplate@DomainTemplate@ChannelTag[controls] UserTemplate@DomainTemplate@SourceRoute@ChannelTag[controls]
Specifies how the user part of the address is rewritten. Substitution sequences can be used to represent parts of the original address or the results of a database lookup. The substitution sequences are replaced with what they represent to construct the rewritten address. In Example 4–1, the $U substitution sequence is used. For more information, see Template Substitutions and Rewrite Rule Control Sequences.
Specifies how the domain part of the address is rewritten. Like the UserTemplate, the DomainTemplate can contain substitution sequences.
Indicates the channel to which this message is sent. (All channel definitions must include a channel tag as well as a channel name. The channel tag typically appears in rewrite rules, as well as in its channel definition.)
The applicability of a rule can be limited using controls. Some control sequences must appear at the beginning of the rule; other controls must appear at the end of the rule. Some can appear almost anywhere in a rule. For more information about controls, see Template Substitutions and Rewrite Rule Control Sequences.
Most rewrite rule patterns consist either of a specific host name that will match only that host or of a subdomain pattern that will match any host/domain in the entire subdomain.
For example, the following rewrite rule pattern contains a specific host name that will match the specified host only:
host.siroe.com
The next rewrite rule pattern contains a subdomain pattern that will match any host or domain in the entire subdomain:
.siroe.com
This pattern will not, however, match the exact host name siroe.com; to match the exact host name siroe.com, a separate siroe.com pattern would be needed.
The MTA attempts to rewrite host/domain names starting from the specific host name and then incrementally generalizing the name to make it less specific. This means that a more specific rewrite rule pattern will be preferentially used over more general rewrite rule patterns. For example, assume the following rewrite rule patterns are present in the configuration file:
hosta.subnet.siroe.com .subnet.siroe.com .siroe.com
Based on the rewrite rule patterns, an address of jdoe@hosta.subnet.siroe.com will match the hosta.subnet.siroe.com rewrite rule pattern; an address of jdoe@hostb.subnet.siroe.com will match the .subnet.siroe.com rewrite rule pattern; and an address of jdoe@hostc.siroe.com will match the .siroe.com rewrite rule pattern.
In particular, the use of rewrite rules incorporating subdomain rewrite rule patterns is common for sites on the Internet. Such a site will typically have a number of rewrite rules for their own internal hosts and subnets, and then will include rewrite rules for the top-level Internet domains into their configuration from the file internet.rules (msg_svr_base/config/internet.rules).
This file is required to contain the following:
Rewrite rules with patterns that match the top level Internet domains
Templates that rewrite addresses matching such patterns to an outgoing TCP/IP channel
In addition to the more common sorts of host or subdomain rewrite rule patterns already discussed, rewrite rules may also make use of several special patterns, summarized in Table 4–3, and discussed in the following subsections.
Table 4–3 Summary of Special Patterns for Rewrite Rules
Pattern |
Description/Usage |
---|---|
$* |
Matches any address. This rule, if specified, is tried first regardless of its position in the file. |
$% |
Percent Hack Rule. Matches any host/domain specification of the form A%B. |
$! |
Bang-style Rule. Matches any host/domain specification of the form B!A. |
[] |
IP literal match-all rule. Matches any IP domain literal. |
. |
Matches any host/domain specification. For example, joe@[129.165.12.11] |
In addition to these special patterns, Messaging Server also has the concept of tags, which may appear in rewrite rule patterns. These tags are used in situations where an address may be rewritten several times and, based upon previous rewrites, distinctions must be made in subsequent rewrites by controlling which rewrite rules match the address. For more information, see the Sun Java System Messaging Server 6 2005Q4 Administration Guide.
Table 4–4 summarizes the template formats.
Table 4–4 Summary of Template Formats for Rewrite Rules
Template |
Usage |
---|---|
A%B |
A becomes the new user/mailbox name, B becomes the new host/domain specification, rewrite again. |
A@B |
Treated as A%B@B. |
A%B@C |
A becomes the new user/mailbox name, B becomes the new host/domain specification, route to the channel associated with the host C. |
A@B@C |
Treated as A@B@C@C. |
A@B@C@D |
A becomes the new user/mailbox name, B becomes the new host/domain specification, insert C as a source route, route to the channel associated with the host D. |
Substitutions are used to rewrite user names or addresses by inserting a character string into the rewritten address, the value of which is determined by the particular substitution sequence used.
Control sequences impose additional conditions to the applicability of a given rewrite rule. Not only must the pattern portion of the rewrite rule match the host or domain specification being examined, but other aspects of the address being rewritten must meet conditions set by the control sequence or sequences.
If a domain or host specification matches the pattern portion of a rewrite rule but doesn’t meet all of the criteria imposed by a control sequences in the rule’s template, then the rewrite rule fails and the rewriter continues to look for other applicable rules.
Table 4–5 summarizes the template substitutions and control sequences.
Table 4–5 Summary of Template Substitutions and Control Sequences
For more information on substitutions, refer to the Sun Java System Messaging Server 6 2005Q4 Administration Guide.