read encoding from header
This commit is contained in:
@@ -65,7 +65,19 @@ rules = [
|
||||
|
||||
# read input and find recipient
|
||||
mail = "".join(sys.stdin.readlines())
|
||||
recipient = email.parser.HeaderParser().parsestr(mail)["To"]
|
||||
parsedmail = email.parser.HeaderParser().parsestr(mail)
|
||||
recipient = parsedmail["To"]
|
||||
|
||||
if parsedmail["Content-type"] is not None:
|
||||
for part in parsedmail["Content-type"].lower().split(";"):
|
||||
if part.find("charset") >= 0:
|
||||
encoding = part.split("=")[1].replace("\"", "").replace("'", "")
|
||||
break
|
||||
# default fallback
|
||||
encoding = "utf-8"
|
||||
else:
|
||||
# default fallback
|
||||
encoding = "utf-8"
|
||||
|
||||
for rule, disclaimer in rules:
|
||||
if recipient.find(rule) >= 0:
|
||||
@@ -76,7 +88,7 @@ for rule, disclaimer in rules:
|
||||
"--htmltoo",
|
||||
"--force-for-bad-html",
|
||||
],
|
||||
input=mail.encode(),
|
||||
input=mail.encode(encoding),
|
||||
capture_output=True
|
||||
)
|
||||
|
||||
@@ -91,4 +103,4 @@ for rule, disclaimer in rules:
|
||||
break
|
||||
|
||||
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(encoding))
|
||||
|
||||
Reference in New Issue
Block a user