bounce_one_service.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 <post_mail.h>
#include <mail_addr.h>
#include <mail_error.h>
#include <bounce.h>
#include <dsn_mask.h>
#include "bounce_service.h"
#define STR vstring_str
int bounce_one_service(int flags, char *queue_name, char *queue_id,
char *encoding, char *orig_sender,
char *dsn_envid, int dsn_ret,
RCPT_BUF *rcpt_buf, DSN_BUF *dsn_buf,
BOUNCE_TEMPLATES *ts)
{
BOUNCE_INFO *bounce_info;
int bounce_status = 1;
int postmaster_status = 1;
VSTREAM *bounce;
int notify_mask = name_mask(VAR_NOTIFY_CLASSES, mail_error_masks,
var_notify_classes);
VSTRING *new_id = vstring_alloc(10);
bounce_info = bounce_mail_one_init(queue_name, queue_id, encoding,
dsn_envid, rcpt_buf, dsn_buf,
ts->failure);
#define NULL_SENDER MAIL_ADDR_EMPTY
#define NULL_TRACE_FLAGS 0
if (strcasecmp(orig_sender, mail_addr_double_bounce()) == 0) {
msg_warn("%s: undeliverable postmaster notification discarded",
queue_id);
bounce_status = 0;
}
#define ANY_BOUNCE (MAIL_ERROR_2BOUNCE | MAIL_ERROR_BOUNCE)
#define SEND_POSTMASTER_ANY_BOUNCE_NOTICE (notify_mask & ANY_BOUNCE)
else if (*orig_sender == 0) {
if (!SEND_POSTMASTER_ANY_BOUNCE_NOTICE) {
bounce_status = 0;
} else {
if ((bounce = post_mail_fopen_nowait(mail_addr_double_bounce(),
var_2bounce_rcpt,
INT_FILT_BOUNCE,
NULL_TRACE_FLAGS,
new_id)) != 0) {
if (!bounce_header(bounce, bounce_info, var_2bounce_rcpt,
POSTMASTER_COPY)
&& 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, DSN_RET_FULL);
bounce_status = post_mail_fclose(bounce);
if (bounce_status == 0)
msg_info("%s: postmaster non-delivery notification: %s",
queue_id, STR(new_id));
}
}
}
else {
RECIPIENT *rcpt = &bounce_info->rcpt_buf->rcpt;
if (rcpt->dsn_notify != 0
&& (rcpt->dsn_notify & DSN_NOTIFY_FAILURE) == 0) {
bounce_status = 0;
} else {
if ((bounce = post_mail_fopen_nowait(NULL_SENDER, orig_sender,
INT_FILT_BOUNCE,
NULL_TRACE_FLAGS,
new_id)) != 0) {
if (bounce_header(bounce, bounce_info, orig_sender,
NO_POSTMASTER_COPY) == 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, dsn_ret ?
dsn_ret : DSN_RET_FULL);
bounce_status = post_mail_fclose(bounce);
if (bounce_status == 0)
msg_info("%s: sender non-delivery notification: %s",
queue_id, STR(new_id));
}
}
#define SEND_POSTMASTER_SINGLE_BOUNCE_NOTICE (notify_mask & MAIL_ERROR_BOUNCE)
if (bounce_status == 0 && SEND_POSTMASTER_SINGLE_BOUNCE_NOTICE
&& strcasecmp(orig_sender, mail_addr_double_bounce()) != 0) {
if ((bounce = post_mail_fopen_nowait(mail_addr_double_bounce(),
var_bounce_rcpt,
INT_FILT_BOUNCE,
NULL_TRACE_FLAGS,
new_id)) != 0) {
if (bounce_header(bounce, bounce_info, var_bounce_rcpt,
POSTMASTER_COPY) == 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, DSN_RET_HDRS);
postmaster_status = post_mail_fclose(bounce);
if (postmaster_status == 0)
msg_info("%s: postmaster non-delivery notification: %s",
queue_id, STR(new_id));
}
if (postmaster_status)
msg_warn("%s: postmaster notice failed while bouncing to %s",
queue_id, orig_sender);
}
}
if (bounce_status == 0 && (flags & BOUNCE_FLAG_DELRCPT))
bounce_delrcpt_one(bounce_info);
bounce_mail_free(bounce_info);
vstring_free(new_id);
return (bounce_status);
}