Skip to content

Commit 6179d4b

Browse files
committed
Add ignore list for DNSBL results
1 parent 82551be commit 6179d4b

File tree

6 files changed

+25
-29
lines changed

6 files changed

+25
-29
lines changed

.github/release-drafter.yml

Lines changed: 0 additions & 6 deletions
This file was deleted.

.github/workflows/python-package.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
16+
python-version: ['3.7', '3.8', '3.9', '3.10']
1717

1818
steps:
1919
- uses: actions/checkout@v2

.github/workflows/release-drafter.yml

Lines changed: 0 additions & 15 deletions
This file was deleted.

setup.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
license = f.read()
2929

3030
setup(name='python-slimta',
31-
version='5.0.3',
31+
version='5.0.4',
3232
author='Ian Good',
3333
author_email='ian@icgood.net',
3434
description='Lightweight, asynchronous SMTP libraries.',
@@ -38,7 +38,7 @@
3838
url='http://slimta.org/',
3939
include_package_data=True,
4040
packages=find_namespace_packages(include=['slimta.*']),
41-
install_requires=['gevent >= 1.1rc',
41+
install_requires=['gevent >= 1.1',
4242
'pysasl >= 0.5.0',
4343
'pycares >= 1'],
4444
extras_require={'spf': ['pyspf', 'py3dns'],
@@ -51,7 +51,6 @@
5151
'Intended Audience :: Information Technology',
5252
'License :: OSI Approved :: MIT License',
5353
'Programming Language :: Python',
54-
'Programming Language :: Python :: 3.6',
5554
'Programming Language :: Python :: 3.7',
5655
'Programming Language :: Python :: 3.8',
5756
'Programming Language :: Python :: 3.9',

slimta/util/dnsbl.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
from __future__ import absolute_import
3030

31+
from ipaddress import IPv4Address, IPv4Network
3132
from functools import wraps
3233

3334
import gevent
@@ -54,11 +55,13 @@ class DnsBlocklist(object):
5455
:meth:`.get()` or ``__contains__``.
5556
5657
:param address: The DNSBL domain name.
58+
:param ignore: List of DNSBL result codes to ignore.
5759
5860
"""
5961

60-
def __init__(self, address):
62+
def __init__(self, address, ignore=None):
6163
self.address = address
64+
self.ignore = [IPv4Network(ip) for ip in (ignore or [])]
6265

6366
def _build_query(self, ip):
6467
one, two, three, four = ip.split('.', 3)
@@ -86,12 +89,18 @@ def get(self, ip, timeout=None, strict=False):
8689
with gevent.Timeout(timeout, None):
8790
query = self._build_query(ip)
8891
try:
89-
DNSResolver.query(query, 'A').get()
92+
answers = DNSResolver.query(query, 'A').get()
9093
except DNSError as exc:
9194
if exc.errno == ARES_ENOTFOUND:
9295
return False
9396
logging.log_exception(__name__, query=query)
9497
else:
98+
if answers:
99+
for rdata in answers:
100+
ip = IPv4Address(rdata.host)
101+
for ignore in self.ignore:
102+
if ip in ignore:
103+
return False
95104
return True
96105
return strict
97106

test/test_slimta_util_dnsbl.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010

1111
class FakeRdata(object):
1212

13-
def __init__(self, text):
14-
self.text = text
13+
def __init__(self, val):
14+
self.host = val
15+
self.text = val
1516

1617

1718
class FakeAsyncResult(object):
@@ -40,6 +41,14 @@ def test_dnsblocklist_get(self):
4041
self.assertTrue(self.dnsbl.get('1.2.3.4'))
4142
self.assertNotIn('5.6.7.8', self.dnsbl)
4243

44+
def test_dnsblocklist_get_ignore(self):
45+
DNSResolver.query('4.3.2.1.test.example.com', 'A').AndReturn(FakeAsyncResult(['127.0.0.2']))
46+
DNSResolver.query('8.7.6.5.test.example.com', 'A').AndReturn(FakeAsyncResult(['127.0.0.11']))
47+
self.mox.ReplayAll()
48+
dnsbl = DnsBlocklist('test.example.com', ['127.0.0.10/31'])
49+
self.assertIn('1.2.3.4', dnsbl)
50+
self.assertNotIn('5.6.7.8', dnsbl)
51+
4352
def test_dnsblocklist_get_reason(self):
4453
DNSResolver.query('4.3.2.1.test.example.com', 'TXT').AndReturn(FakeAsyncResult())
4554
DNSResolver.query('4.3.2.1.test.example.com', 'TXT').AndReturn(FakeAsyncResult(['good reason']))

0 commit comments

Comments
 (0)