summaryrefslogtreecommitdiffstats
path: root/src/local/indirect.c
blob: a9699a593c4cef71a7e0a9dfdef184e38465bd07 (plain)
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
/*++
/* NAME
/*	indirect 3
/* SUMMARY
/*	indirect delivery
/* SYNOPSIS
/*	#include "local.h"
/*
/*	void	deliver_indirect(state)
/*	LOCAL_STATE state;
/*	char	*recipient;
/* DESCRIPTION
/*	deliver_indirect() delivers a message via the message
/*	forwarding service, with duplicate filtering up to a
/*	configurable number of recipients.
/*
/*	Arguments:
/* .IP state
/*	The attributes that specify the message, sender and more.
/*	A table with the results from expanding aliases or lists.
/* CONFIGURATION VARIABLES
/*	duplicate_filter_limit, duplicate filter size limit
/* DIAGNOSTICS
/*	The result is non-zero when the operation should be tried again.
/* 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 <unistd.h>

/* Utility library. */

#include <msg.h>
#include <htable.h>

/* Global library. */

#include <mail_params.h>
#include <bounce.h>
#include <defer.h>
#include <been_here.h>
#include <sent.h>

/* Application-specific. */

#include "local.h"

/* deliver_indirect - deliver mail via forwarding service */

int     deliver_indirect(LOCAL_STATE state)
{

    /*
     * Suppress duplicate expansion results. Add some sugar to the name to
     * avoid collisions with other duplicate filters. Allow the user to
     * specify an upper bound on the size of the duplicate filter, so that we
     * can handle huge mailing lists with millions of recipients.
     */
    if (msg_verbose)
	msg_info("deliver_indirect: %s", state.msg_attr.rcpt.address);
    if (been_here(state.dup_filter, "indirect %s",
		  state.msg_attr.rcpt.address))
	return (0);

    /*
     * Don't forward a trace-only request.
     */
    if (DEL_REQ_TRACE_ONLY(state.request->flags)) {
	dsb_simple(state.msg_attr.why, "2.0.0", "forwards to %s",
		   state.msg_attr.rcpt.address);
	return (sent(BOUNCE_FLAGS(state.request), SENT_ATTR(state.msg_attr)));
    }

    /*
     * Send the address to the forwarding service. Inherit the delivered
     * attribute from the alias or from the .forward file owner.
     */
    if (forward_append(state.msg_attr)) {
	dsb_simple(state.msg_attr.why, "4.3.0", "unable to forward message");
	return (defer_append(BOUNCE_FLAGS(state.request),
			     BOUNCE_ATTR(state.msg_attr)));
    }
    return (0);
}