Patch for blocklist

This commit is contained in:
2026-03-07 11:56:54 -06:00
parent 6db032bd4c
commit a70ae78a93
2 changed files with 44 additions and 27 deletions

View File

@@ -18,9 +18,9 @@ class BlocklistChecker:
self.dynamodb = dynamodb
def is_sender_blocked(
self,
recipient: str,
sender: str,
self,
recipient: str,
sender: str,
worker_name: str
) -> bool:
"""
@@ -54,17 +54,17 @@ class BlocklistChecker:
return False
def batch_check_blocked_senders(
self,
recipients: List[str],
sender: str,
worker_name: str
self,
recipients: List[str],
senders: List[str], # <-- Geändert: Erwartet nun eine Liste
worker_name: str
) -> Dict[str, bool]:
"""
Batch check if sender is blocked for multiple recipients (more efficient)
Batch check if ANY of the senders are blocked for multiple recipients (more efficient)
Args:
recipients: List of recipient email addresses
sender: Sender email address
senders: List of sender email addresses (Envelope & Header)
worker_name: Worker name for logging
Returns:
@@ -73,7 +73,8 @@ class BlocklistChecker:
# Get all blocked patterns in one batch call
patterns_by_recipient = self.dynamodb.batch_get_blocked_patterns(recipients)
sender_clean = parseaddr(sender)[1].lower()
# Alle übergebenen Adressen bereinigen
senders_clean = [parseaddr(s)[1].lower() for s in senders if s]
result = {}
for recipient in recipients:
@@ -81,15 +82,18 @@ class BlocklistChecker:
is_blocked = False
for pattern in patterns:
if fnmatch.fnmatch(sender_clean, pattern.lower()):
log(
f"⛔ BLOCKED: Sender {sender_clean} matches pattern '{pattern}' "
f"for inbox {recipient}",
'WARNING',
worker_name
)
is_blocked = True
break
for sender_clean in senders_clean:
if fnmatch.fnmatch(sender_clean, pattern.lower()):
log(
f"⛔ BLOCKED: Sender {sender_clean} matches pattern '{pattern}' "
f"for inbox {recipient}",
'WARNING',
worker_name
)
is_blocked = True
break # Bricht die Senders-Schleife ab
if is_blocked:
break # Bricht die Pattern-Schleife ab
result[recipient] = is_blocked