Skip to content

Commit 9a09459

Browse files
committed
update
1 parent 5abb2f4 commit 9a09459

2 files changed

Lines changed: 52 additions & 1 deletion

File tree

Mailman/Handlers/SMTPDirect.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
from Mailman.Handlers.Decorate import decorate
4848
from Mailman.Logging.Syslog import mailman_log
4949
import Mailman.SafeDict
50+
from Mailman.Queue.Switchboard import get_switchboard
5051

5152
import email
5253
from email.utils import formataddr
@@ -429,14 +430,19 @@ def bulkdeliver(mlist, msg, msgdata, envsender, failures, conn):
429430
mailman_log('smtp-failure', 'All recipients refused: %s, msgid: %s',
430431
e, msgid)
431432
refused = e.recipients
433+
# Move message to bad queue since all recipients were refused
434+
badq = get_switchboard(mm_cfg.BADQUEUE_DIR)
435+
badq.enqueue(msg, msgdata)
432436
except smtplib.SMTPResponseException as e:
433437
mailman_log('smtp-failure', 'SMTP session failure: %s, %s, msgid: %s',
434438
e.smtp_code, e.smtp_error, msgid)
435439
# Properly handle permanent vs temporary failures
436440
if e.smtp_code >= 500 and e.smtp_code != 552:
437-
# Permanent failure - add to refused
441+
# Permanent failure - add to refused and move to bad queue
438442
for r in recips:
439443
refused[r] = (e.smtp_code, e.smtp_error)
444+
badq = get_switchboard(mm_cfg.BADQUEUE_DIR)
445+
badq.enqueue(msg, msgdata)
440446
else:
441447
# Temporary failure - don't add to refused
442448
mailman_log('smtp-failure', 'Temporary SMTP failure, will retry: %s', e.smtp_error)
@@ -446,4 +452,7 @@ def bulkdeliver(mlist, msg, msgdata, envsender, failures, conn):
446452
error = str(e)
447453
for r in recips:
448454
refused[r] = (-1, error)
455+
# Move message to bad queue for low level errors
456+
badq = get_switchboard(mm_cfg.BADQUEUE_DIR)
457+
badq.enqueue(msg, msgdata)
449458
failures.update(refused)

Mailman/Handlers/SpamDetect.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,48 @@ def getDecodedHeaders(msg, lcset):
8686

8787

8888
def process(mlist, msg, msgdata):
89+
# Check for Google Groups messages first
90+
google_groups_headers = [
91+
'X-Google-Groups-Id',
92+
'X-Google-Groups-Info',
93+
'X-Google-Groups-Url',
94+
'X-Google-Groups-Name',
95+
'X-Google-Groups-Email'
96+
]
97+
98+
for header in google_groups_headers:
99+
if msg.get(header):
100+
syslog('vette', 'Google Groups message detected via header %s, discarding', header)
101+
# Send bounce to the message's errors-to address
102+
try:
103+
bounce_msg = Message()
104+
bounce_msg['From'] = mlist.GetBounceEmail()
105+
# Use the message's errors-to header if present, otherwise use the From address
106+
bounce_to = msg.get('errors-to') or msg.get('from', 'unknown')
107+
bounce_msg['To'] = bounce_to
108+
bounce_msg['Subject'] = 'Message rejected: Google Groups not allowed'
109+
bounce_msg['Message-ID'] = Utils.unique_message_id(mlist)
110+
bounce_msg['Date'] = Utils.formatdate(localtime=True)
111+
bounce_msg['X-Mailman-From'] = msg.get('from', 'unknown')
112+
bounce_msg['X-Mailman-To'] = msg.get('to', 'unknown')
113+
bounce_msg['X-Mailman-List'] = mlist.internal_name()
114+
bounce_msg['X-Mailman-Reason'] = 'Google Groups messages are not allowed'
115+
116+
# Include original message headers
117+
bounce_text = 'Original message headers:\n'
118+
for name, value in msg.items():
119+
bounce_text += f'{name}: {value}\n'
120+
bounce_msg.set_payload(bounce_text)
121+
122+
# Send the bounce
123+
mlist.BounceMessage(bounce_msg, msgdata)
124+
syslog('vette', 'Sent bounce to %s for rejected Google Groups message', bounce_to)
125+
except Exception as e:
126+
syslog('error', 'Failed to send bounce for Google Groups message: %s', str(e))
127+
128+
# Discard the original message
129+
raise Errors.DiscardMessage
130+
89131
# Before anything else, check DMARC if necessary. We do this as early
90132
# as possible so reject/discard actions trump other holds/approvals and
91133
# wrap/munge actions get flagged even for approved messages.

0 commit comments

Comments
 (0)