handle BATV (Bounce Address Tag Validation) in whitelist

This commit is contained in:
2021-09-21 11:10:57 +02:00
parent 1e53393238
commit 54e73273fb

View File

@@ -31,6 +31,8 @@ class WhitelistBase:
self.logger = logging.getLogger(__name__) self.logger = logging.getLogger(__name__)
self.valid_entry_regex = re.compile( self.valid_entry_regex = re.compile(
r"^[a-zA-Z0-9_.=+-]*?(@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+)?$") r"^[a-zA-Z0-9_.=+-]*?(@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+)?$")
self.batv_regex = re.compile(
r"^prvs=[0-9]{4}[0-9A-Fa-f]{6}=")
def check(self, mailfrom, recipient): def check(self, mailfrom, recipient):
"Check if mailfrom/recipient combination is whitelisted." "Check if mailfrom/recipient combination is whitelisted."
@@ -144,6 +146,8 @@ class DatabaseWhitelist(WhitelistBase):
def check(self, mailfrom, recipient): def check(self, mailfrom, recipient):
# check if mailfrom/recipient combination is whitelisted # check if mailfrom/recipient combination is whitelisted
super().check(mailfrom, recipient) super().check(mailfrom, recipient)
mailfrom = self.batv_regex.sub("", mailfrom, count=1)
recipient = self.batv_regex.sub("", recipient, count=1)
# generate list of possible mailfroms # generate list of possible mailfroms
self.logger.debug( self.logger.debug(
@@ -227,6 +231,9 @@ class DatabaseWhitelist(WhitelistBase):
comment, comment,
permanent) permanent)
mailfrom = self.batv_regex.sub("", mailfrom, count=1)
recipient = self.batv_regex.sub("", recipient, count=1)
try: try:
self.model.create( self.model.create(
mailfrom=mailfrom, mailfrom=mailfrom,