working and documented script
This commit is contained in:
@@ -2,7 +2,17 @@
|
|||||||
"""
|
"""
|
||||||
Postfix filter for adding a disclaimer to selected email.
|
Postfix filter for adding a disclaimer to selected email.
|
||||||
|
|
||||||
Emails are
|
Emails are either passed through to sendmail/postfix or - if matching a rule - piped through altermime first.
|
||||||
|
See https://dukun.de/xox/altermime/postfix-altermime-howto-2.html for more details
|
||||||
|
|
||||||
|
Place script in Postfix folder, make sure disclaimer files are in the right place and adapt Postfix config via master.cf:
|
||||||
|
> […]
|
||||||
|
> submissions inet n - n - - smtpd
|
||||||
|
> -o content_filter=disclaimerfilter
|
||||||
|
> […]
|
||||||
|
> # disclaimer filter - add a disclaimer to certain emails going out as list
|
||||||
|
> disclaimerfilter unix - n n - - pipe
|
||||||
|
> flags=Rq user=filter argv=/etc/postfix/disclaimerfilter.py -f ${sender} -- ${recipient}
|
||||||
|
|
||||||
License: GPLv3
|
License: GPLv3
|
||||||
Author: Georg Schlisio
|
Author: Georg Schlisio
|
||||||
@@ -53,9 +63,6 @@ rules = [
|
|||||||
["chor@greifswalder-domchor.de", "/etc/postfix/mailinglists/disclaimers/domchordisclaimer"]
|
["chor@greifswalder-domchor.de", "/etc/postfix/mailinglists/disclaimers/domchordisclaimer"]
|
||||||
]
|
]
|
||||||
|
|
||||||
# DEBUGGING CASE - don't use in production! overwrites above
|
|
||||||
rules = [["abmelden@augustiner-kantorei.de", "augustinerdisclaimer"]]
|
|
||||||
|
|
||||||
# read input and find recipient
|
# read input and find recipient
|
||||||
mail = "".join(sys.stdin.readlines())
|
mail = "".join(sys.stdin.readlines())
|
||||||
recipient = email.parser.HeaderParser().parsestr(mail)["To"]
|
recipient = email.parser.HeaderParser().parsestr(mail)["To"]
|
||||||
@@ -83,5 +90,5 @@ for rule, disclaimer in rules:
|
|||||||
# only first matching disclaimer!
|
# only first matching disclaimer!
|
||||||
break
|
break
|
||||||
|
|
||||||
sendmailprocess = subprocess.Popen(["/usr/bin/sendmail"] + sys.argv[1:], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
|
sendmailprocess = subprocess.Popen(["/usr/bin/sendmail", "-G", "-i"] + sys.argv[1:], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
sendmailprocess.communicate(input=mail.encode('utf-8'))
|
sendmailprocess.communicate(input=mail.encode('utf-8'))
|
||||||
|
|||||||
Reference in New Issue
Block a user