Skip to content

Commit

Permalink
plugin-counters: Added new "reject message" mode for recipient counting
Browse files Browse the repository at this point in the history
If $MAXRCPTS_REJECT is set and the recipient count is exceeded, the
whole message is rejected rather than just the individual recipients.
  • Loading branch information
bruceg committed Sep 17, 2010
1 parent f21d5a6 commit aeb0e8f
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 6 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
-------------------------------------------------------------------------------
Changes in version 1.17

- Added support for rejecting whole messages when the recipient count is
exceeded in plugin-counters.

Development of this version has been sponsored by FutureQuest, Inc.
[email protected] http://www.FutureQuest.net/
-------------------------------------------------------------------------------
Expand Down
17 changes: 17 additions & 0 deletions plugin-counters.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ static const response* recipient(str* r)
static const response* start(int fd)
{
unsigned long maxhops;
if (session_getenv("MAXRCPTS_REJECT")){
unsigned long maxrcpts = minenv("maxrcpts", "MAXRCPTS");
if (maxrcpts > 0 && rcpt_count > maxrcpts)
return &resp_manyrcpt;
}
minenv("maxdatabytes", "DATABYTES");
if ((maxhops = session_getenvu("MAXHOPS")) == 0)
maxhops = 100;
Expand Down Expand Up @@ -126,6 +131,17 @@ static const response* block(const char* bytes, unsigned long len)
return 0;
}

static const response* end(int fd)
{
if (session_getenv("MAXRCPTS_REJECT")){
unsigned long maxrcpts = minenv("maxrcpts", "MAXRCPTS");
if (maxrcpts > 0 && rcpt_count > maxrcpts)
return &resp_manyrcpt;
}
return 0;
(void)fd;
}

struct plugin plugin = {
.version = PLUGIN_VERSION,
.init = init,
Expand All @@ -134,4 +150,5 @@ struct plugin plugin = {
.recipient = recipient,
.data_start = start,
.data_block = block,
.message_end = end,
};
19 changes: 13 additions & 6 deletions plugin-counters.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ <h2>Configuration</h2>

<dt><tt>$MAXRCPTS</tt></dt> <dd>The maximum recipient limit</dd>

<dt><tt>$MAXRCPTS_REJECT</tt></dt> <dd>If set (to anything), messages
that have more than <tt>$MAXRCPTS</tt> recipients will have the message
rejected rather than just the excess recipients.</dd>

<dt><tt>$MAXHOPS</tt></dt> <dd>The maximum hop limit (defaults to
100)</dd>

Expand All @@ -28,19 +32,22 @@ <h2>Sender Action</h2>

<h2>Recipient Action</h2>

<p>If at least the maximum recipient limit has been reached for the
current message, this recipient is rejected. Otherwise no action.</p>
<p>If the maximum recipient limit has been exceeded for the current
message, this recipient is rejected. Otherwise no action.</p>

<h2>Data Action</h2>

<p>If the message is larger than the maximum message size, it is
rejected. If more than the maximum hop limit of either "<tt>Received:</tt>"
or "<tt>Delivered-To:</tt>" headers are present in the message, it is
<p>If the maximum recipient limit has been exceeded
and <tt>$MAXRCPTS_REJECT</tt> is set, the message is rejected. If the
message is larger than the maximum message size, it is rejected. If
more than the maximum hop limit of either "<tt>Received:</tt>" or
"<tt>Delivered-To:</tt>" headers are present in the message, it is
rejected. Otherwise no action.</p>

<h2>Message Action</h2>

<p>None</p>
<p>If the maximum recipient limit has been exceeded
and <tt>$MAXRCPTS_REJECT</tt> is set, the message is rejected.</p>

</body>
</html>
25 changes: 25 additions & 0 deletions tests/smtpfront-maxrcpts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,37 @@ RCPT TO:<[email protected]>
RCPT TO:<[email protected]>
RCPT TO:<[email protected]>
RCPT TO:<[email protected]>
DATA
.
EOF

MAXRCPTS_REJECT=1
export MAXRCPTS_REJECT

sfecho <<EOF
MAIL FROM:<[email protected]>
RCPT TO:<[email protected]>
RCPT TO:<[email protected]>
RCPT TO:<[email protected]>
RCPT TO:<[email protected]>
DATA
.
EOF

unset MAXRCPTS
unset MAXRCPTS_REJECT
<result>
250 Sender='[email protected]'.^M
250 Recipient='[email protected]'.^M
250 Recipient='[email protected]'.^M
550 5.5.3 Too many recipients^M
550 5.5.3 Too many recipients^M
354 End your message with a period on a line by itself.^M
250 Received 0 bytes.^M
250 Sender='[email protected]'.^M
250 Recipient='[email protected]'.^M
250 Recipient='[email protected]'.^M
550 5.5.3 Too many recipients^M
550 5.5.3 Too many recipients^M
550 5.5.3 Too many recipients^M
500 5.5.1 Not implemented.^M

0 comments on commit aeb0e8f

Please sign in to comment.