Expand PMF_FN_* macros.
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / global / trace.c
blobc13374ece5c58fdd837e4209d12a423a7b389474
1 /* $NetBSD$ */
3 /*++
4 /* NAME
5 /* trace 3
6 /* SUMMARY
7 /* user requested delivery tracing
8 /* SYNOPSIS
9 /* #include <trace.h>
11 /* int trace_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 trace_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;
28 /* DESCRIPTION
29 /* trace_append() updates the message delivery record that is
30 /* mailed back to the originator. In case of a trace-only
31 /* message, the recipient status is also written to the
32 /* mailer logfile.
34 /* trace_flush() returns the specified message to the specified
35 /* sender, including the message delivery record log that was built
36 /* with vtrace_append().
38 /* Arguments:
39 /* .IP flags
40 /* The bitwise OR of zero or more of the following (specify
41 /* BOUNCE_FLAG_NONE to request no special processing):
42 /* .RS
43 /* .IP BOUNCE_FLAG_CLEAN
44 /* Delete the logfile in case of an error (as in: pretend
45 /* that we never even tried to deliver this message).
46 /* .RE
47 /* .IP queue
48 /* The message queue name of the original message file.
49 /* .IP id
50 /* The message queue id.
51 /* .IP encoding
52 /* The body content encoding: MAIL_ATTR_ENC_{7BIT,8BIT,NONE}.
53 /* .IP sender
54 /* The sender envelope address.
55 /* .IP dsn_envid
56 /* Optional DSN envelope ID.
57 /* .IP dsn_ret
58 /* Optional DSN return full/headers option.
59 /* .IP stats
60 /* Time stamps from different message delivery stages
61 /* and session reuse count.
62 /* .IP rcpt
63 /* Recipient information. See recipient_list(3).
64 /* .IP relay
65 /* The host we sent the mail to.
66 /* .IP dsn
67 /* Delivery status information. See dsn(3).
68 /* DIAGNOSTICS
69 /* A non-zero result means the operation failed.
71 /* Fatal: out of memory.
72 /* BUGS
73 /* Should be replaced by routines with an attribute-value based
74 /* interface instead of an interface that uses a rigid argument list.
75 /* LICENSE
76 /* .ad
77 /* .fi
78 /* The Secure Mailer license must be distributed with this software.
79 /* AUTHOR(S)
80 /* Wietse Venema
81 /* IBM T.J. Watson Research
82 /* P.O. Box 704
83 /* Yorktown Heights, NY 10598, USA
84 /*--*/
86 /* System library. */
88 #include <sys_defs.h>
89 #include <stdio.h>
90 #include <string.h>
92 /* Utility library. */
94 #include <msg.h>
95 #include <vstring.h>
97 /* Global library. */
99 #include <mail_params.h>
100 #include <mail_proto.h>
101 #include <log_adhoc.h>
102 #include <rcpt_print.h>
103 #include <dsn_print.h>
104 #include <trace.h>
106 /* trace_append - append to message delivery record */
108 int trace_append(int flags, const char *id, MSG_STATS *stats,
109 RECIPIENT *rcpt, const char *relay,
110 DSN *dsn)
112 VSTRING *why = vstring_alloc(100);
113 DSN my_dsn = *dsn;
114 int req_stat;
117 * User-requested address verification, verbose delivery, or DSN SUCCESS
118 * notification.
120 if (strcmp(relay, NO_RELAY_AGENT) != 0)
121 vstring_sprintf(why, "delivery via %s: ", relay);
122 vstring_strcat(why, my_dsn.reason);
123 my_dsn.reason = vstring_str(why);
125 if (mail_command_client(MAIL_CLASS_PRIVATE, var_trace_service,
126 ATTR_TYPE_INT, MAIL_ATTR_NREQ, BOUNCE_CMD_APPEND,
127 ATTR_TYPE_INT, MAIL_ATTR_FLAGS, flags,
128 ATTR_TYPE_STR, MAIL_ATTR_QUEUEID, id,
129 ATTR_TYPE_FUNC, rcpt_print, (void *) rcpt,
130 ATTR_TYPE_FUNC, dsn_print, (void *) &my_dsn,
131 ATTR_TYPE_END) != 0) {
132 msg_warn("%s: %s service failure", id, var_trace_service);
133 req_stat = -1;
134 } else {
135 if (flags & DEL_REQ_FLAG_USR_VRFY)
136 log_adhoc(id, stats, rcpt, relay, dsn, my_dsn.action);
137 req_stat = 0;
139 vstring_free(why);
140 return (req_stat);
143 /* trace_flush - deliver delivery record to the sender */
145 int trace_flush(int flags, const char *queue, const char *id,
146 const char *encoding, const char *sender,
147 const char *dsn_envid, int dsn_ret)
149 if (mail_command_client(MAIL_CLASS_PRIVATE, var_trace_service,
150 ATTR_TYPE_INT, MAIL_ATTR_NREQ, BOUNCE_CMD_TRACE,
151 ATTR_TYPE_INT, MAIL_ATTR_FLAGS, flags,
152 ATTR_TYPE_STR, MAIL_ATTR_QUEUE, queue,
153 ATTR_TYPE_STR, MAIL_ATTR_QUEUEID, id,
154 ATTR_TYPE_STR, MAIL_ATTR_ENCODING, encoding,
155 ATTR_TYPE_STR, MAIL_ATTR_SENDER, sender,
156 ATTR_TYPE_STR, MAIL_ATTR_DSN_ENVID, dsn_envid,
157 ATTR_TYPE_INT, MAIL_ATTR_DSN_RET, dsn_ret,
158 ATTR_TYPE_END) == 0) {
159 return (0);
160 } else {
161 return (-1);