1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
/*++
/* NAME
/* defer 3
/* SUMMARY
/* defer service client interface
/* SYNOPSIS
/* #include <defer.h>
/*
/* int defer_append(flags, id, orig_rcpt, recipient, relay,
/* entry, format, ...)
/* int flags;
/* const char *id;
/* const char *orig_rcpt;
/* const char *recipient;
/* const char *relay;
/* time_t entry;
/* const char *format;
/*
/* int vdefer_append(flags, id, orig_rcpt, recipient, relay,
/* entry, format, ap)
/* int flags;
/* const char *id;
/* const char *orig_rcpt;
/* const char *recipient;
/* const char *relay;
/* time_t entry;
/* const char *format;
/* va_list ap;
/*
/* int defer_flush(flags, queue, id, encoding, sender)
/* int flags;
/* const char *queue;
/* const char *id;
/* const char *encoding;
/* const char *sender;
/*
/* int defer_warn(flags, queue, id, sender)
/* int flags;
/* const char *queue;
/* const char *id;
/* const char *sender;
/* DESCRIPTION
/* This module implements a client interface to the defer service,
/* which maintains a per-message logfile with status records for
/* each recipient whose delivery is deferred, and the reason why.
/*
/* defer_append() appends a record to the per-message defer log,
/* with the reason for delayed delivery to the named recipient.
/* The result is a convenient non-zero value.
/* When the fast flush cache is enabled, the fast flush server is
/* notified of deferred mail.
/*
/* vdefer_append() implements an alternative client interface.
/*
/* defer_flush() bounces the specified message to the specified
/* sender, including the defer log that was built with defer_append().
/* The result is zero in case of success, non-zero otherwise.
/*
/* defer_warn() sends a warning message that the mail in question has
/* been deferred. It does not flush the log.
/*
/* Arguments:
/* .IP flags
/* The bit-wise OR of zero or more of the following (specify
/* BOUNCE_FLAG_NONE to explicitly request not special processing):
/* .RS
/* .IP BOUNCE_FLAG_CLEAN
/* Delete the defer log in case of an error (as in: pretend
/* that we never even tried to defer this message).
/* .RE
/* .IP queue
/* The message queue name of the original message file.
/* .IP id
/* The queue id of the original message file.
/* .IP orig_rcpt
/* The original envelope recipient address. If unavailable,
/* specify a null string or null pointer.
/* .IP recipient
/* A recipient address that is being deferred. The domain part
/* of the address is marked dead (for a limited amount of time).
/* .IP encoding
/* The body content encoding: MAIL_ATTR_ENC_{7BIT,8BIT,NONE}.
/* .IP sender
/* The sender envelope address.
/* .IP relay
/* Host we could not talk to.
/* .IP entry
/* Message arrival time.
/* .IP format
/* The reason for non-delivery.
/* .IP ap
/* Variable-length argument list.
/* .PP
/* For convenience, these functions always return a non-zero result.
/* DIAGNOSTICS
/* Warnings: problems connecting to the defer service.
/* Fatal: out of memory.
/* BUGS
/* Should be replaced by routines with an attribute-value based
/* interface instead of an interface that uses a rigid argument list.
/* LICENSE
/* .ad
/* .fi
/* The Secure Mailer license must be distributed with this software.
/* AUTHOR(S)
/* Wietse Venema
/* IBM T.J. Watson Research
/* P.O. Box 704
/* Yorktown Heights, NY 10598, USA
/*--*/
/* System library. */
#include <sys_defs.h>
#include <stdlib.h> /* 44BSD stdarg.h uses abort() */
#include <stdarg.h>
#include <string.h>
#ifdef STRCASECMP_IN_STRINGS_H
#include <strings.h>
#endif
/* Utility library. */
#include <msg.h>
#include <vstring.h>
/* Global library. */
#include "mail_params.h"
#include "mail_queue.h"
#include "mail_proto.h"
#include "flush_clnt.h"
#include "bounce.h"
#include "defer.h"
#define STR(x) vstring_str(x)
/* defer_append - defer message delivery */
int defer_append(int flags, const char *id, const char *orig_rcpt,
const char *recipient, const char *relay,
time_t entry, const char *fmt,...)
{
va_list ap;
int status;
va_start(ap, fmt);
status = vdefer_append(flags, id, orig_rcpt, recipient,
relay, entry, fmt, ap);
va_end(ap);
return (status);
}
/* vdefer_append - defer delivery of queue file */
int vdefer_append(int flags, const char *id, const char *orig_rcpt,
const char *recipient, const char *relay,
time_t entry, const char *fmt, va_list ap)
{
VSTRING *why = vstring_alloc(100);
int delay = time((time_t *) 0) - entry;
const char *rcpt_domain;
vstring_vsprintf(why, fmt, ap);
if (orig_rcpt == 0)
orig_rcpt = "";
if (mail_command_client(MAIL_CLASS_PRIVATE, var_defer_service,
ATTR_TYPE_NUM, MAIL_ATTR_NREQ, BOUNCE_CMD_APPEND,
ATTR_TYPE_NUM, MAIL_ATTR_FLAGS, flags,
ATTR_TYPE_STR, MAIL_ATTR_QUEUEID, id,
ATTR_TYPE_STR, MAIL_ATTR_ORCPT, orig_rcpt,
ATTR_TYPE_STR, MAIL_ATTR_RECIP, recipient,
ATTR_TYPE_STR, MAIL_ATTR_WHY, vstring_str(why),
ATTR_TYPE_END) != 0)
msg_warn("%s: defer service failure", id);
if (*orig_rcpt && strcasecmp(recipient, orig_rcpt) != 0)
msg_info("%s: to=<%s>, orig_to=<%s>, relay=%s, delay=%d, status=deferred (%s)",
id, recipient, orig_rcpt, relay, delay, vstring_str(why));
else
msg_info("%s: to=<%s>, relay=%s, delay=%d, status=deferred (%s)",
id, recipient, relay, delay, vstring_str(why));
vstring_free(why);
/*
* Notify the fast flush service. XXX Should not this belong in the
* bounce/defer daemon? Well, doing it here is more robust.
*/
if ((rcpt_domain = strrchr(recipient, '@')) != 0 && *++rcpt_domain != 0)
switch (flush_add(rcpt_domain, id)) {
case FLUSH_STAT_OK:
case FLUSH_STAT_DENY:
break;
default:
msg_warn("unable to talk to fast flush service");
break;
}
return (-1);
}
/* defer_flush - flush the defer log and deliver to the sender */
int defer_flush(int flags, const char *queue, const char *id,
const char *encoding, const char *sender)
{
if (mail_command_client(MAIL_CLASS_PRIVATE, var_defer_service,
ATTR_TYPE_NUM, MAIL_ATTR_NREQ, BOUNCE_CMD_FLUSH,
ATTR_TYPE_NUM, MAIL_ATTR_FLAGS, flags,
ATTR_TYPE_STR, MAIL_ATTR_QUEUE, queue,
ATTR_TYPE_STR, MAIL_ATTR_QUEUEID, id,
ATTR_TYPE_STR, MAIL_ATTR_ENCODING, encoding,
ATTR_TYPE_STR, MAIL_ATTR_SENDER, sender,
ATTR_TYPE_END) == 0) {
return (0);
} else {
return (-1);
}
}
/* defer_warn - send a copy of the defer log to the sender as a warning bounce
* do not flush the log */
int defer_warn(int flags, const char *queue, const char *id,
const char *sender)
{
if (mail_command_client(MAIL_CLASS_PRIVATE, var_defer_service,
ATTR_TYPE_NUM, MAIL_ATTR_NREQ, BOUNCE_CMD_WARN,
ATTR_TYPE_NUM, MAIL_ATTR_FLAGS, flags,
ATTR_TYPE_STR, MAIL_ATTR_QUEUE, queue,
ATTR_TYPE_STR, MAIL_ATTR_QUEUEID, id,
ATTR_TYPE_STR, MAIL_ATTR_SENDER, sender,
ATTR_TYPE_END) == 0) {
return (0);
} else {
return (-1);
}
}
|