1
0
mirror of https://github.com/Mailu/Mailu.git synced 2025-05-27 22:57:38 +02:00
3057: Retry up to 5 times if not ready r=mergify[bot] a=nextgens

Add retry logic to ensure we don't always pass if clamav is not ready; return a 25 error only if it's a permanent rejection code so that we can differentiate in between "definitely reject" and "was rejected because of a glitch"

Co-authored-by: Florent Daigniere <nextgens@freenetproject.org>
This commit is contained in:
bors-mailu[bot] 2023-11-15 12:55:47 +00:00 committed by GitHub
commit 42db941fa9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 15 deletions

View File

@ -1,7 +1,7 @@
# GTUBE should be blocked, see https://rspamd.com/doc/gtube_patterns.html
python3 tests/email_test.py "XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X"
if [ $? -eq 25 ]; then
exit 0
else
if [ $? -ne 25 ]; then
exit 1
fi
exit 0

View File

@ -21,19 +21,31 @@ if len(sys.argv) == 3:
part.add_header('Content-Disposition', "attachment; filename=%s" % ntpath.basename(sys.argv[2]))
msg.attach(part)
try:
smtp_server = smtplib.SMTP('localhost')
smtp_server.set_debuglevel(1)
smtp_server.connect('localhost', 587)
smtp_server.ehlo()
smtp_server.starttls()
smtp_server.ehlo()
smtp_server.login("admin@mailu.io", "password")
for i in range(5):
try:
smtp_server = smtplib.SMTP('localhost')
smtp_server.set_debuglevel(1)
smtp_server.connect('localhost', 587)
smtp_server.ehlo()
smtp_server.starttls()
smtp_server.ehlo()
smtp_server.login("admin@mailu.io", "password")
smtp_server.sendmail("admin@mailu.io", "user@mailu.io", msg.as_string())
smtp_server.quit()
except:
sys.exit(25)
smtp_server.sendmail("admin@mailu.io", "user@mailu.io", msg.as_string())
smtp_server.quit()
except smtplib.SMTPRecipientsRefused:
sys.exit(25)
except smtplib.SMTPDataError as e:
if e.smtp_code == 451:
print(f"Not ready attempt {i}")
time.sleep(5)
continue
if e.smtp_code >= 500 and e.smtp_code <600:
sys.exit(25)
sys.exit(2525)
except:
sys.exit(2525)
break
time.sleep(30)