xref: /freebsd/contrib/sendmail/cf/feature/bcc.m4 (revision 43a5ec4eb41567cc92586503212743d89686d78f)
1divert(-1)
2#
3# Copyright (c) 2014 Proofpoint, Inc. and its suppliers.
4#	All rights reserved.
5#
6# By using this file, you agree to the terms and conditions set
7# forth in the LICENSE file which can be found at the top level of
8# the sendmail distribution.
9#
10#
11
12divert(-1)
13# Arguments:
14# 1: Map to use
15#   - empty/none: default map bcctable
16#   - `access': to use access_db (with bcc: as tag)
17#   - map definition
18#   The map contains domain names and the RHS should be simply "ok".
19#   If the access map is used, then its lookup algorithm is used.
20#   Otherwise:
21#    domain	ok
22#   matches anything@domain
23#    .domain	ok
24#   matches any subdomain, e.g., l@sub.domain and l@sub.dom.domain
25#   On a match, the original address will be used as bcc address unless
26#   argument 3 is set.
27# 2: Name of host ([mailer:]host)
28# 3: Default bcc address: if set, this will be always used.
29#   Only one of 2/3 can be empty.
30#   Note: if Bcc address is used then only one copy will be sent!
31#   (due to duplicate elimination)
32# 4: Map definition for canonicalRcpt map of address rewriting to
33#   apply to the added bcc envelope recipients.
34#   The option -T<TMPF> is required to handle temporary map failures.
35#
36# The ruleset must return either
37# - an e-mail address (user@dom.ain) which is then added as "bcc" recipient.
38# - an empty string: do not add a "bcc" recipient, or
39# - $#error: fail the SMTP transaction (e.g., temporary lookup failure)
40#
41# This feature sets O AddBcc=true
42
43ifelse(lower(_ARG_),`access',`define(`_BCC_ACCESS_', `1')')
44define(`_ADD_BCC_', `1')
45
46ifdef(`_BCC_ACCESS_', `dnl
47ifdef(`_ACCESS_TABLE_', `',
48	`errprint(`*** ERROR: FEATURE(`bcc') requires FEATURE(`access_db')
49')')')
50
51ifdef(`_BCC_ACCESS_', `', `
52LOCAL_CONFIG
53Kbcctable ifelse(defn(`_ARG_'), `', DATABASE_MAP_TYPE MAIL_SETTINGS_DIR`bcctable', `_ARG_')')
54
55LOCAL_CONFIG
56O AddBcc=true
57ifelse(len(X`'_ARG2_),`1', `', `
58DA`'_ARG2_')
59
60ifelse(len(X`'_ARG4_), `1', `',
61`define(`_CANONIFY_BCC_', `1')dnl
62define(`_NEED_SMTPOPMODES_', `1')dnl
63# canonical address look up for AddBcc recipients
64KcanonicalRcpt _ARG4_
65')dnl
66
67LOCAL_RULESETS
68Sbcc
69R< $+ >			$1
70ifdef(`_BCC_ACCESS_', `dnl
71R$+ @ $+		$: $1@$2 $| $>SearchList <! bcc> $| <D:$2> <>',
72`R$+ @ $+		$: $1@$2 $| $>BCC $2')
73R$* $| <?>		$@
74R$* $| $*		$: ifelse(len(X`'_ARG3_),`1', `$1', `_ARG3_')
75
76ifdef(`_CANONIFY_BCC_', `dnl
77R$+ @ $+		$: $1@$2 $| <$(canonicalRcpt $1 @ $2 $: $)>
78R$* $| <>		$@
79R$* $| <$* <TMPF>>	$#error $@ 4.3.0 $: _TMPFMSG_(`BCC')
80R$* $| <$+>		$@ $2			map matched?
81')
82
83
84ifdef(`_BCC_ACCESS_', `', `
85SBCC
86R$+		$: $1 < $(bcctable $1 $: ? $) >
87R$- . $+ <?>	$: $2 < $(bcctable .$2 $: ? $) >
88R$- . $+ <?>	$: $>BCC $2
89R$* <$*>	$: <$2>
90')
91