Last active
August 27, 2018 08:52
-
-
Save Luzifer/4c09bf4e1942ab5c3ec2889c53c8846f to your computer and use it in GitHub Desktop.
Uberspace .qmail filter script (for Uberspace-v6 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 | |
# | spamc | /path/to/check_mail_v6.py | |
from datetime import datetime | |
import re | |
import sys | |
BLOCK_SCORE = 9.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-spam-status: ' in lline: | |
match = re.findall(r"score=([0-9.]+)", lline) | |
if len(match) > 0: | |
score = float(match[0]) | |
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