Expand PMF_FN_* macros.
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / global / defer.c
blob85735350272e99adfeede1ca7aedfb4dc17d53e5
1 /* $NetBSD$ */
3 /*++
4 /* NAME
5 /* defer 3
6 /* SUMMARY
7 /* defer service client interface
8 /* SYNOPSIS
9 /* #include <defer.h>
11 /* int defer_append(flags, id, stats, rcpt, relay, dsn)
12 /* int flags;
13 /* const char *id;
14 /* MSG_STATS *stats;
15 /* RECIPIENT *rcpt;
16 /* const char *relay;
17 /* DSN *dsn;
19 /* int defer_flush(flags, queue, id, encoding, sender,
20 /* dsn_envid, dsn_ret)
21 /* int flags;
22 /* const char *queue;
23 /* const char *id;
24 /* const char *encoding;
25 /* const char *sender;
26 /* const char *dsn_envid;
27 /* int dsn_ret;
29 /* int defer_warn(flags, queue, id, sender, dsn_envid, dsn_ret)
30 /* int flags;
31 /* const char *queue;
32 /* const char *id;
33 /* const char *sender;
34 /* const char *dsn_envid;
35 /* int dsn_ret;
36 /* DESCRIPTION
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.
61 /* Arguments:
62 /* .IP flags
63 /* The bit-wise OR of zero or more of the following (specify
64 /* BOUNCE_FLAG_NONE to explicitly request not special processing):
65 /* .RS
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
78 /* mail.
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
82 /* mail.
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.
86 /* .RE
87 /* .IP queue
88 /* The message queue name of the original message file.
89 /* .IP id
90 /* The queue id of the original message file.
91 /* .IP stats
92 /* Time stamps from different message delivery stages
93 /* and session reuse count.
94 /* .IP rcpt
95 /* Recipient information. See recipient_list(3).
96 /* .IP relay
97 /* Host we could not talk to.
98 /* .IP dsn
99 /* Delivery status. See dsn(3). The specified action is ignored.
100 /* .IP encoding
101 /* The body content encoding: MAIL_ATTR_ENC_{7BIT,8BIT,NONE}.
102 /* .IP sender
103 /* The sender envelope address.
104 /* .IP dsn_envid
105 /* Optional DSN envelope ID.
106 /* .IP dsn_ret
107 /* Optional DSN return full/headers option.
108 /* .PP
109 /* For convenience, these functions always return a non-zero result.
110 /* DIAGNOSTICS
111 /* Warnings: problems connecting to the defer service.
112 /* Fatal: out of memory.
113 /* BUGS
114 /* Should be replaced by routines with an attribute-value based
115 /* interface instead of an interface that uses a rigid argument list.
116 /* LICENSE
117 /* .ad
118 /* .fi
119 /* The Secure Mailer license must be distributed with this software.
120 /* AUTHOR(S)
121 /* Wietse Venema
122 /* IBM T.J. Watson Research
123 /* P.O. Box 704
124 /* Yorktown Heights, NY 10598, USA
125 /*--*/
127 /* System library. */
129 #include <sys_defs.h>
130 #include <string.h>
132 /* Utility library. */
134 #include <msg.h>
135 #include <vstring.h>
137 /* Global library. */
139 #include <mail_params.h>
140 #include <mail_queue.h>
141 #include <mail_proto.h>
142 #include <flush_clnt.h>
143 #include <verify.h>
144 #include <dsn_util.h>
145 #include <rcpt_print.h>
146 #include <dsn_print.h>
147 #include <log_adhoc.h>
148 #include <trace.h>
149 #include <defer.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,
157 DSN *dsn)
159 const char *rcpt_domain;
160 DSN my_dsn = *dsn;
161 int status;
164 * Sanity check.
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
173 * service database.
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);
179 return (status);
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);
189 return (status);
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.
199 else {
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,
212 ATTR_TYPE_END) != 0)
213 msg_warn("%s: %s service failure", id, var_defer_service);
214 log_adhoc(id, stats, rcpt, relay, &my_dsn, "deferred");
217 * Traced delivery.
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)) {
230 case FLUSH_STAT_OK:
231 case FLUSH_STAT_DENY:
232 break;
233 default:
234 msg_warn("%s: %s service failure", id, var_flush_service);
235 break;
237 return (-1);
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) {
259 return (0);
260 } else {
261 return (-1);
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) {
280 return (0);
281 } else {
282 return (-1);