bounce_notify_verp.c [plain text]
#include <sys_defs.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <ctype.h>
#ifdef STRCASECMP_IN_STRINGS_H
#include <strings.h>
#endif
#include <msg.h>
#include <vstream.h>
#include <name_mask.h>
#include <mail_params.h>
#include <mail_queue.h>
#include <post_mail.h>
#include <mail_addr.h>
#include <mail_error.h>
#include <verp_sender.h>
#include "bounce_service.h"
#define STR vstring_str
int bounce_notify_verp(char *service, char *queue_name,
char *queue_id, char *encoding,
char *recipient,
char *verp_delims, int flush)
{
char *myname = "bounce_notify_verp";
BOUNCE_INFO *bounce_info;
int bounce_status = 0;
int postmaster_status;
VSTREAM *bounce;
int notify_mask = name_mask(VAR_NOTIFY_CLASSES, mail_error_masks,
var_notify_classes);
char *postmaster;
VSTRING *verp_buf = vstring_alloc(100);
if (*recipient == 0)
msg_panic("%s: attempt to bounce a single bounce", myname);
if (strcasecmp(recipient, mail_addr_double_bounce()) == 0)
msg_panic("%s: attempt to bounce a double bounce", myname);
bounce_info = bounce_mail_init(service, queue_name, queue_id,
encoding, flush);
#define NULL_SENDER MAIL_ADDR_EMPTY
#define NULL_CLEANUP_FLAGS 0
#define BOUNCE_HEADERS 1
#define BOUNCE_ALL 0
while (bounce_log_read(bounce_info->log_handle) != 0) {
verp_sender(verp_buf, verp_delims, recipient,
bounce_info->log_handle->recipient);
if ((bounce = post_mail_fopen_nowait(NULL_SENDER, STR(verp_buf),
NULL_CLEANUP_FLAGS)) != 0) {
if (bounce_header(bounce, bounce_info, STR(verp_buf)) == 0
&& bounce_boilerplate(bounce, bounce_info) == 0
&& bounce_recipient_log(bounce, bounce_info) == 0
&& bounce_header_dsn(bounce, bounce_info) == 0
&& bounce_recipient_dsn(bounce, bounce_info) == 0)
bounce_original(bounce, bounce_info, flush ?
BOUNCE_ALL : BOUNCE_HEADERS);
bounce_status = post_mail_fclose(bounce);
} else
bounce_status = 1;
if (bounce_status != 0)
break;
bounce_log_delrcpt(bounce_info->log_handle);
#define WANT_IF_BOUNCE (flush == 1 && (notify_mask & MAIL_ERROR_BOUNCE))
#define WANT_IF_DELAY (flush == 0 && (notify_mask & MAIL_ERROR_DELAY))
if (WANT_IF_BOUNCE || WANT_IF_DELAY) {
postmaster = flush ? var_bounce_rcpt : var_delay_rcpt;
if ((bounce = post_mail_fopen_nowait(mail_addr_double_bounce(),
postmaster,
NULL_CLEANUP_FLAGS)) != 0) {
if (bounce_header(bounce, bounce_info, postmaster) == 0
&& bounce_recipient_log(bounce, bounce_info) == 0
&& bounce_header_dsn(bounce, bounce_info) == 0
&& bounce_recipient_dsn(bounce, bounce_info) == 0)
bounce_original(bounce, bounce_info, BOUNCE_HEADERS);
postmaster_status = post_mail_fclose(bounce);
} else
postmaster_status = 1;
if (postmaster_status)
msg_warn("postmaster notice failed while bouncing to %s",
recipient);
}
}
if (flush != 0 && bounce_status == 0 && mail_queue_remove(service, queue_id)
&& errno != ENOENT)
msg_fatal("remove %s %s: %m", service, queue_id);
bounce_mail_free(bounce_info);
vstring_free(verp_buf);
return (bounce_status);
}