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
|
/*++
/* NAME
/* defer 3
/* SUMMARY
/* defer service client interface
/* SYNOPSIS
/* #include <defer.h>
/*
/* int defer_append(flags, id, recipient, relay, entry, format, ...)
/* int flags;
/* const char *id;
/* const char *recipient;
/* const char *relay;
/* time_t entry;
/* const char *format;
/*
/* int vdefer_append(flags, id, recipient, relay, entry, format, ap)
/* int flags;
/* const char *id;
/* const char *recipient;
/* const char *relay;
/* time_t entry;
/* const char *format;
/* va_list ap;
/*
/* int defer_flush(flags, queue, id, sender)
/* int flags;
/* const char *queue;
/* const char *id;
/* 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.
/*
/* 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).
/* .IP BOUNCE_FLAG_COPY
/* Request that postmaster a copy is sent (defer_flush() only).
/* .RE
/* .IP queue
/* The message queue name of the original message file.
/* .IP id
/* The queue id of the original message file.
/* .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 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>
/* Utility library. */
#include <msg.h>
#include <vstring.h>
/* Global library. */
#include "mail_queue.h"
#include "mail_proto.h"
#include "bounce.h"
#include "defer.h"
/* defer_append - defer message delivery */
int defer_append(int flags, const char *id, 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, 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 *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;
vstring_vsprintf(why, fmt, ap);
if (mail_command_write(MAIL_CLASS_PRIVATE, MAIL_SERVICE_DEFER,
"%d %d %s %s %s", BOUNCE_CMD_APPEND,
flags, id, recipient, vstring_str(why)) != 0)
msg_warn("%s: defer service failure", id);
msg_info("%s: to=<%s>, relay=%s, delay=%d, status=deferred (%s)",
id, recipient, relay, delay, vstring_str(why));
vstring_free(why);
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 *sender)
{
if (mail_command_write(MAIL_CLASS_PRIVATE, MAIL_SERVICE_DEFER,
"%d %d %s %s %s", BOUNCE_CMD_FLUSH,
flags, queue, id, sender) == 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_write(MAIL_CLASS_PRIVATE, MAIL_SERVICE_DEFER,
"%d %d %s %s %s", BOUNCE_CMD_WARN,
flags, queue, id, sender) == 0) {
return (0);
} else {
return (-1);
}
}
|