Postfix3.3.1
trace.c
[詳解]
1 /*++
2 /* NAME
3 /* trace 3
4 /* SUMMARY
5 /* user requested delivery tracing
6 /* SYNOPSIS
7 /* #include <trace.h>
8 /*
9 /* int trace_append(flags, id, stats, rcpt, relay, dsn)
10 /* int flags;
11 /* const char *id;
12 /* MSG_STATS *stats;
13 /* RECIPIENT *rcpt;
14 /* const char *relay;
15 /* DSN *dsn;
16 /*
17 /* int trace_flush(flags, queue, id, encoding, sender,
18 /* dsn_envid, dsn_ret)
19 /* int flags;
20 /* const char *queue;
21 /* const char *id;
22 /* const char *encoding;
23 /* const char *sender;
24 /* const char *dsn_envid;
25 /* int dsn_ret;
26 /* DESCRIPTION
27 /* trace_append() updates the message delivery record that is
28 /* mailed back to the originator. In case of a trace-only
29 /* message, the recipient status is also written to the
30 /* mailer logfile.
31 /*
32 /* trace_flush() returns the specified message to the specified
33 /* sender, including the message delivery record log that was built
34 /* with vtrace_append().
35 /*
36 /* Arguments:
37 /* .IP flags
38 /* The bitwise OR of zero or more of the following (specify
39 /* BOUNCE_FLAG_NONE to request no special processing):
40 /* .RS
41 /* .IP BOUNCE_FLAG_CLEAN
42 /* Delete the logfile in case of an error (as in: pretend
43 /* that we never even tried to deliver this message).
44 /* .RE
45 /* .IP queue
46 /* The message queue name of the original message file.
47 /* .IP id
48 /* The message queue id.
49 /* .IP encoding
50 /* The body content encoding: MAIL_ATTR_ENC_{7BIT,8BIT,NONE}.
51 /* .IP sender
52 /* The sender envelope address.
53 /* .IP dsn_envid
54 /* Optional DSN envelope ID.
55 /* .IP dsn_ret
56 /* Optional DSN return full/headers option.
57 /* .IP stats
58 /* Time stamps from different message delivery stages
59 /* and session reuse count.
60 /* .IP rcpt
61 /* Recipient information. See recipient_list(3).
62 /* .IP relay
63 /* The host we sent the mail to.
64 /* .IP dsn
65 /* Delivery status information. See dsn(3).
66 /* DIAGNOSTICS
67 /* A non-zero result means the operation failed.
68 /*
69 /* Fatal: out of memory.
70 /* BUGS
71 /* Should be replaced by routines with an attribute-value based
72 /* interface instead of an interface that uses a rigid argument list.
73 /* LICENSE
74 /* .ad
75 /* .fi
76 /* The Secure Mailer license must be distributed with this software.
77 /* AUTHOR(S)
78 /* Wietse Venema
79 /* IBM T.J. Watson Research
80 /* P.O. Box 704
81 /* Yorktown Heights, NY 10598, USA
82 /*--*/
83 
84 /* System library. */
85 
86 #include <sys_defs.h>
87 #include <stdio.h>
88 #include <string.h>
89 
90 /* Utility library. */
91 
92 #include <msg.h>
93 #include <vstring.h>
94 
95 /* Global library. */
96 
97 #include <mail_params.h>
98 #include <mail_proto.h>
99 #include <log_adhoc.h>
100 #include <rcpt_print.h>
101 #include <dsn_print.h>
102 #include <trace.h>
103 
104 /* trace_append - append to message delivery record */
105 
106 int trace_append(int flags, const char *id, MSG_STATS *stats,
107  RECIPIENT *rcpt, const char *relay,
108  DSN *dsn)
109 {
110  VSTRING *why = vstring_alloc(100);
111  DSN my_dsn = *dsn;
112  int req_stat;
113 
114  /*
115  * User-requested address verification, verbose delivery, or DSN SUCCESS
116  * notification.
117  */
118  if (strcmp(relay, NO_RELAY_AGENT) != 0)
119  vstring_sprintf(why, "delivery via %s: ", relay);
120  vstring_strcat(why, my_dsn.reason);
121  my_dsn.reason = vstring_str(why);
122 
127  SEND_ATTR_FUNC(rcpt_print, (void *) rcpt),
128  SEND_ATTR_FUNC(dsn_print, (void *) &my_dsn),
129  ATTR_TYPE_END) != 0) {
130  msg_warn("%s: %s service failure", id, var_trace_service);
131  req_stat = -1;
132  } else {
133  if (flags & DEL_REQ_FLAG_USR_VRFY)
134  log_adhoc(id, stats, rcpt, relay, dsn, my_dsn.action);
135  req_stat = 0;
136  }
137  vstring_free(why);
138  return (req_stat);
139 }
140 
141 /* trace_flush - deliver delivery record to the sender */
142 
143 int trace_flush(int flags, const char *queue, const char *id,
144  const char *encoding, const char *sender,
145  const char *dsn_envid, int dsn_ret)
146 {
156  ATTR_TYPE_END) == 0) {
157  return (0);
158  } else {
159  return (-1);
160  }
161 }
int dsn_print(ATTR_PRINT_MASTER_FN print_fn, VSTREAM *fp, int flags, void *ptr)
Definition: dsn_print.c:48
#define MAIL_ATTR_ENCODING
Definition: mail_proto.h:202
const char * action
Definition: dsn.h:19
const char * reason
Definition: dsn.h:20
#define vstring_str(vp)
Definition: vstring.h:71
int trace_append(int flags, const char *id, MSG_STATS *stats, RECIPIENT *rcpt, const char *relay, DSN *dsn)
Definition: trace.c:106
#define BOUNCE_CMD_TRACE
Definition: bounce.h:48
#define ATTR_TYPE_END
Definition: attr.h:39
#define DEL_REQ_FLAG_USR_VRFY
#define NO_RELAY_AGENT
Definition: bounce.h:54
#define BOUNCE_CMD_APPEND
Definition: bounce.h:43
#define MAIL_ATTR_QUEUE
Definition: mail_proto.h:129
#define MAIL_ATTR_NREQ
Definition: mail_proto.h:125
char * var_trace_service
Definition: mail_params.c:311
int trace_flush(int flags, const char *queue, const char *id, const char *encoding, const char *sender, const char *dsn_envid, int dsn_ret)
Definition: trace.c:143
void msg_warn(const char *fmt,...)
Definition: msg.c:215
VSTRING * vstring_alloc(ssize_t len)
Definition: vstring.c:353
#define MAIL_ATTR_DSN_RET
Definition: mail_proto.h:274
VSTRING * vstring_sprintf(VSTRING *vp, const char *format,...)
Definition: vstring.c:602
int mail_command_client(const char *class, const char *name,...)
#define MAIL_ATTR_DSN_ENVID
Definition: mail_proto.h:273
#define SEND_ATTR_INT(name, val)
Definition: attr.h:63
void log_adhoc(const char *id, MSG_STATS *stats, RECIPIENT *recipient, const char *relay, DSN *dsn, const char *status)
Definition: log_adhoc.c:82
#define SEND_ATTR_FUNC(func, val)
Definition: attr.h:69
Definition: dsn.h:17
VSTRING * vstring_free(VSTRING *vp)
Definition: vstring.c:380
#define MAIL_ATTR_SENDER
Definition: mail_proto.h:131
int rcpt_print(ATTR_PRINT_MASTER_FN print_fn, VSTREAM *fp, int flags, void *ptr)
Definition: rcpt_print.c:51
#define MAIL_ATTR_QUEUEID
Definition: mail_proto.h:130
#define SEND_ATTR_STR(name, val)
Definition: attr.h:64
#define MAIL_ATTR_FLAGS
Definition: mail_proto.h:128
#define MAIL_CLASS_PRIVATE
Definition: mail_proto.h:96
VSTRING * vstring_strcat(VSTRING *vp, const char *src)
Definition: vstring.c:459