Postfix3.3.1
sent.c
[詳解]
1 /*++
2 /* NAME
3 /* sent 3
4 /* SUMMARY
5 /* log that a message was or could be sent
6 /* SYNOPSIS
7 /* #include <sent.h>
8 /*
9 /* int sent(flags, queue_id, stats, recipient, relay, dsn)
10 /* int flags;
11 /* const char *queue_id;
12 /* MSG_STATS *stats;
13 /* RECIPIENT *recipient;
14 /* const char *relay;
15 /* DSN *dsn;
16 /* DESCRIPTION
17 /* sent() logs that a message was successfully delivered,
18 /* updates the address verification service, or updates a
19 /* message delivery record on request by the sender. The
20 /* flags argument determines the action.
21 /*
22 /* Arguments:
23 /* .IP flags
24 /* Zero or more of the following:
25 /* .RS
26 /* .IP SENT_FLAG_NONE
27 /* The message is a normal delivery request.
28 /* .IP DEL_REQ_FLAG_MTA_VRFY
29 /* The message is an MTA-requested address verification probe.
30 /* Update the address verification database.
31 /* .IP DEL_REQ_FLAG_USR_VRFY
32 /* The message is a user-requested address expansion probe.
33 /* Update the message delivery record.
34 /* .IP DEL_REQ_FLAG_RECORD
35 /* .IP DEL_REQ_FLAG_REC_SENT
36 /* This is a normal message with logged delivery. Update the
37 /* the message delivery record.
38 /* .RE .IP queue_id
39 /* The message queue id.
40 /* .IP stats
41 /* Time stamps from different message delivery stages
42 /* and session reuse count.
43 /* .IP recipient
44 /* Recipient information. See recipient_list(3).
45 /* .IP relay
46 /* Name of the host we're talking to.
47 /* .IP dsn
48 /* Delivery status. See dsn(3). The action is ignored in case
49 /* of a probe message. Otherwise, "delivered" is assumed when
50 /* no action is specified.
51 /* DIAGNOSTICS
52 /* A non-zero result means the operation failed.
53 /*
54 /* Fatal: out of memory.
55 /* BUGS
56 /* Should be replaced by routines with an attribute-value based
57 /* interface instead of an interface that uses a rigid argument list.
58 /* LICENSE
59 /* .ad
60 /* .fi
61 /* The Secure Mailer license must be distributed with this software.
62 /* AUTHOR(S)
63 /* Wietse Venema
64 /* IBM T.J. Watson Research
65 /* P.O. Box 704
66 /* Yorktown Heights, NY 10598, USA
67 /*--*/
68 
69 /* System library. */
70 
71 #include <sys_defs.h>
72 #include <string.h>
73 
74 /* Utility library. */
75 
76 #include <msg.h>
77 #include <vstring.h>
78 
79 /* Global library. */
80 
81 #define DSN_INTERN
82 #include <mail_params.h>
83 #include <verify.h>
84 #include <log_adhoc.h>
85 #include <trace.h>
86 #include <defer.h>
87 #include <sent.h>
88 #include <dsn_util.h>
89 #include <dsn_mask.h>
90 
91 /* Application-specific. */
92 
93 /* sent - log that a message was or could be sent */
94 
95 int sent(int flags, const char *id, MSG_STATS *stats,
96  RECIPIENT *recipient, const char *relay,
97  DSN *dsn)
98 {
99  DSN my_dsn = *dsn;
100  DSN *dsn_res;
101  int status;
102 
103  /*
104  * Sanity check.
105  */
106  if (my_dsn.status[0] != '2' || !dsn_valid(my_dsn.status)) {
107  msg_warn("sent: ignoring dsn code \"%s\"", my_dsn.status);
108  my_dsn.status = "2.0.0";
109  }
110 
111  /*
112  * DSN filter (Postfix 3.0).
113  */
114  if (delivery_status_filter != 0
115  && (dsn_res = dsn_filter_lookup(delivery_status_filter, &my_dsn)) != 0)
116  my_dsn = *dsn_res;
117 
118  /*
119  * MTA-requested address verification information is stored in the verify
120  * service database.
121  */
122  if (flags & DEL_REQ_FLAG_MTA_VRFY) {
123  my_dsn.action = "deliverable";
124  status = verify_append(id, stats, recipient, relay, &my_dsn,
126  return (status);
127  }
128 
129  /*
130  * User-requested address verification information is logged and mailed
131  * to the requesting user.
132  */
133  if (flags & DEL_REQ_FLAG_USR_VRFY) {
134  my_dsn.action = "deliverable";
135  status = trace_append(flags, id, stats, recipient, relay, &my_dsn);
136  return (status);
137  }
138 
139  /*
140  * Normal mail delivery. May also send a delivery record to the user.
141  */
142  else {
143 
144  /* Readability macros: record all deliveries, or the delayed ones. */
145 #define REC_ALL_SENT(flags) (flags & DEL_REQ_FLAG_RECORD)
146 #define REC_DLY_SENT(flags, rcpt) \
147  ((flags & DEL_REQ_FLAG_REC_DLY_SENT) \
148  && (rcpt->dsn_notify == 0 || (rcpt->dsn_notify & DSN_NOTIFY_DELAY)))
149 
150  if (my_dsn.action == 0 || my_dsn.action[0] == 0)
151  my_dsn.action = "delivered";
152 
153  if (((REC_ALL_SENT(flags) == 0 && REC_DLY_SENT(flags, recipient) == 0)
154  || trace_append(flags, id, stats, recipient, relay, &my_dsn) == 0)
155  && ((recipient->dsn_notify & DSN_NOTIFY_SUCCESS) == 0
156  || trace_append(flags, id, stats, recipient, relay, &my_dsn) == 0)) {
157  log_adhoc(id, stats, recipient, relay, &my_dsn, "sent");
158  status = 0;
159  } else {
160  VSTRING *junk = vstring_alloc(100);
161 
162  vstring_sprintf(junk, "%s: %s service failed",
163  id, var_trace_service);
164  my_dsn.reason = vstring_str(junk);
165  my_dsn.status = "4.3.0";
166  status = defer_append(flags, id, stats, recipient, relay, &my_dsn);
167  vstring_free(junk);
168  }
169  return (status);
170  }
171 }
DSN_FILTER * delivery_status_filter
Definition: bounce.c:218
size_t dsn_valid(const char *text)
Definition: dsn_util.c:112
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 DEL_REQ_FLAG_USR_VRFY
#define REC_DLY_SENT(flags, rcpt)
#define REC_ALL_SENT(flags)
int verify_append(const char *queue_id, MSG_STATS *stats, RECIPIENT *recipient, const char *relay, DSN *dsn, int vrfy_stat)
Definition: verify.c:92
char * var_trace_service
Definition: mail_params.c:311
void msg_warn(const char *fmt,...)
Definition: msg.c:215
VSTRING * vstring_alloc(ssize_t len)
Definition: vstring.c:353
VSTRING * vstring_sprintf(VSTRING *vp, const char *format,...)
Definition: vstring.c:602
void log_adhoc(const char *id, MSG_STATS *stats, RECIPIENT *recipient, const char *relay, DSN *dsn, const char *status)
Definition: log_adhoc.c:82
const char * status
Definition: dsn.h:18
#define DSN_NOTIFY_SUCCESS
Definition: dsn_mask.h:44
Definition: dsn.h:17
VSTRING * vstring_free(VSTRING *vp)
Definition: vstring.c:380
int defer_append(int flags, const char *id, MSG_STATS *stats, RECIPIENT *rcpt, const char *relay, DSN *dsn)
Definition: defer.c:187
int sent(int flags, const char *id, MSG_STATS *stats, RECIPIENT *recipient, const char *relay, DSN *dsn)
Definition: sent.c:95
#define DEL_RCPT_STAT_OK
#define DEL_REQ_FLAG_MTA_VRFY
DSN * dsn_filter_lookup(DSN_FILTER *fp, DSN *dsn)
Definition: dsn_filter.c:123