7 /* process envelope addresses
9 /* #include <cleanup.h>
11 /* void cleanup_addr_sender(state, addr)
12 /* CLEANUP_STATE *state;
15 /* void cleanup_addr_recipient(state, addr)
16 /* CLEANUP_STATE *state;
19 /* void cleanup_addr_bcc(state, addr)
20 /* CLEANUP_STATE *state;
23 /* This module processes envelope address records and writes the result
24 /* to the queue file. Processing includes address rewriting and
25 /* sender/recipient auto bcc address generation.
27 /* cleanup_addr_sender() processes sender envelope information and updates
30 /* cleanup_addr_recipient() processes recipient envelope information
31 /* and updates state->recip.
33 /* cleanup_addr_bcc() processes recipient envelope information. This
34 /* is a separate function to avoid invoking cleanup_addr_recipient()
39 /* Queue file and message processing state. This state is updated
40 /* as records are processed and as errors happen.
46 /* The Secure Mailer license must be distributed with this software.
49 /* IBM T.J. Watson Research
51 /* Yorktown Heights, NY 10598, USA
60 #ifdef STRCASECMP_IN_STRINGS_H
64 /* Utility library. */
70 #include <stringops.h>
75 #include <cleanup_user.h>
76 #include <mail_params.h>
78 #include <mail_addr.h>
79 #include <canon_addr.h>
80 #include <mail_addr_find.h>
81 #include <mail_proto.h>
84 /* Application-specific. */
88 #define STR vstring_str
89 #define IGNORE_EXTENSION (char **) 0
91 /* cleanup_addr_sender - process envelope sender record */
93 void cleanup_addr_sender(CLEANUP_STATE
*state
, const char *buf
)
95 VSTRING
*clean_addr
= vstring_alloc(100);
99 * Note: an unqualified envelope address is for all practical purposes
100 * equivalent to a fully qualified local address, both for delivery and
101 * for replying. Having to support both forms is error prone, therefore
102 * an incomplete envelope address is rewritten to fully qualified form in
103 * the local domain context.
105 * 20000520: Replace mailer-daemon@$myorigin by the null address, to handle
106 * bounced mail traffic more robustly.
108 cleanup_rewrite_internal(MAIL_ATTR_RWR_LOCAL
, clean_addr
, buf
);
109 if (strncasecmp(STR(clean_addr
), MAIL_ADDR_MAIL_DAEMON
"@",
110 sizeof(MAIL_ADDR_MAIL_DAEMON
)) == 0) {
111 canon_addr_internal(state
->temp1
, MAIL_ADDR_MAIL_DAEMON
);
112 if (strcasecmp(STR(clean_addr
), STR(state
->temp1
)) == 0)
113 vstring_strcpy(clean_addr
, "");
115 if (state
->flags
& CLEANUP_FLAG_MAP_OK
) {
116 if (cleanup_send_canon_maps
117 && (cleanup_send_canon_flags
& CLEANUP_CANON_FLAG_ENV_FROM
))
118 cleanup_map11_internal(state
, clean_addr
, cleanup_send_canon_maps
,
119 cleanup_ext_prop_mask
& EXT_PROP_CANONICAL
);
120 if (cleanup_comm_canon_maps
121 && (cleanup_comm_canon_flags
& CLEANUP_CANON_FLAG_ENV_FROM
))
122 cleanup_map11_internal(state
, clean_addr
, cleanup_comm_canon_maps
,
123 cleanup_ext_prop_mask
& EXT_PROP_CANONICAL
);
124 if (cleanup_masq_domains
125 && (cleanup_masq_flags
& CLEANUP_MASQ_FLAG_ENV_FROM
))
126 cleanup_masquerade_internal(clean_addr
, cleanup_masq_domains
);
128 CLEANUP_OUT_BUF(state
, REC_TYPE_FROM
, clean_addr
);
129 if (state
->sender
) /* XXX Can't happen */
130 myfree(state
->sender
);
131 state
->sender
= mystrdup(STR(clean_addr
)); /* Used by Milter client */
132 if ((state
->flags
& CLEANUP_FLAG_BCC_OK
)
134 && cleanup_send_bcc_maps
135 && (bcc
= mail_addr_find(cleanup_send_bcc_maps
, STR(clean_addr
),
136 IGNORE_EXTENSION
)) != 0)
137 cleanup_addr_bcc(state
, bcc
);
138 vstring_free(clean_addr
);
141 /* cleanup_addr_recipient - process envelope recipient */
143 void cleanup_addr_recipient(CLEANUP_STATE
*state
, const char *buf
)
145 VSTRING
*clean_addr
= vstring_alloc(100);
149 * Note: an unqualified envelope address is for all practical purposes
150 * equivalent to a fully qualified local address, both for delivery and
151 * for replying. Having to support both forms is error prone, therefore
152 * an incomplete envelope address is rewritten to fully qualified form in
153 * the local domain context.
155 cleanup_rewrite_internal(MAIL_ATTR_RWR_LOCAL
,
156 clean_addr
, *buf
? buf
: var_empty_addr
);
157 if (state
->flags
& CLEANUP_FLAG_MAP_OK
) {
158 if (cleanup_rcpt_canon_maps
159 && (cleanup_rcpt_canon_flags
& CLEANUP_CANON_FLAG_ENV_RCPT
))
160 cleanup_map11_internal(state
, clean_addr
, cleanup_rcpt_canon_maps
,
161 cleanup_ext_prop_mask
& EXT_PROP_CANONICAL
);
162 if (cleanup_comm_canon_maps
163 && (cleanup_comm_canon_flags
& CLEANUP_CANON_FLAG_ENV_RCPT
))
164 cleanup_map11_internal(state
, clean_addr
, cleanup_comm_canon_maps
,
165 cleanup_ext_prop_mask
& EXT_PROP_CANONICAL
);
166 if (cleanup_masq_domains
167 && (cleanup_masq_flags
& CLEANUP_MASQ_FLAG_ENV_RCPT
))
168 cleanup_masquerade_internal(clean_addr
, cleanup_masq_domains
);
170 cleanup_out_recipient(state
, state
->dsn_orcpt
, state
->dsn_notify
,
171 state
->orig_rcpt
, STR(clean_addr
));
172 if (state
->recip
) /* This can happen */
173 myfree(state
->recip
);
174 state
->recip
= mystrdup(STR(clean_addr
)); /* Used by Milter client */
175 if ((state
->flags
& CLEANUP_FLAG_BCC_OK
)
177 && cleanup_rcpt_bcc_maps
178 && (bcc
= mail_addr_find(cleanup_rcpt_bcc_maps
, STR(clean_addr
),
179 IGNORE_EXTENSION
)) != 0)
180 cleanup_addr_bcc(state
, bcc
);
181 vstring_free(clean_addr
);
184 /* cleanup_addr_bcc - process automatic BCC recipient */
186 void cleanup_addr_bcc(CLEANUP_STATE
*state
, const char *bcc
)
188 VSTRING
*clean_addr
= vstring_alloc(100);
191 * Note: BCC addresses are supplied locally, and must be rewritten in the
192 * local address rewriting context.
194 #define NO_DSN_ORCPT ((char *) 0)
196 cleanup_rewrite_internal(MAIL_ATTR_RWR_LOCAL
, clean_addr
, bcc
);
197 if (state
->flags
& CLEANUP_FLAG_MAP_OK
) {
198 if (cleanup_rcpt_canon_maps
199 && (cleanup_rcpt_canon_flags
& CLEANUP_CANON_FLAG_ENV_RCPT
))
200 cleanup_map11_internal(state
, clean_addr
, cleanup_rcpt_canon_maps
,
201 cleanup_ext_prop_mask
& EXT_PROP_CANONICAL
);
202 if (cleanup_comm_canon_maps
203 && (cleanup_comm_canon_flags
& CLEANUP_CANON_FLAG_ENV_RCPT
))
204 cleanup_map11_internal(state
, clean_addr
, cleanup_comm_canon_maps
,
205 cleanup_ext_prop_mask
& EXT_PROP_CANONICAL
);
206 if (cleanup_masq_domains
207 && (cleanup_masq_flags
& CLEANUP_MASQ_FLAG_ENV_RCPT
))
208 cleanup_masquerade_internal(clean_addr
, cleanup_masq_domains
);
210 cleanup_out_recipient(state
, NO_DSN_ORCPT
, DSN_NOTIFY_NEVER
,
211 STR(clean_addr
), STR(clean_addr
));
212 vstring_free(clean_addr
);