Skip to content

Commit

Permalink
plugin-rbl: Allow switching to an alternate backend when sender is on…
Browse files Browse the repository at this point in the history
… RBL
  • Loading branch information
bruceg committed Apr 17, 2014
1 parent 6a76554 commit e4e64ed
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 5 deletions.
13 changes: 13 additions & 0 deletions plugin-rbl.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ static const response* init(void)
const response* r;
const char* e;
ipv4addr ip;
struct plugin* backend = 0;

debug = session_getenv("RBL_DEBUG") != 0;

Expand All @@ -86,6 +87,11 @@ static const response* init(void)
return 0;
}

if ((e = session_getenv("RBL_BACKEND")) != 0) {
if ((r = load_backend(&backend, e)) != 0)
return r;
}

/* Can only handle IPv4 sessions */
if ((e = session_getenv("TCPREMOTEIP")) == 0) {
if (debug)
Expand All @@ -99,6 +105,13 @@ static const response* init(void)

if ((r = test_rbls(blacklist, bad, &ip)) != 0)
return r;
if (msgstatus == bad && backend != 0) {
if (backend->init != 0)
if ((r = backend->init()) != 0)
return r;
switch_backend(backend);
msgstatus = good;
}
return 0;
}

Expand Down
67 changes: 62 additions & 5 deletions tests/plugin-rbl
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
<loop ip 127.0.0.2 127.0.0.99>
<loop backend "" queuedir>

if [ -n "$backend" ]; then
export RBL_BACKEND=$backend
fi
export RBL_BLACKLISTS=sbl-xbl.spamhaus.org
export RBL_DEBUG=1
export TCPREMOTEIP=$ip

setup_queuedir

smtpfront echo rbl accept <<EOF
HELO me
MAIL FROM:<somewhere>
RCPT TO:<elsewhere>
DATA
Subject: test
.
EOF

unset RBL_BLACKLISTS RBL_DEBUG TCPLOCALIP
dump_queuedir

cleanup_queuedir

<result 127.0.0.2>
unset RBL_BACKEND RBL_BLACKLISTS RBL_DEBUG TCPLOCALIP QUEUEDIR
rm -rf $tmp/queuedir $tmp/queuedir

<result 127.0.0.2 "">
mailfront[#]: rbl: sbl-xbl.spamhaus.org:
mailfront[#]: http://www.spamhaus.org/sbl/query/SBL233
mailfront[#]: http://www.spamhaus.org/query/bl?ip=127.0.0.2
Expand All @@ -22,12 +37,54 @@ mailfront[#]: 451 Blocked: http://www.spamhaus.org/sbl/query/SBL233
mailfront[#]: RCPT TO:<elsewhere>
mailfront[#]: 503 5.5.1 You must send MAIL FROM: first
503 5.5.1 You must send MAIL FROM: first^M
mailfront[#]: bytes in: 50 bytes out: 145
mailfront[#]: 503 5.5.1 You must send MAIL FROM: first
503 5.5.1 You must send MAIL FROM: first^M
mailfront[#]: Subject: test
mailfront[#]: 500 5.5.1 Not implemented.
500 5.5.1 Not implemented.^M
mailfront[#]: .
mailfront[#]: 500 5.5.1 Not implemented.
500 5.5.1 Not implemented.^M
mailfront[#]: bytes in: 71 bytes out: 243
queuedir tmp: 0 new: 0

<result 127.0.0.2 queuedir>
mailfront[#]: rbl: sbl-xbl.spamhaus.org:
mailfront[#]: http://www.spamhaus.org/sbl/query/SBL233
mailfront[#]: http://www.spamhaus.org/query/bl?ip=127.0.0.2
250 local.host^M
mailfront[#]: MAIL FROM:<somewhere>
250 2.1.0 Sender accepted.^M
mailfront[#]: RCPT TO:<elsewhere>
250 2.1.5 Recipient accepted.^M
354 End your message with a period on a line by itself.^M
250 2.6.0 Message accepted.^M
mailfront[#]: bytes in: 71 bytes out: 193
queuedir tmp: 0 new: 1
===== queued file =====
somewhere^@elsewhere^@^@Subject: test
=====

<result 127.0.0.99 "">
250 local.host^M
mailfront[#]: MAIL FROM:<somewhere>
250 Sender='somewhere'.^M
mailfront[#]: RCPT TO:<elsewhere>
250 Recipient='elsewhere'.^M
354 End your message with a period on a line by itself.^M
mailfront[#]: Subject: test
250 Received 14 bytes.^M
mailfront[#]: bytes in: 71 bytes out: 182
queuedir tmp: 0 new: 0

<result 127.0.0.99>
<result 127.0.0.99 queuedir>
250 local.host^M
mailfront[#]: MAIL FROM:<somewhere>
250 Sender='somewhere'.^M
mailfront[#]: RCPT TO:<elsewhere>
250 Recipient='elsewhere'.^M
mailfront[#]: bytes in: 50 bytes out: 101
354 End your message with a period on a line by itself.^M
mailfront[#]: Subject: test
250 Received 14 bytes.^M
mailfront[#]: bytes in: 71 bytes out: 182
queuedir tmp: 0 new: 0

0 comments on commit e4e64ed

Please sign in to comment.