7 /* defer service client interface
11 /* int defer_append(flags, id, stats, rcpt, relay, dsn)
19 /* int defer_flush(flags, queue, id, encoding, sender,
20 /* dsn_envid, dsn_ret)
24 /* const char *encoding;
25 /* const char *sender;
26 /* const char *dsn_envid;
29 /* int defer_warn(flags, queue, id, sender, dsn_envid, dsn_ret)
33 /* const char *sender;
34 /* const char *dsn_envid;
37 /* This module implements a client interface to the defer service,
38 /* which maintains a per-message logfile with status records for
39 /* each recipient whose delivery is deferred, and the dsn_text why.
41 /* defer_append() appends a record to the per-message defer log,
42 /* with the dsn_text for delayed delivery to the named rcpt,
43 /* updates the address verification service, or updates a message
44 /* delivery record on request by the sender. The flags argument
45 /* determines the action.
46 /* The result is a convenient non-zero value.
47 /* When the fast flush cache is enabled, the fast flush server is
48 /* notified of deferred mail.
50 /* defer_flush() bounces the specified message to the specified
51 /* sender, including the defer log that was built with defer_append().
52 /* defer_flush() requests that the deferred recipients are deleted
53 /* from the original queue file; the defer logfile is deleted after
54 /* successful completion.
55 /* The result is zero in case of success, non-zero otherwise.
57 /* defer_warn() sends a warning message that the mail in
58 /* question has been deferred. The defer log is not deleted,
59 /* and no recipients are deleted from the original queue file.
63 /* The bit-wise OR of zero or more of the following (specify
64 /* BOUNCE_FLAG_NONE to explicitly request not special processing):
66 /* .IP BOUNCE_FLAG_CLEAN
67 /* Delete the defer log in case of an error (as in: pretend
68 /* that we never even tried to defer this message).
69 /* .IP BOUNCE_FLAG_DELRCPT
70 /* When specified with a flush request, request that
71 /* recipients be deleted from the queue file.
73 /* Note: the bounce daemon ignores this request when the
74 /* recipient queue file offset is <= 0.
75 /* .IP DEL_REQ_FLAG_MTA_VRFY
76 /* The message is an MTA-requested address verification probe.
77 /* Update the address verification database instead of deferring
79 /* .IP DEL_REQ_FLAG_USR_VRFY
80 /* The message is a user-requested address expansion probe.
81 /* Update the message delivery record instead of deferring
83 /* .IP DEL_REQ_FLAG_RECORD
84 /* This is a normal message with logged delivery. Update the
85 /* message delivery record and defer mail delivery.
88 /* The message queue name of the original message file.
90 /* The queue id of the original message file.
92 /* Time stamps from different message delivery stages
93 /* and session reuse count.
95 /* Recipient information. See recipient_list(3).
97 /* Host we could not talk to.
99 /* Delivery status. See dsn(3). The specified action is ignored.
101 /* The body content encoding: MAIL_ATTR_ENC_{7BIT,8BIT,NONE}.
103 /* The sender envelope address.
105 /* Optional DSN envelope ID.
107 /* Optional DSN return full/headers option.
109 /* For convenience, these functions always return a non-zero result.
111 /* Warnings: problems connecting to the defer service.
112 /* Fatal: out of memory.
114 /* Should be replaced by routines with an attribute-value based
115 /* interface instead of an interface that uses a rigid argument list.
119 /* The Secure Mailer license must be distributed with this software.
122 /* IBM T.J. Watson Research
124 /* Yorktown Heights, NY 10598, USA
127 /* System library. */
129 #include <sys_defs.h>
132 /* Utility library. */
137 /* Global library. */
139 #include <mail_params.h>
140 #include <mail_queue.h>
141 #include <mail_proto.h>
142 #include <flush_clnt.h>
144 #include <dsn_util.h>
145 #include <rcpt_print.h>
146 #include <dsn_print.h>
147 #include <log_adhoc.h>
151 #define STR(x) vstring_str(x)
153 /* defer_append - defer message delivery */
155 int defer_append(int flags
, const char *id
, MSG_STATS
*stats
,
156 RECIPIENT
*rcpt
, const char *relay
,
159 const char *rcpt_domain
;
166 if (my_dsn
.status
[0] != '4' || !dsn_valid(my_dsn
.status
)) {
167 msg_warn("defer_append: ignoring dsn code \"%s\"", my_dsn
.status
);
168 my_dsn
.status
= "4.0.0";
172 * MTA-requested address verification information is stored in the verify
175 if (flags
& DEL_REQ_FLAG_MTA_VRFY
) {
176 my_dsn
.action
= "undeliverable";
177 status
= verify_append(id
, stats
, rcpt
, relay
, &my_dsn
,
178 DEL_RCPT_STAT_DEFER
);
183 * User-requested address verification information is logged and mailed
184 * to the requesting user.
186 if (flags
& DEL_REQ_FLAG_USR_VRFY
) {
187 my_dsn
.action
= "undeliverable";
188 status
= trace_append(flags
, id
, stats
, rcpt
, relay
, &my_dsn
);
193 * Normal mail delivery. May also send a delivery record to the user.
195 * XXX DSN We write all deferred recipients to the defer logfile regardless
196 * of DSN NOTIFY options, because those options don't apply to mailq(1)
197 * reports or to postmaster notifications.
202 * Supply default action.
204 my_dsn
.action
= "delayed";
206 if (mail_command_client(MAIL_CLASS_PRIVATE
, var_defer_service
,
207 ATTR_TYPE_INT
, MAIL_ATTR_NREQ
, BOUNCE_CMD_APPEND
,
208 ATTR_TYPE_INT
, MAIL_ATTR_FLAGS
, flags
,
209 ATTR_TYPE_STR
, MAIL_ATTR_QUEUEID
, id
,
210 ATTR_TYPE_FUNC
, rcpt_print
, (void *) rcpt
,
211 ATTR_TYPE_FUNC
, dsn_print
, (void *) &my_dsn
,
213 msg_warn("%s: %s service failure", id
, var_defer_service
);
214 log_adhoc(id
, stats
, rcpt
, relay
, &my_dsn
, "deferred");
219 if (flags
& DEL_REQ_FLAG_RECORD
)
220 if (trace_append(flags
, id
, stats
, rcpt
, relay
, &my_dsn
) != 0)
221 msg_warn("%s: %s service failure", id
, var_trace_service
);
224 * Notify the fast flush service. XXX Should not this belong in the
225 * bounce/defer daemon? Well, doing it here is more robust.
227 if ((rcpt_domain
= strrchr(rcpt
->address
, '@')) != 0
228 && *++rcpt_domain
!= 0)
229 switch (flush_add(rcpt_domain
, id
)) {
231 case FLUSH_STAT_DENY
:
234 msg_warn("%s: %s service failure", id
, var_flush_service
);
241 /* defer_flush - flush the defer log and deliver to the sender */
243 int defer_flush(int flags
, const char *queue
, const char *id
,
244 const char *encoding
, const char *sender
,
245 const char *dsn_envid
, int dsn_ret
)
247 flags
|= BOUNCE_FLAG_DELRCPT
;
249 if (mail_command_client(MAIL_CLASS_PRIVATE
, var_defer_service
,
250 ATTR_TYPE_INT
, MAIL_ATTR_NREQ
, BOUNCE_CMD_FLUSH
,
251 ATTR_TYPE_INT
, MAIL_ATTR_FLAGS
, flags
,
252 ATTR_TYPE_STR
, MAIL_ATTR_QUEUE
, queue
,
253 ATTR_TYPE_STR
, MAIL_ATTR_QUEUEID
, id
,
254 ATTR_TYPE_STR
, MAIL_ATTR_ENCODING
, encoding
,
255 ATTR_TYPE_STR
, MAIL_ATTR_SENDER
, sender
,
256 ATTR_TYPE_STR
, MAIL_ATTR_DSN_ENVID
, dsn_envid
,
257 ATTR_TYPE_INT
, MAIL_ATTR_DSN_RET
, dsn_ret
,
258 ATTR_TYPE_END
) == 0) {
265 /* defer_warn - send a copy of the defer log to the sender as a warning bounce
266 * do not flush the log */
268 int defer_warn(int flags
, const char *queue
, const char *id
,
269 const char *sender
, const char *envid
, int dsn_ret
)
271 if (mail_command_client(MAIL_CLASS_PRIVATE
, var_defer_service
,
272 ATTR_TYPE_INT
, MAIL_ATTR_NREQ
, BOUNCE_CMD_WARN
,
273 ATTR_TYPE_INT
, MAIL_ATTR_FLAGS
, flags
,
274 ATTR_TYPE_STR
, MAIL_ATTR_QUEUE
, queue
,
275 ATTR_TYPE_STR
, MAIL_ATTR_QUEUEID
, id
,
276 ATTR_TYPE_STR
, MAIL_ATTR_SENDER
, sender
,
277 ATTR_TYPE_STR
, MAIL_ATTR_DSN_ENVID
, envid
,
278 ATTR_TYPE_INT
, MAIL_ATTR_DSN_RET
, dsn_ret
,
279 ATTR_TYPE_END
) == 0) {