improve BATV handling
This commit is contained in:
@@ -32,7 +32,11 @@ class WhitelistBase:
|
|||||||
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(
|
self.batv_regex = re.compile(
|
||||||
r"^prvs=[0-9]{4}[0-9A-Fa-f]{6}=")
|
r"^prvs=[0-9]{4}[0-9A-Fa-f]{6}=(?P<LEFT_PART>.+?)@")
|
||||||
|
|
||||||
|
def remove_batv(self, addr):
|
||||||
|
return self.batv_regex.sub("\g<LEFT_PART>", addr, count=1)
|
||||||
|
|
||||||
|
|
||||||
def check(self, mailfrom, recipient):
|
def check(self, mailfrom, recipient):
|
||||||
"Check if mailfrom/recipient combination is whitelisted."
|
"Check if mailfrom/recipient combination is whitelisted."
|
||||||
@@ -146,8 +150,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)
|
mailfrom = self.remove_batv(mailfrom)
|
||||||
recipient = self.batv_regex.sub("", recipient, count=1)
|
recipient = self.remove_batv(recipient)
|
||||||
|
|
||||||
# generate list of possible mailfroms
|
# generate list of possible mailfroms
|
||||||
self.logger.debug(
|
self.logger.debug(
|
||||||
@@ -231,8 +235,8 @@ class DatabaseWhitelist(WhitelistBase):
|
|||||||
comment,
|
comment,
|
||||||
permanent)
|
permanent)
|
||||||
|
|
||||||
mailfrom = self.batv_regex.sub("", mailfrom, count=1)
|
mailfrom = self.remove_batv(mailfrom)
|
||||||
recipient = self.batv_regex.sub("", recipient, count=1)
|
recipient = self.remove_batv(recipient)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.model.create(
|
self.model.create(
|
||||||
|
|||||||
Reference in New Issue
Block a user