xref: /freebsd/contrib/sendmail/cf/m4/proto.m4 (revision a8445737e740901f5f2c8d24c12ef7fc8b00134e)
1divert(-1)
2#
3# Copyright (c) 1998 Sendmail, Inc.  All rights reserved.
4# Copyright (c) 1983, 1995 Eric P. Allman.  All rights reserved.
5# Copyright (c) 1988, 1993
6#	The Regents of the University of California.  All rights reserved.
7#
8# By using this file, you agree to the terms and conditions set
9# forth in the LICENSE file which can be found at the top level of
10# the sendmail distribution.
11#
12#
13divert(0)
14
15VERSIONID(`@(#)proto.m4	8.223 (Berkeley) 6/30/98')
16
17MAILER(local)dnl
18
19# level 8 config file format
20V8/Berkeley
21divert(-1)
22
23# do some sanity checking
24ifdef(`__OSTYPE__',,
25	`errprint(`*** ERROR: No system type defined (use OSTYPE macro)')')
26
27# pick our default mailers
28ifdef(`confSMTP_MAILER',, `define(`confSMTP_MAILER', `esmtp')')
29ifdef(`confLOCAL_MAILER',, `define(`confLOCAL_MAILER', `local')')
30ifdef(`confRELAY_MAILER',,
31	`define(`confRELAY_MAILER',
32		`ifdef(`_MAILER_smtp_', `relay',
33			`ifdef(`_MAILER_uucp', `uucp-new', `unknown')')')')
34ifdef(`confUUCP_MAILER',, `define(`confUUCP_MAILER', `uucp-old')')
35define(`_SMTP_', `confSMTP_MAILER')dnl		for readability only
36define(`_LOCAL_', `confLOCAL_MAILER')dnl	for readability only
37define(`_RELAY_', `confRELAY_MAILER')dnl	for readability only
38define(`_UUCP_', `confUUCP_MAILER')dnl		for readability only
39
40# set our default hashed database type
41ifdef(`DATABASE_MAP_TYPE',, `define(`DATABASE_MAP_TYPE', `hash')')
42
43# back compatibility with old config files
44ifdef(`confDEF_GROUP_ID',
45	`errprint(`*** confDEF_GROUP_ID is obsolete.')
46	 errprint(`    Use confDEF_USER_ID with a colon in the value instead.')')
47ifdef(`confREAD_TIMEOUT',
48	`errprint(`*** confREAD_TIMEOUT is obsolete.')
49	 errprint(`    Use individual confTO_<timeout> parameters instead.')')
50ifdef(`confMESSAGE_TIMEOUT',
51	`define(`_ARG_', index(confMESSAGE_TIMEOUT, /))
52	 ifelse(_ARG_, -1,
53		`define(`confTO_QUEUERETURN', confMESSAGE_TIMEOUT)',
54		`define(`confTO_QUEUERETURN',
55			substr(confMESSAGE_TIMEOUT, 0, _ARG_))
56		 define(`confTO_QUEUEWARN',
57			substr(confMESSAGE_TIMEOUT, eval(_ARG_+1)))')')
58ifdef(`confMIN_FREE_BLOCKS', `ifelse(index(confMIN_FREE_BLOCKS, /), -1,,
59	`errprint(`*** compound confMIN_FREE_BLOCKS is obsolete.')
60	 errprint(`    Use confMAX_MESSAGE_SIZE for the second part of the value.')')')
61
62# clean option definitions below....
63define(`_OPTION', `ifdef(`$2', `O $1=$2', `#O $1`'ifelse($3, `',, `=$3')')')dnl
64
65divert(0)dnl
66
67# override file safeties - setting this option compromises system security
68# need to set this now for the sake of class files
69_OPTION(DontBlameSendmail, `confDONT_BLAME_SENDMAIL', safe)
70
71##################
72#   local info   #
73##################
74
75Cwlocalhost
76ifdef(`USE_CW_FILE',
77`# file containing names of hosts for which we receive email
78Fw`'confCW_FILE',
79	`dnl')
80
81# my official domain name
82# ... `define' this only if sendmail cannot automatically determine your domain
83ifdef(`confDOMAIN_NAME', `Dj`'confDOMAIN_NAME', `#Dj$w.Foo.COM')
84
85ifdef(`_NULL_CLIENT_ONLY_', `divert(-1)')dnl
86
87CP.
88
89ifdef(`UUCP_RELAY',
90`# UUCP relay host
91DY`'UUCP_RELAY
92CPUUCP
93
94')dnl
95ifdef(`BITNET_RELAY',
96`#  BITNET relay host
97DB`'BITNET_RELAY
98CPBITNET
99
100')dnl
101ifdef(`DECNET_RELAY',
102`define(`_USE_DECNET_SYNTAX_', 1)dnl
103# DECnet relay host
104DC`'DECNET_RELAY
105CPDECNET
106
107')dnl
108ifdef(`FAX_RELAY',
109`# FAX relay host
110DF`'FAX_RELAY
111CPFAX
112
113')dnl
114# "Smart" relay host (may be null)
115DS`'ifdef(`SMART_HOST', SMART_HOST)
116
117ifdef(`LUSER_RELAY', `dnl
118# place to which unknown users should be forwarded
119Kuser user -m -a<>
120DL`'LUSER_RELAY',
121`dnl')
122
123# operators that cannot be in local usernames (i.e., network indicators)
124CO @ % ifdef(`_NO_UUCP_', `', `!')
125
126# a class with just dot (for identifying canonical names)
127C..
128
129# a class with just a left bracket (for identifying domain literals)
130C[[
131
132ifdef(`MAILER_TABLE', `dnl
133# Mailer table (overriding domains)
134Kmailertable MAILER_TABLE',
135`dnl')
136
137ifdef(`DOMAIN_TABLE', `dnl
138# Domain table (adding domains)
139Kdomaintable DOMAIN_TABLE',
140`dnl')
141
142ifdef(`GENERICS_TABLE', `dnl
143# Generics table (mapping outgoing addresses)
144Kgenerics GENERICS_TABLE',
145`dnl')
146
147ifdef(`UUDOMAIN_TABLE', `dnl
148# UUCP domain table
149Kuudomain UUDOMAIN_TABLE',
150`dnl')
151
152ifdef(`BITDOMAIN_TABLE', `dnl
153# BITNET mapping table
154Kbitdomain BITDOMAIN_TABLE',
155`dnl')
156
157ifdef(`VIRTUSER_TABLE', `dnl
158# Virtual user table (maps incoming users)
159Kvirtuser VIRTUSER_TABLE',
160`dnl')
161
162ifdef(`ACCESS_TABLE', `dnl
163# Access list database (for spam stomping)
164Kaccess ACCESS_TABLE',
165`dnl')
166
167ifdef(`_RELAY_MX_SERVED_', `dnl
168# MX map (to allow relaying to hosts that we MX for)
169Kmxserved bestmx -z: -T<TEMP>',
170`dnl')
171
172ifdef(`_ACCEPT_UNRESOLVABLE_DOMAINS_',`dnl',`dnl
173# Resolve map (to check if a host exists in check_mail)
174Kresolve host -a<OK> -T<TEMP>')
175
176ifdef(`confCR_FILE', `dnl
177# Hosts that will permit relaying ($=R)
178FR`'confCR_FILE',
179`dnl')
180
181# who I send unqualified names to (null means deliver locally)
182DR`'ifdef(`LOCAL_RELAY', LOCAL_RELAY)
183
184# who gets all local email traffic ($R has precedence for unqualified names)
185DH`'ifdef(`MAIL_HUB', MAIL_HUB)
186
187# dequoting map
188Kdequote dequote
189
190divert(0)dnl	# end of nullclient diversion
191# class E: names that should be exposed as from this host, even if we masquerade
192ifdef(`_NULL_CLIENT_ONLY_', `#',
193`# class L: names that should be delivered locally, even if we have a relay
194# class M: domains that should be converted to $M
195#CL root
196')CE root
197undivert(5)dnl
198
199# who I masquerade as (null for no masquerading) (see also $=M)
200DM`'ifdef(`MASQUERADE_NAME', MASQUERADE_NAME)
201
202# my name for error messages
203ifdef(`confMAILER_NAME', `Dn`'confMAILER_NAME', `#DnMAILER-DAEMON')
204
205undivert(6)dnl
206include(_CF_DIR_`m4/version.m4')
207
208###############
209#   Options   #
210###############
211
212# strip message body to 7 bits on input?
213_OPTION(SevenBitInput, `confSEVEN_BIT_INPUT')
214
215# 8-bit data handling
216_OPTION(EightBitMode, `confEIGHT_BIT_HANDLING', adaptive)
217
218ifdef(`_NULL_CLIENT_ONLY_', `dnl', `
219# wait for alias file rebuild (default units: minutes)
220_OPTION(AliasWait, `confALIAS_WAIT', 5m)
221
222# location of alias file
223_OPTION(AliasFile, `ALIAS_FILE', /etc/aliases)
224')
225# minimum number of free blocks on filesystem
226_OPTION(MinFreeBlocks, `confMIN_FREE_BLOCKS', 100)
227
228# maximum message size
229_OPTION(MaxMessageSize, `confMAX_MESSAGE_SIZE', 1000000)
230
231# substitution for space (blank) characters
232_OPTION(BlankSub, `confBLANK_SUB', _)
233
234# avoid connecting to "expensive" mailers on initial submission?
235_OPTION(HoldExpensive, `confCON_EXPENSIVE')
236
237# checkpoint queue runs after every N successful deliveries
238_OPTION(CheckpointInterval, `confCHECKPOINT_INTERVAL', 10)
239
240# default delivery mode
241_OPTION(DeliveryMode, `confDELIVERY_MODE', background)
242
243# automatically rebuild the alias database?
244_OPTION(AutoRebuildAliases, `confAUTO_REBUILD')
245
246# error message header/file
247_OPTION(ErrorHeader, `confERROR_MESSAGE', /etc/sendmail.oE)
248
249# error mode
250_OPTION(ErrorMode, `confERROR_MODE', print)
251
252# save Unix-style "From_" lines at top of header?
253_OPTION(SaveFromLine, `confSAVE_FROM_LINES')
254
255# temporary file mode
256_OPTION(TempFileMode, `confTEMP_FILE_MODE', 0600)
257
258# match recipients against GECOS field?
259_OPTION(MatchGECOS, `confMATCH_GECOS')
260
261# maximum hop count
262_OPTION(MaxHopCount, `confMAX_HOP', 17)
263
264# location of help file
265O HelpFile=ifdef(`HELP_FILE', HELP_FILE, /usr/lib/sendmail.hf)
266
267# ignore dots as terminators in incoming messages?
268_OPTION(IgnoreDots, `confIGNORE_DOTS')
269
270# name resolver options
271_OPTION(ResolverOptions, `confBIND_OPTS', +AAONLY)
272
273# deliver MIME-encapsulated error messages?
274_OPTION(SendMimeErrors, `confMIME_FORMAT_ERRORS')
275
276# Forward file search path
277_OPTION(ForwardPath, `confFORWARD_PATH', /var/forward/$u:$z/.forward.$w:$z/.forward)
278
279# open connection cache size
280_OPTION(ConnectionCacheSize, `confMCI_CACHE_SIZE', 2)
281
282# open connection cache timeout
283_OPTION(ConnectionCacheTimeout, `confMCI_CACHE_TIMEOUT', 5m)
284
285# persistent host status directory
286_OPTION(HostStatusDirectory, `confHOST_STATUS_DIRECTORY', .hoststat)
287
288# single thread deliveries (requires HostStatusDirectory)?
289_OPTION(SingleThreadDelivery, `confSINGLE_THREAD_DELIVERY')
290
291# use Errors-To: header?
292_OPTION(UseErrorsTo, `confUSE_ERRORS_TO')
293
294# log level
295_OPTION(LogLevel, `confLOG_LEVEL', 10)
296
297# send to me too, even in an alias expansion?
298_OPTION(MeToo, `confME_TOO')
299
300# verify RHS in newaliases?
301_OPTION(CheckAliases, `confCHECK_ALIASES')
302
303# default messages to old style headers if no special punctuation?
304_OPTION(OldStyleHeaders, `confOLD_STYLE_HEADERS')
305
306# SMTP daemon options
307_OPTION(DaemonPortOptions, `confDAEMON_OPTIONS', Port=esmtp)
308
309# privacy flags
310_OPTION(PrivacyOptions, `confPRIVACY_FLAGS', authwarnings)
311
312# who (if anyone) should get extra copies of error messages
313_OPTION(PostMasterCopy, `confCOPY_ERRORS_TO', Postmaster)
314
315# slope of queue-only function
316_OPTION(QueueFactor, `confQUEUE_FACTOR', 600000)
317
318# queue directory
319O QueueDirectory=ifdef(`QUEUE_DIR', QUEUE_DIR, /var/spool/mqueue)
320
321# timeouts (many of these)
322_OPTION(Timeout.initial, `confTO_INITIAL', 5m)
323_OPTION(Timeout.connect, `confTO_CONNECT', 5m)
324_OPTION(Timeout.iconnect, `confTO_ICONNECT', 5m)
325_OPTION(Timeout.helo, `confTO_HELO', 5m)
326_OPTION(Timeout.mail, `confTO_MAIL', 10m)
327_OPTION(Timeout.rcpt, `confTO_RCPT', 1h)
328_OPTION(Timeout.datainit, `confTO_DATAINIT', 5m)
329_OPTION(Timeout.datablock, `confTO_DATABLOCK', 1h)
330_OPTION(Timeout.datafinal, `confTO_DATAFINAL', 1h)
331_OPTION(Timeout.rset, `confTO_RSET', 5m)
332_OPTION(Timeout.quit, `confTO_QUIT', 2m)
333_OPTION(Timeout.misc, `confTO_MISC', 2m)
334_OPTION(Timeout.command, `confTO_COMMAND', 1h)
335_OPTION(Timeout.ident, `confTO_IDENT', 30s)
336_OPTION(Timeout.fileopen, `confTO_FILEOPEN', 60s)
337_OPTION(Timeout.queuereturn, `confTO_QUEUERETURN', 5d)
338_OPTION(Timeout.queuereturn.normal, `confTO_QUEUERETURN_NORMAL', 5d)
339_OPTION(Timeout.queuereturn.urgent, `confTO_QUEUERETURN_URGENT', 2d)
340_OPTION(Timeout.queuereturn.non-urgent, `confTO_QUEUERETURN_NONURGENT', 7d)
341_OPTION(Timeout.queuewarn, `confTO_QUEUEWARN', 4h)
342_OPTION(Timeout.queuewarn.normal, `confTO_QUEUEWARN_NORMAL', 4h)
343_OPTION(Timeout.queuewarn.urgent, `confTO_QUEUEWARN_URGENT', 1h)
344_OPTION(Timeout.queuewarn.non-urgent, `confTO_QUEUEWARN_NONURGENT', 12h)
345_OPTION(Timeout.hoststatus, `confTO_HOSTSTATUS', 30m)
346
347# should we not prune routes in route-addr syntax addresses?
348_OPTION(DontPruneRoutes, `confDONT_PRUNE_ROUTES')
349
350# queue up everything before forking?
351_OPTION(SuperSafe, `confSAFE_QUEUE')
352
353# status file
354O StatusFile=ifdef(`STATUS_FILE', `STATUS_FILE', /etc/sendmail.st)
355
356# time zone handling:
357#  if undefined, use system default
358#  if defined but null, use TZ envariable passed in
359#  if defined and non-null, use that info
360ifelse(confTIME_ZONE, `USE_SYSTEM', `#O TimeZoneSpec=',
361	confTIME_ZONE, `USE_TZ', `O TimeZoneSpec=',
362	`O TimeZoneSpec=confTIME_ZONE')
363
364# default UID (can be username or userid:groupid)
365_OPTION(DefaultUser, `confDEF_USER_ID', mailnull)
366
367# list of locations of user database file (null means no lookup)
368_OPTION(UserDatabaseSpec, `confUSERDB_SPEC', /etc/userdb)
369
370# fallback MX host
371_OPTION(FallbackMXhost, `confFALLBACK_MX', fall.back.host.net)
372
373# if we are the best MX host for a site, try it directly instead of config err
374_OPTION(TryNullMXList, `confTRY_NULL_MX_LIST')
375
376# load average at which we just queue messages
377_OPTION(QueueLA, `confQUEUE_LA', 8)
378
379# load average at which we refuse connections
380_OPTION(RefuseLA, `confREFUSE_LA', 12)
381
382# maximum number of children we allow at one time
383_OPTION(MaxDaemonChildren, `confMAX_DAEMON_CHILDREN', 12)
384
385# maximum number of new connections per second
386_OPTION(ConnectionRateThrottle, `confCONNECTION_RATE_THROTTLE', 3)
387
388# work recipient factor
389_OPTION(RecipientFactor, `confWORK_RECIPIENT_FACTOR', 30000)
390
391# deliver each queued job in a separate process?
392_OPTION(ForkEachJob, `confSEPARATE_PROC')
393
394# work class factor
395_OPTION(ClassFactor, `confWORK_CLASS_FACTOR', 1800)
396
397# work time factor
398_OPTION(RetryFactor, `confWORK_TIME_FACTOR', 90000)
399
400# shall we sort the queue by hostname first?
401_OPTION(QueueSortOrder, `confQUEUE_SORT_ORDER', priority)
402
403# minimum time in queue before retry
404_OPTION(MinQueueAge, `confMIN_QUEUE_AGE', 30m)
405
406# default character set
407_OPTION(DefaultCharSet, `confDEF_CHAR_SET', iso-8859-1)
408
409# service switch file (ignored on Solaris, Ultrix, OSF/1, others)
410_OPTION(ServiceSwitchFile, `confSERVICE_SWITCH_FILE', /etc/service.switch)
411
412# hosts file (normally /etc/hosts)
413_OPTION(HostsFile, `confHOSTS_FILE', /etc/hosts)
414
415# dialup line delay on connection failure
416_OPTION(DialDelay, `confDIAL_DELAY', 10s)
417
418# action to take if there are no recipients in the message
419_OPTION(NoRecipientAction, `confNO_RCPT_ACTION', add-to-undisclosed)
420
421# chrooted environment for writing to files
422_OPTION(SafeFileEnvironment, `confSAFE_FILE_ENV', /arch)
423
424# are colons OK in addresses?
425_OPTION(ColonOkInAddr, `confCOLON_OK_IN_ADDR')
426
427# how many jobs can you process in the queue?
428_OPTION(MaxQueueRunSize, `confMAX_QUEUE_RUN_SIZE', 10000)
429
430# shall I avoid expanding CNAMEs (violates protocols)?
431_OPTION(DontExpandCnames, `confDONT_EXPAND_CNAMES')
432
433# SMTP initial login message (old $e macro)
434_OPTION(SmtpGreetingMessage, `confSMTP_LOGIN_MSG')
435
436# UNIX initial From header format (old $l macro)
437_OPTION(UnixFromLine, `confFROM_LINE')
438
439# From: lines that have embedded newlines are unwrapped onto one line
440_OPTION(SingleLineFromHeader, `confSINGLE_LINE_FROM_HEADER', False)
441
442# Allow HELO SMTP command that does not `include' a host name
443_OPTION(AllowBogusHELO, `confALLOW_BOGUS_HELO', False)
444
445# Characters to be quoted in a full name phrase (@,;:\()[] are automatic)
446_OPTION(MustQuoteChars, `confMUST_QUOTE_CHARS', .)
447
448# delimiter (operator) characters (old $o macro)
449_OPTION(OperatorChars, `confOPERATORS')
450
451# shall I avoid calling initgroups(3) because of high NIS costs?
452_OPTION(DontInitGroups, `confDONT_INIT_GROUPS')
453
454# are group-writable `:include:' and .forward files (un)trustworthy?
455_OPTION(UnsafeGroupWrites, `confUNSAFE_GROUP_WRITES')
456
457# where do errors that occur when sending errors get sent?
458_OPTION(DoubleBounceAddress, `confDOUBLE_BOUNCE_ADDRESS', postmaster)
459
460# what user id do we assume for the majority of the processing?
461_OPTION(RunAsUser, `confRUN_AS_USER', sendmail)
462
463# maximum number of recipients per SMTP envelope
464_OPTION(MaxRecipientsPerMessage, `confMAX_RCPTS_PER_MESSAGE', 100)
465
466# shall we get local names from our installed interfaces?
467_OPTION(DontProbeInterfaces, `confDONT_PROBE_INTERFACES')
468
469###########################
470#   Message precedences   #
471###########################
472
473Pfirst-class=0
474Pspecial-delivery=100
475Plist=-30
476Pbulk=-60
477Pjunk=-100
478
479#####################
480#   Trusted users   #
481#####################
482
483# this is equivalent to setting class "t"
484ifdef(`_USE_CT_FILE_', `', `#')Ft`'ifdef(`confCT_FILE', confCT_FILE, `/etc/sendmail.ct')
485Troot
486Tdaemon
487ifdef(`_NO_UUCP_', `dnl', `Tuucp')
488ifdef(`confTRUSTED_USERS', `T`'confTRUSTED_USERS', `dnl')
489
490#########################
491#   Format of headers   #
492#########################
493
494ifdef(`confFROM_HEADER',, `define(`confFROM_HEADER', `$?x$x <$g>$|$g$.')')dnl
495H?P?Return-Path: <$g>
496HReceived: confRECEIVED_HEADER
497H?D?Resent-Date: $a
498H?D?Date: $a
499H?F?Resent-From: confFROM_HEADER
500H?F?From: confFROM_HEADER
501H?x?Full-Name: $x
502# HPosted-Date: $a
503# H?l?Received-Date: $b
504H?M?Resent-Message-Id: <$t.$i@$j>
505H?M?Message-Id: <$t.$i@$j>
506ifdef(`_NULL_CLIENT_ONLY_',
507	`include(_CF_DIR_`'m4/nullrelay.m4)m4exit',
508	`dnl')
509#
510######################################################################
511######################################################################
512#####
513#####			REWRITING RULES
514#####
515######################################################################
516######################################################################
517
518############################################
519###  Ruleset 3 -- Name Canonicalization  ###
520############################################
521S3
522
523# handle null input (translate to <@> special case)
524R$@			$@ <@>
525
526# strip group: syntax (not inside angle brackets!) and trailing semicolon
527R$*			$: $1 <@>			mark addresses
528R$* < $* > $* <@>	$: $1 < $2 > $3			unmark <addr>
529R@ $* <@>		$: @ $1				unmark @host:...
530R$* :: $* <@>		$: $1 :: $2			unmark node::addr
531R:`include': $* <@>	$: :`include': $1			unmark :`include':...
532R$* [ $* : $* ] <@>	$: $1 [ $2 : $3 ]		unmark IPv6 addrs
533R$* : $* [ $* ]		$: $1 : $2 [ $3 ] <@>		remark if leading colon
534R$* : $* <@>		$: $2				strip colon if marked
535R$* <@>			$: $1				unmark
536R$* ;			   $1				strip trailing semi
537R$* < $* ; >		   $1 < $2 >			bogus bracketed semi
538
539# null input now results from list:; syntax
540R$@			$@ :; <@>
541
542# strip angle brackets -- note RFC733 heuristic to get innermost item
543R$*			$: < $1 >			housekeeping <>
544R$+ < $* >		   < $2 >			strip excess on left
545R< $* > $+		   < $1 >			strip excess on right
546R<>			$@ < @ >			MAIL FROM:<> case
547R< $+ >			$: $1				remove housekeeping <>
548
549# make sure <@a,@b,@c:user@d> syntax is easy to parse -- undone later
550R@ $+ , $+		@ $1 : $2			change all "," to ":"
551
552# localize and dispose of route-based addresses
553R@ $+ : $+		$@ $>96 < @$1 > : $2		handle <route-addr>
554
555# find focus for list syntax
556R $+ : $* ; @ $+	$@ $>96 $1 : $2 ; < @ $3 >	list syntax
557R $+ : $* ;		$@ $1 : $2;			list syntax
558
559# find focus for @ syntax addresses
560R$+ @ $+		$: $1 < @ $2 >			focus on domain
561R$+ < $+ @ $+ >		$1 $2 < @ $3 >			move gaze right
562R$+ < @ $+ >		$@ $>96 $1 < @ $2 >		already canonical
563
564# do some sanity checking
565R$* < @ $* : $* > $*	$1 < @ $2 $3 > $4		nix colons in addrs
566
567ifdef(`_NO_UUCP_', `dnl',
568`# convert old-style addresses to a domain-based address
569R$- ! $+		$@ $>96 $2 < @ $1 .UUCP >	resolve uucp names
570R$+ . $- ! $+		$@ $>96 $3 < @ $1 . $2 >		domain uucps
571R$+ ! $+		$@ $>96 $2 < @ $1 .UUCP >	uucp subdomains
572')
573ifdef(`_USE_DECNET_SYNTAX_',
574`# convert node::user addresses into a domain-based address
575R$- :: $+		$@ $>96 $2 < @ $1 .DECNET >	resolve DECnet names
576R$- . $- :: $+		$@ $>96 $3 < @ $1.$2 .DECNET >	numeric DECnet addr
577',
578	`dnl')
579# if we have % signs, take the rightmost one
580R$* % $*		$1 @ $2				First make them all @s.
581R$* @ $* @ $*		$1 % $2 @ $3			Undo all but the last.
582R$* @ $*		$@ $>96 $1 < @ $2 >		Insert < > and finish
583
584# else we must be a local name
585R$*			$@ $>96 $1
586
587
588################################################
589###  Ruleset 96 -- bottom half of ruleset 3  ###
590################################################
591
592S96
593
594# handle special cases for local names
595R$* < @ localhost > $*		$: $1 < @ $j . > $2		no domain at all
596R$* < @ localhost . $m > $*	$: $1 < @ $j . > $2		local domain
597ifdef(`_NO_UUCP_', `dnl',
598`R$* < @ localhost . UUCP > $*	$: $1 < @ $j . > $2		.UUCP domain')
599R$* < @ [ $+ ] > $*		$: $1 < @@ [ $2 ] > $3		mark [a.b.c.d]
600R$* < @@ $=w > $*		$: $1 < @ $j . > $3		self-literal
601R$* < @@ $+ > $*		$@ $1 < @ $2 > $3		canon IP addr
602
603ifdef(`DOMAIN_TABLE', `dnl
604# look up domains in the domain table
605R$* < @ $+ > $* 		$: $1 < @ $(domaintable $2 $) > $3', `dnl')
606
607undivert(2)dnl
608
609ifdef(`BITDOMAIN_TABLE', `dnl
610# handle BITNET mapping
611R$* < @ $+ .BITNET > $*		$: $1 < @ $(bitdomain $2 $: $2.BITNET $) > $3', `dnl')
612
613ifdef(`UUDOMAIN_TABLE', `dnl
614# handle UUCP mapping
615R$* < @ $+ .UUCP > $*		$: $1 < @ $(uudomain $2 $: $2.UUCP $) > $3', `dnl')
616
617ifdef(`_NO_UUCP_', `dnl',
618`ifdef(`UUCP_RELAY',
619`# pass UUCP addresses straight through
620R$* < @ $+ . UUCP > $*		$@ $1 < @ $2 . UUCP . > $3',
621`# if really UUCP, handle it immediately
622ifdef(`_CLASS_U_',
623`R$* < @ $=U . UUCP > $*	$@ $1 < @ $2 . UUCP . > $3', `dnl')
624ifdef(`_CLASS_V_',
625`R$* < @ $=V . UUCP > $*	$@ $1 < @ $2 . UUCP . > $3', `dnl')
626ifdef(`_CLASS_W_',
627`R$* < @ $=W . UUCP > $*	$@ $1 < @ $2 . UUCP . > $3', `dnl')
628ifdef(`_CLASS_X_',
629`R$* < @ $=X . UUCP > $*	$@ $1 < @ $2 . UUCP . > $3', `dnl')
630ifdef(`_CLASS_Y_',
631`R$* < @ $=Y . UUCP > $*	$@ $1 < @ $2 . UUCP . > $3', `dnl')
632
633ifdef(`_NO_CANONIFY_', `dnl', `dnl
634# try UUCP traffic as a local address
635R$* < @ $+ . UUCP > $*		$: $1 < @ $[ $2 $] . UUCP . > $3
636R$* < @ $+ . . UUCP . > $*	$@ $1 < @ $2 . > $3')
637')')
638ifdef(`_NO_CANONIFY_', `dnl', `dnl
639# pass to name server to make hostname canonical
640R$* < @ $* $~P > $*		$: $1 < @ $[ $2 $3 $] > $4')
641
642# local host aliases and pseudo-domains are always canonical
643R$* < @ $=w > $*		$: $1 < @ $2 . > $3
644R$* < @ $j > $*			$: $1 < @ $j . > $2
645ifdef(`_MASQUERADE_ENTIRE_DOMAIN_',
646`R$* < @ $* $=M > $*		$: $1 < @ $2 $3 . > $4',
647`R$* < @ $=M > $*		$: $1 < @ $2 . > $3')
648R$* < @ $* $=P > $*		$: $1 < @ $2 $3 . > $4
649R$* < @ $* . . > $*		$1 < @ $2 . > $3
650
651
652##################################################
653###  Ruleset 4 -- Final Output Post-rewriting  ###
654##################################################
655S4
656
657R$* <@>			$@				handle <> and list:;
658
659# strip trailing dot off possibly canonical name
660R$* < @ $+ . > $*	$1 < @ $2 > $3
661
662# eliminate internal code -- should never get this far!
663R$* < @ *LOCAL* > $*	$1 < @ $j > $2
664
665# externalize local domain info
666R$* < $+ > $*		$1 $2 $3			defocus
667R@ $+ : @ $+ : $+	@ $1 , @ $2 : $3		<route-addr> canonical
668R@ $*			$@ @ $1				... and exit
669
670ifdef(`_NO_UUCP_', `dnl',
671`# UUCP must always be presented in old form
672R$+ @ $- . UUCP		$2!$1				u@h.UUCP => h!u')
673
674ifdef(`_USE_DECNET_SYNTAX_',
675`# put DECnet back in :: form
676R$+ @ $+ . DECNET	$2 :: $1			u@h.DECNET => h::u',
677	`dnl')
678# delete duplicate local names
679R$+ % $=w @ $=w		$1 @ $2				u%host@host => u@host
680
681
682
683##############################################################
684###   Ruleset 97 -- recanonicalize and call ruleset zero   ###
685###		   (used for recursive calls)		   ###
686##############################################################
687
688S`'97
689R$*			$: $>3 $1
690R$*			$@ $>0 $1
691
692
693######################################
694###   Ruleset 0 -- Parse Address   ###
695######################################
696
697S0
698
699R$*			$: $>Parse0 $1		initial parsing
700R<@>			$#_LOCAL_ $: <@>		special case error msgs
701R$*			$: $>98 $1		handle local hacks
702R$*			$: $>Parse1 $1		final parsing
703
704#
705#  Parse0 -- do initial syntax checking and eliminate local addresses.
706#	This should either return with the (possibly modified) input
707#	or return with a #error mailer.  It should not return with a
708#	#mailer other than the #error mailer.
709#
710
711SParse0
712R<@>			$@ <@>			special case error msgs
713R$* : $* ; <@>		$#error $@ 5.1.3 $: "List:; syntax illegal for recipient addresses"
714#R@ <@ $* >		< @ $1 >		catch "@@host" bogosity
715R<@ $+>			$#error $@ 5.1.3 $: "User address required"
716R$*			$: <> $1
717R<> $* < @ [ $+ ] > $*	$1 < @ [ $2 ] > $3
718R<> $* <$* : $* > $*	$#error $@ 5.1.3 $: "Colon illegal in host name part"
719R<> $*			$1
720R$* < @ . $* > $*	$#error $@ 5.1.2 $: "Invalid host name"
721R$* < @ $* .. $* > $*	$#error $@ 5.1.2 $: "Invalid host name"
722
723# now delete the local info -- note $=O to find characters that cause forwarding
724R$* < @ > $*		$@ $>Parse0 $>3 $1		user@ => user
725R< @ $=w . > : $*	$@ $>Parse0 $>3 $2		@here:... -> ...
726R$- < @ $=w . >		$: $(dequote $1 $) < @ $2 . >	dequote "foo"@here
727R< @ $+ >		$#error $@ 5.1.3 $: "User address required"
728R$* $=O $* < @ $=w . >	$@ $>Parse0 $>3 $1 $2 $3	...@here -> ...
729R$- 			$: $(dequote $1 $) < @ *LOCAL* >	dequote "foo"
730R< @ *LOCAL* >		$#error $@ 5.1.3 $: "User address required"
731R$* $=O $* < @ *LOCAL* >
732			$@ $>Parse0 $>3 $1 $2 $3	...@*LOCAL* -> ...
733R$* < @ *LOCAL* >	$: $1
734
735#
736#  Parse1 -- the bottom half of ruleset 0.
737#
738
739SParse1
740ifdef(`_MAILER_smtp_',
741`# handle numeric address spec
742R$* < @ [ $+ ] > $*	$: $>98 $1 < @ [ $2 ] > $3	numeric internet spec
743R$* < @ [ $+ ] > $*	$#_SMTP_ $@ [$2] $: $1 < @ [$2] > $3	still numeric: send',
744	`dnl')
745
746ifdef(`VIRTUSER_TABLE', `dnl
747# handle virtual users
748R$+ < @ $=w . > 	$: < $(virtuser $1 @ $2 $@ $1 $: @ $) > $1 < @ $2 . >
749R<@> $+ + $* < @ $* . >
750			$: < $(virtuser $1 + * @ $3 $@ $1 $: @ $) > $1 + $2 < @ $3 . >
751R<@> $+ + $* < @ $* . >
752			$: < $(virtuser $1 @ $3 $@ $1 $: @ $) > $1 + $2 < @ $3 . >
753R<@> $+ < @ $+ . >	$: < $(virtuser @ $2 $@ $1 $: @ $) > $1 < @ $2 . >
754R<@> $+			$: $1
755R< error : $- $+ > $* 	$#error $@ $(dequote $1 $) $: $2
756R< $+ > $+ < @ $+ >	$: $>97 $1',
757`dnl')
758
759# short circuit local delivery so forwarded email works
760ifdef(`_MAILER_usenet_', `dnl
761R$+ . USENET < @ $=w . >	$#usenet $: $1		handle usenet specially', `dnl')
762ifdef(`_STICKY_LOCAL_DOMAIN_',
763`R$+ < @ $=w . >		$: < $H > $1 < @ $2 . >		first try hub
764R< $+ > $+ < $+ >	$>95 < $1 > $2 < $3 >		yep ....
765R< > $+ + $* < $+ >	$#_LOCAL_ $: $1 + $2		plussed name?
766R< > $+ < $+ >		$#_LOCAL_ $: @ $1			nope, local address',
767`R$=L < @ $=w . >	$#_LOCAL_ $: @ $1		special local names
768R$+ < @ $=w . >		$#_LOCAL_ $: $1			regular local name')
769
770ifdef(`MAILER_TABLE', `dnl
771# not local -- try mailer table lookup
772R$* <@ $+ > $*		$: < $2 > $1 < @ $2 > $3	extract host name
773R< $+ . > $*		$: < $1 > $2			strip trailing dot
774R< $+ > $*		$: < $(mailertable $1 $) > $2	lookup
775R< $~[ : $+ > $* 	$>95 < $1 : $2 > $3		check -- resolved?
776R< $+ > $*		$: $>90 <$1> $2			try domain',
777`dnl')
778undivert(4)dnl
779
780ifdef(`_NO_UUCP_', `dnl',
781`# resolve remotely connected UUCP links (if any)
782ifdef(`_CLASS_V_',
783`R$* < @ $=V . UUCP . > $*		$: $>95 < $V > $1 <@$2.UUCP.> $3',
784	`dnl')
785ifdef(`_CLASS_W_',
786`R$* < @ $=W . UUCP . > $*		$: $>95 < $W > $1 <@$2.UUCP.> $3',
787	`dnl')
788ifdef(`_CLASS_X_',
789`R$* < @ $=X . UUCP . > $*		$: $>95 < $X > $1 <@$2.UUCP.> $3',
790	`dnl')')
791
792# resolve fake top level domains by forwarding to other hosts
793ifdef(`BITNET_RELAY',
794`R$*<@$+.BITNET.>$*	$: $>95 < $B > $1 <@$2.BITNET.> $3	user@host.BITNET',
795	`dnl')
796ifdef(`DECNET_RELAY',
797`R$*<@$+.DECNET.>$*	$: $>95 < $C > $1 <@$2.DECNET.> $3	user@host.DECNET',
798	`dnl')
799ifdef(`_MAILER_pop_',
800`R$+ < @ POP. >		$#pop $: $1			user@POP',
801	`dnl')
802ifdef(`_MAILER_fax_',
803`R$+ < @ $+ .FAX. >	$#fax $@ $2 $: $1		user@host.FAX',
804`ifdef(`FAX_RELAY',
805`R$*<@$+.FAX.>$*		$: $>95 < $F > $1 <@$2.FAX.> $3	user@host.FAX',
806	`dnl')')
807
808ifdef(`UUCP_RELAY',
809`# forward non-local UUCP traffic to our UUCP relay
810R$*<@$*.UUCP.>$*		$: $>95 < $Y > $1 <@$2.UUCP.> $3	uucp mail',
811`ifdef(`_MAILER_uucp_',
812`# forward other UUCP traffic straight to UUCP
813R$* < @ $+ .UUCP. > $*		$#_UUCP_ $@ $2 $: $1 < @ $2 .UUCP. > $3	user@host.UUCP',
814	`dnl')')
815ifdef(`_MAILER_usenet_', `
816# addresses sent to net.group.USENET will get forwarded to a newsgroup
817R$+ . USENET		$#usenet $: $1',
818	`dnl')
819
820ifdef(`_LOCAL_RULES_',
821`# figure out what should stay in our local mail system
822undivert(1)', `dnl')
823
824# pass names that still have a host to a smarthost (if defined)
825R$* < @ $* > $*		$: $>95 < $S > $1 < @ $2 > $3	glue on smarthost name
826
827# deal with other remote names
828ifdef(`_MAILER_smtp_',
829`R$* < @$* > $*		$#_SMTP_ $@ $2 $: $1 < @ $2 > $3		user@host.domain',
830`R$* < @$* > $*		$#error $@ 5.1.2 $: "Unrecognized host name" $2')
831
832# handle locally delivered names
833R$=L			$#_LOCAL_ $: @ $1			special local names
834R$+			$#_LOCAL_ $: $1			regular local names
835
836###########################################################################
837###   Ruleset 5 -- special rewriting after aliases have been expanded   ###
838###########################################################################
839
840S5
841
842# deal with plussed users so aliases work nicely
843R$+ + *			$#_LOCAL_ $@ $&h $: $1
844R$+ + $*		$#_LOCAL_ $@ + $2 $: $1 + *
845
846# prepend an empty "forward host" on the front
847R$+			$: <> $1
848
849ifdef(`LUSER_RELAY', `dnl
850# send unrecognized local users to a relay host
851R< > $+ 		$: < $L . > $(user $1 $)	look up user
852R< $* > $+ <> $*	$: < > $2 $3			found; strip $L
853R< $* . > $+		$: < $1 > $2			strip extra dot',
854`dnl')
855
856# see if we have a relay or a hub
857R< > $+			$: < $H > $1			try hub
858R< > $+			$: < $R > $1			try relay
859R< > $+			$: < > < $1 $&h >		nope, restore +detail
860R< > < $+ + $* > $*	   < > < $1 > + $2 $3		find the user part
861R< > < $+ > + $*	$#_LOCAL_ $@ $2 $: @ $1		strip the extra +
862R< > < $+ >		$@ $1				no +detail
863R$+			$: $1 $&h			add +detail back in
864R< local : $* > $*	$: $>95 < local : $1 > $2	no host extension
865R< error : $* > $*	$: $>95 < error : $1 > $2	no host extension
866R< $- : $+ > $+		$: $>95 < $1 : $2 > $3 < @ $2 >
867R< $+ > $+		$@ $>95 < $1 > $2 < @ $1 >
868
869ifdef(`MAILER_TABLE', `dnl
870###################################################################
871###  Ruleset 90 -- try domain part of mailertable entry 	###
872###################################################################
873
874S90
875R$* <$- . $+ > $*	$: $1$2 < $(mailertable .$3 $@ $1$2 $@ $2 $) > $4
876R$* <$~[ : $+ > $*	$>95 < $2 : $3 > $4		check -- resolved?
877R$* < . $+ > $* 	$@ $>90 $1 . <$2> $3		no -- strip & try again
878R$* < $* > $*		$: < $(mailertable . $@ $1$2 $) > $3	try "."
879R< $~[ : $+ > $*	$>95 < $1 : $2 > $3		"." found?
880R< $* > $*		$@ $2				no mailertable match',
881`dnl')
882
883###################################################################
884###  Ruleset 95 -- canonify mailer:[user@]host syntax to triple	###
885###################################################################
886
887S95
888R< > $*				$@ $1			strip off null relay
889R< error : $- $+ > $*		$#error $@ $(dequote $1 $) $: $2
890R< local : $* > $*		$>CanonLocal < $1 > $2
891R< $- : $+ @ $+ > $*<$*>$*	$# $1 $@ $3 $: $2<@$3>	use literal user
892R< $- : $+ > $*			$# $1 $@ $2 $: $3	try qualified mailer
893R< $=w > $*			$@ $2			delete local host
894R< $+ > $*			$#_RELAY_ $@ $1 $: $2	use unqualified mailer
895
896###################################################################
897###  Ruleset CanonLocal -- canonify local: syntax		###
898###################################################################
899
900SCanonLocal
901# strip trailing dot from any host name that may appear
902R< $* > $* < @ $* . >		$: < $1 > $2 < @ $3 >
903
904# handle local: syntax -- use old user, either with or without host
905R< > $* < @ $* > $*		$#_LOCAL_ $@ $1@$2 $: $1
906R< > $+				$#_LOCAL_ $@ $1    $: $1
907
908# handle local:user@host syntax -- ignore host part
909R< $+ @ $+ > $* < @ $* >	$: < $1 > $3 < @ $4 >
910
911# handle local:user syntax
912R< $+ > $* <@ $* > $*		$#_LOCAL_ $@ $2@$3 $: $1
913R< $+ > $* 			$#_LOCAL_ $@ $2    $: $1
914
915###################################################################
916###  Ruleset 93 -- convert header names to masqueraded form	###
917###################################################################
918
919S93
920
921ifdef(`GENERICS_TABLE', `dnl
922# handle generics database
923ifdef(`_GENERICS_ENTIRE_DOMAIN_',
924`R$+ < @ $* $=G . >	$: < $1@$2$3 > $1 < @ $2$3 . > @	mark',
925`R$+ < @ $=G . >	$: < $1@$2 > $1 < @ $2 . > @	mark')
926R$+ < @ *LOCAL* >	$: < $1@$j > $1 < @ *LOCAL* > @	mark
927R< $+ > $+ < $* > @	$: < $(generics $1 $: $) > $2 < $3 >
928R< > $+ < @ $+ > 	$: < $(generics $1 $: $) > $1 < @ $2 >
929R< $* @ $* > $* < $* >	$@ $>3 $1 @ $2			found qualified
930R< $+ > $* < $* >	$: $>3 $1 @ *LOCAL*		found unqualified
931R< > $*			$: $1				not found',
932`dnl')
933
934# special case the users that should be exposed
935R$=E < @ *LOCAL* >	$@ $1 < @ $j . >		leave exposed
936ifdef(`_MASQUERADE_ENTIRE_DOMAIN_',
937`R$=E < @ $* $=M . >	$@ $1 < @ $2 $3 . >',
938`R$=E < @ $=M . >	$@ $1 < @ $2 . >')
939ifdef(`_LIMITED_MASQUERADE_', `dnl',
940`R$=E < @ $=w . >	$@ $1 < @ $2 . >')
941
942# handle domain-specific masquerading
943ifdef(`_MASQUERADE_ENTIRE_DOMAIN_',
944`R$* < @ $* $=M . > $*	$: $1 < @ $2 $3 . @ $M > $4	convert masqueraded doms',
945`R$* < @ $=M . > $*	$: $1 < @ $2 . @ $M > $3	convert masqueraded doms')
946ifdef(`_LIMITED_MASQUERADE_', `dnl',
947`R$* < @ $=w . > $*	$: $1 < @ $2 . @ $M > $3')
948R$* < @ *LOCAL* > $*	$: $1 < @ $j . @ $M > $2
949R$* < @ $+ @ > $*	$: $1 < @ $2 > $3		$M is null
950R$* < @ $+ @ $+ > $*	$: $1 < @ $3 . > $4		$M is not null
951
952###################################################################
953###  Ruleset 94 -- convert envelope names to masqueraded form	###
954###################################################################
955
956S94
957ifdef(`_MASQUERADE_ENVELOPE_',
958`R$+			$@ $>93 $1',
959`R$* < @ *LOCAL* > $*	$: $1 < @ $j . > $2')
960
961###################################################################
962###  Ruleset 98 -- local part of ruleset zero (can be null)	###
963###################################################################
964
965S98
966undivert(3)dnl
967
968ifelse(confDELIVERY_MODE, defer, `errprint(`WARNING: Antispam rules not available in deferred delivery mode.')')
969ifdef(`ACCESS_TABLE', `dnl
970######################################################################
971###  LookUpDomain -- search for domain in access database
972###
973###	Parameters:
974###		<$1> -- key (domain name)
975###		<$2> -- default (what to return if not found in db)
976###		<$3> -- passthru (additional data passed unchanged through)
977######################################################################
978
979SLookUpDomain
980R<$+> <$+> <$*>		$: < $(access $1 $: ? $) > <$1> <$2> <$3>
981R<?> <$+.$+> <$+> <$*>	$@ $>LookUpDomain <$2> <$3> <$4>
982R<?> <$+> <$+> <$*>	$@ <$2> <$3>
983R<$*> <$+> <$+> <$*>	$@ <$1> <$4>
984
985######################################################################
986###  LookUpAddress -- search for host address in access database
987###
988###	Parameters:
989###		<$1> -- key (dot quadded host address)
990###		<$2> -- default (what to return if not found in db)
991###		<$3> -- passthru (additional data passed through)
992######################################################################
993
994SLookUpAddress
995R<$+> <$+> <$*>		$: < $(access $1 $: ? $) > <$1> <$2> <$3>
996R<?> <$+.$-> <$+> <$*>	$@ $>LookUpAddress <$1> <$3> <$4>
997R<?> <$+> <$+> <$*>	$@ <$2> <$3>
998R<$*> <$+> <$+> <$*>	$@ <$1> <$4>',
999`dnl')
1000
1001######################################################################
1002###  ParseRecipient --	Strip off hosts in $=R as well as possibly
1003###			$* $=m or the access database.
1004###			Check user portion for host separators.
1005###
1006###	Parameters:
1007###		$1 -- full recipient address
1008###
1009###	Returns:
1010###		parsed, non-local-relaying address
1011######################################################################
1012
1013SParseRecipient
1014R$*			$: <?> $>Parse0 $>3 $1
1015R<?> $* < @ $* . >	<?> $1 < @ $2 >		strip trailing dots
1016R<?> $- < @ $* >	$: <?> $(dequote $1 $) < @ $2 >		dequote local part
1017
1018# if no $=O character, no host in the user portion, we are done
1019R<?> $* $=O $* < @ $* >	$: <NO> $1 $2 $3 < @ $4>
1020R<?> $*			$@ $1
1021
1022ifdef(`_RELAY_ENTIRE_DOMAIN_', `dnl
1023# if we relay, check username portion for user%host so host can be checked also
1024R<NO> $* < @ $* $=m >	$: <RELAY> $1 < @ $2 $3 >', `dnl')
1025ifdef(`_RELAY_HOSTS_ONLY_',
1026`R<NO> $* < @ $=R >	$: <RELAY> $1 < @ $2 >
1027ifdef(`ACCESS_TABLE', `dnl
1028R<NO> $* < @ $* >	$: <$(access $2 $: NO $)> $1 < @ $2 >',`dnl')',
1029`R<NO> $* < @ $* $=R >	$: <RELAY> $1 < @ $2 $3 >
1030ifdef(`ACCESS_TABLE', `dnl
1031R<NO> $* < @ $* >	$: $>LookUpDomain <$2> <NO> <$1 < @ $2 >>
1032R<$+> <$+>		$: <$1> $2',`dnl')')
1033R<RELAY> $* < @ $* >	$@ $>ParseRecipient $1
1034R<$-> $*		$@ $2
1035
1036######################################################################
1037###  check_relay -- check hostname/address on SMTP startup
1038######################################################################
1039
1040SLocal_check_relay
1041Scheck_relay
1042R$*			$: $1 $| $>"Local_check_relay" $1
1043R$* $| $* $| $#$*	$#$3
1044R$* $| $* $| $*		$@ $>"Basic_check_relay" $1 $| $2
1045
1046SBasic_check_relay
1047# check for deferred delivery mode
1048R$*			$: < ${deliveryMode} > $1
1049R< d > $*		$@ deferred
1050R< $* > $*		$: $2
1051
1052ifdef(`ACCESS_TABLE', `dnl
1053R$+ $| $+		$: $>LookUpDomain < $1 > <?> < $2 >
1054R<?> < $+ >		$: $>LookUpAddress < $1 > <OK> < $1 >
1055R<OK> < $* >		$: $1
1056R<RELAY> < $* >		$: $1
1057R<REJECT> $*		$#error $@ 5.7.1 $: "ifdef(`confREJECT_MSG', `confREJECT_MSG', `550 Access denied')"
1058R<DISCARD> $*		$#discard $: discard
1059R<$+> $*		$#error $@ 5.7.1 $: $1', `dnl')
1060
1061ifdef(`_RBL_', `dnl
1062# MAPS project checks -- http://maps.vix.com/
1063R$*			$: $&{client_addr}
1064R$-.$-.$-.$-		$: $(host $4.$3.$2.$1._RBL_. $: OK $)
1065ROK			$@ OK
1066R$+			$#error $@ 5.7.1 $: "Mail from " $&{client_addr} " refused; see http://maps.vix.com/rbl/"',
1067`dnl')
1068
1069######################################################################
1070###  check_mail -- check SMTP ``MAIL FROM:'' command argument
1071######################################################################
1072
1073SLocal_check_mail
1074Scheck_mail
1075R$*			$: $1 $| $>"Local_check_mail" $1
1076R$* $| $#$*		$#$2
1077R$* $| $*		$@ $>"Basic_check_mail" $1
1078
1079SBasic_check_mail
1080# check for deferred delivery mode
1081R$*			$: < ${deliveryMode} > $1
1082R< d > $*		$@ deferred
1083R< $* > $*		$: $2
1084
1085R<>			$@ <OK>
1086R$*			$: <?> $>Parse0 $>3 $1		make domain canonical
1087R<?> $* < @ $+ . > $*	<?> $1 < @ $2 > $3		strip trailing dots
1088# handle non-DNS hostnames (*.bitnet, *.decnet, *.uucp, etc)
1089R<?> $* < $* $=P > $*	$: <OK> $1 < @ $2 $3 > $4
1090ifdef(`_ACCEPT_UNRESOLVABLE_DOMAINS_',
1091`R<?> $* < @ $+ > $*	$: <OK> $1 < @ $2 > $3		... unresolvable OK',
1092`R<?> $* < @ $+ > $*	$: <? $(resolve $2 $: $2 <PERM> $) > $1 < @ $2 > $3
1093R<? $* <$->> $* < @ $+ > $*
1094			$: <$2> $3 < @ $4 > $5')
1095
1096ifdef(`_ACCEPT_UNQUALIFIED_SENDERS_',`dnl',`dnl
1097# handle case of @localhost on address
1098R<$+> $* < @localhost >	$: < ? $&{client_name} > <$1> $2 < @localhost >
1099R<$+> $* < @localhost.$m >
1100			$: < ? $&{client_name} > <$1> $2 < @localhost.$m >
1101ifdef(`_NO_UUCP_', `dnl',
1102`R<$+> $* < @localhost.UUCP >
1103			$: < ? $&{client_name} > <$1> $2 < @localhost.UUCP >')
1104R<? $=w> <$+> $*	<?> <$2> $3
1105R<? $+> <$+> $*		$#error $@ 5.5.4 $: "553 Real domain name required"
1106R<?> <$+> $*		$: <$1> $2')
1107
1108ifdef(`ACCESS_TABLE', `dnl
1109# lookup localpart (user@)
1110R<$+> $* < @ $+ > $*	$: <USER $(access $2@ $: ? $) > <$1> $2 < @ $3 > $4
1111# no match, try full address (user@domain rest)
1112R<USER ?> <$+> $* < @ $* > $*
1113			$: <USER $(access $2@$3$4 $: ? $) > <$1> $2 < @ $3 > $4
1114# no match, try address (user@domain)
1115R<USER ?> <$+> $+ < @ $+ > $*
1116			$: <USER $(access $2@$3 $: ? $) > <$1> $2 < @ $3 > $4
1117# no match, try (sub)domain (domain)
1118R<USER ?> <$+> $* < @ $+ > $*
1119			$: $>LookUpDomain <$3> <$1> <>
1120# check unqualified user in access database
1121R<?> $*			$: <USER $(access $1@ $: ? $) > <?> $1
1122# retransform for further use
1123R<USER $+> <$+> $*	$: <$1> $3',
1124`dnl')
1125
1126ifdef(`_ACCEPT_UNQUALIFIED_SENDERS_',`dnl',`dnl
1127# handle case of no @domain on address
1128R<?> $*			$: < ? $&{client_name} > $1
1129R<?> $*			$@ <OK>				...local unqualed ok
1130R<? $+> $*		$#error $@ 5.5.4 $: "553 Domain name required"
1131							...remote is not')
1132# check results
1133R<?> $*			$@ <OK>
1134R<OK> $*		$@ <OK>
1135R<TEMP> $*		$#error $@ 4.1.8 $: "451 Sender domain must resolve"
1136R<PERM> $*		$#error $@ 5.1.8 $: "501 Sender domain must exist"
1137ifdef(`ACCESS_TABLE', `dnl
1138R<RELAY> $*		$@ <RELAY>
1139R<DISCARD> $*		$#discard $: discard
1140R<REJECT> $*		$#error $@ 5.7.1 $: "ifdef(`confREJECT_MSG', `confREJECT_MSG', `550 Access denied')"
1141R<$+> $*		$#error $@ 5.7.1 $: $1		error from access db',
1142`dnl')
1143
1144######################################################################
1145###  check_rcpt -- check SMTP ``RCPT TO:'' command argument
1146######################################################################
1147
1148SLocal_check_rcpt
1149Scheck_rcpt
1150R$*			$: $1 $| $>"Local_check_rcpt" $1
1151R$* $| $#$*		$#$2
1152R$* $| $*		$@ $>"Basic_check_rcpt" $1
1153
1154SBasic_check_rcpt
1155# check for deferred delivery mode
1156R$*			$: < ${deliveryMode} > $1
1157R< d > $*		$@ deferred
1158R< $* > $*		$: $2
1159
1160ifdef(`_LOOSE_RELAY_CHECK_',`dnl
1161R$*			$: $>Parse0 $>3 $1
1162R$* < @ $* . >		$1 < @ $2 >			strip trailing dots',
1163`R$*			$: $>ParseRecipient $1		strip relayable hosts')
1164
1165ifdef(`_BLACKLIST_RCPT_',`dnl
1166ifdef(`ACCESS_TABLE', `dnl
1167# blacklist local users or any host from receiving mail
1168R$*			$: <?> $1
1169R<?> $+ < @ $=w >	$: <> <USER $1> <FULL $1@$2> <HOST $2> <$1 < @ $2 >>
1170R<?> $+ < @ $* >	$: <> <FULL $1@$2> <HOST $2> <$1 < @ $2 >>
1171R<?> $+			$: <> <USER $1> <$1>
1172R<> <USER $+> $*	$: <$(access $1 $: $)> $2
1173R<> <FULL $+> $*	$: <$(access $1 $: $)> $2
1174R<OK> <FULL $+> $*	$: <$(access $1 $: $)> $2
1175R<> <HOST $+> $*	$: <$(access $1 $: $)> $2
1176R<OK> <HOST $+> $*	$: <$(access $1 $: $)> $2
1177R<> <$*>		$: $1
1178R<OK> <$*>		$: $1
1179R<RELAY> <$*>		$: $1
1180R<REJECT> $*		$#error $@ 5.2.1 $: "550 Mailbox disabled for this recipient"
1181R<$+> $*		$#error $@ 5.2.1 $: $1			error from access db', `dnl')', `dnl')
1182
1183ifdef(`_PROMISCUOUS_RELAY_', `dnl', `dnl
1184# anything terminating locally is ok
1185ifdef(`_RELAY_ENTIRE_DOMAIN_', `dnl
1186R$+ < @ $* $=m >	$@ OK', `dnl')
1187R$+ < @ $=w >		$@ OK
1188ifdef(`_RELAY_HOSTS_ONLY_',
1189`R$+ < @ $=R >		$@ OK
1190ifdef(`ACCESS_TABLE', `dnl
1191R$+ < @ $* >		$: <$(access $2 $: ? $)> <$1 < @ $2 >>',`dnl')',
1192`R$+ < @ $* $=R >	$@ OK
1193ifdef(`ACCESS_TABLE', `dnl
1194R$+ < @ $* >		$: $>LookUpDomain <$2> <?> <$1 < @ $2 >>',`dnl')')
1195ifdef(`ACCESS_TABLE', `dnl
1196R<RELAY> $*		$@ RELAY
1197R<$*> <$*>		$: $2',`dnl')
1198
1199ifdef(`_RELAY_MX_SERVED_', `dnl
1200# allow relaying for hosts which we MX serve
1201R$+ < @ $* >		$: < : $(mxserved $2 $) : > $1 < @ $2 >
1202R< : $* <TEMP> : > $*	$#error $@ 4.7.1 $: "450 Can not check MX records for recipient host " $1
1203R<$* : $=w . : $*> $*	$@ OK
1204R<$*> $*			$: $2',
1205`dnl')
1206
1207# check for local user (i.e. unqualified address)
1208R$*			$: <?> $1
1209R<?> $+ < @ $+ >	$: <REMOTE> $1 < @ $2 >
1210# local user is ok
1211R<?> $+			$@ OK
1212R<$+> $*		$: $2
1213
1214# anything originating locally is ok
1215R$*			$: <?> $&{client_name}
1216# check if bracketed IP address (forward lookup != reverse lookup)
1217R<?> [$+]		$: <BAD> [$1]
1218# pass to name server to make hostname canonical
1219R<?> $* $~P 		$: <?> $[ $1 $2 $]
1220R<$-> $*		$: $2
1221R$* .			$1				strip trailing dots
1222R$@			$@ OK
1223ifdef(`_RELAY_ENTIRE_DOMAIN_', `dnl
1224R$* $=m			$@ OK', `dnl')
1225R$=w			$@ OK
1226ifdef(`_RELAY_HOSTS_ONLY_',
1227`R$=R			$@ OK
1228ifdef(`ACCESS_TABLE', `dnl
1229R$*			$: <$(access $1 $: ? $)> <$1>',`dnl')',
1230`R$* $=R			$@ OK
1231ifdef(`ACCESS_TABLE', `dnl
1232R$*			$: $>LookUpDomain <$1> <?> <$1>',`dnl')')
1233ifdef(`ACCESS_TABLE', `dnl
1234R<RELAY> $*		$@ RELAY
1235R<$*> <$*>		$: $2',`dnl')
1236
1237# check IP address
1238R$*			$: $&{client_addr}
1239R$@			$@ OK			originated locally
1240R0			$@ OK			originated locally
1241R$=R $*			$@ OK			relayable IP address
1242ifdef(`ACCESS_TABLE', `dnl
1243R$*			$: $>LookUpAddress <$1> <?> <$1>
1244R<RELAY> $* 		$@ RELAY		relayable IP address
1245R<$*> <$*>		$: $2', `dnl')
1246R$*			$: [ $1 ]		put brackets around it...
1247R$=w			$@ OK			... and see if it is local
1248
1249ifdef(`_RELAY_LOCAL_FROM_', `dnl
1250# anything with a local FROM is ok
1251R$*			$: $1 $| $>Parse0 $>3 $&f
1252R$* $| $+ < @ $=w . >	$@ OK			FROM local
1253R$* $| $*		$: $1
1254', `dnl')
1255
1256# anything else is bogus
1257R$*			$#error $@ 5.7.1 $: "550 Relaying denied"')
1258
1259undivert(9)dnl
1260#
1261######################################################################
1262######################################################################
1263#####
1264`#####			MAILER DEFINITIONS'
1265#####
1266######################################################################
1267######################################################################
1268undivert(7)dnl
1269