Last active
November 11, 2019 22:10
-
-
Save Luzifer/3dd07b5307f753ab11ed817805c13bca to your computer and use it in GitHub Desktop.
Uberspace .qmail filter script (for Uberspace-v7 accounts)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
# Installation: Insert this line into your .qmail-* file | |
# | /path/to/check_mail_v7.py | |
from datetime import datetime | |
import sys | |
BLOCK_SCORE = 8.0 | |
MAILLOG = '/home/myuser/maillog.txt' | |
RET_SUCCESS = 0 | |
RET_SUCCESSSTOP = 99 | |
RET_HARDFAIL = 100 # Do not use this, it produces masses of bounces | |
RET_SOFTFAIL = 111 | |
def main(): | |
sender = "" | |
to = "" | |
subject = "" | |
score = 0.0 | |
result = RET_SUCCESS | |
for line in sys.stdin: | |
lline = line.lower() | |
if 'x-rspamd-score: ' in lline: | |
score = float(line.split(': ')[1].strip()) | |
if 'subject: ' in lline: | |
subject = line.split(': ')[1].strip() | |
if 'from: ' in lline: | |
sender = line.split(': ')[1].strip() | |
if 'to: ' in lline: | |
to = line.split(': ')[1].strip() | |
if score > BLOCK_SCORE: | |
result = RET_SUCCESSSTOP | |
with open(MAILLOG, 'a') as f: | |
f.write('[{date}] score="{score}" action="{result}" to="{to}" from="{sender}" subject="{subject}"\n'.format( | |
date=datetime.now().strftime('%Y-%m-%d %H:%M:%S'), | |
score=score, | |
result=result, | |
sender=sender, | |
subject=subject, | |
to=to, | |
)) | |
return result | |
if __name__ == '__main__': | |
sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment