[projects/pld-builder.new] mailer: send mail in utf-8
arekm
arekm at pld-linux.org
Thu Nov 12 10:29:32 CET 2026
commit e9437d6e0cab203fc3dcce11c5cccb857e8d60c4
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date: Thu Nov 12 10:28:16 2026 +0100
mailer: send mail in utf-8
A report quoting a request with text outside latin-1, the locale of the
scripts in bin/, could not be written to sendmail and killed the
builder. Mail now goes out as utf-8 and says so, and build logs in it
are read as utf-8, so their text is no longer garbled.
PLD_Builder/mailer.py | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
---
diff --git a/PLD_Builder/mailer.py b/PLD_Builder/mailer.py
index f9c65c3..f60a966 100644
--- a/PLD_Builder/mailer.py
+++ b/PLD_Builder/mailer.py
@@ -2,6 +2,7 @@
import os
import shutil
+import subprocess
import time
from io import StringIO
@@ -41,7 +42,7 @@ class Message:
s = os.stat(logfile)
if s.st_size > 50000:
# just head and tail
- with open(logfile) as f:
+ with open(logfile, encoding="utf-8", errors="replace") as f:
line_cnt = sum(1 for _ in f)
f.seek(0)
for line, l in enumerate(f):
@@ -50,7 +51,7 @@ class Message:
if line == line_cnt - 100:
self.body.write("\n\n[...]\n\n")
else:
- with open(logfile) as f:
+ with open(logfile, encoding="utf-8", errors="replace") as f:
shutil.copyfileobj(f, self.body)
def set_std_headers(self):
@@ -58,6 +59,9 @@ class Message:
self.headers["Message-ID"] = f"<pld-builder.{time.time():f}.{os.getpid()}@{os.uname()[1]}>"
self.headers["From"] = f"PLD {config.builder} builder <{config.email}>"
self.headers["X-PLD-Builder"] = config.builder
+ self.headers["MIME-Version"] = "1.0"
+ self.headers["Content-Type"] = "text/plain; charset=utf-8"
+ self.headers["Content-Transfer-Encoding"] = "8bit"
def write_to(self, f):
for k, v in self.headers.items():
@@ -72,11 +76,13 @@ class Message:
log.alert("/usr/lib/sendmail doesn't exist: Can't send email")
return False
send_sendmail = f"/usr/lib/sendmail -i -t -f {config.admin_email}"
- f = os.popen(send_sendmail, "w")
+ p = subprocess.Popen(send_sendmail, shell=True, stdin=subprocess.PIPE, encoding="utf-8")
try:
- self.write_to(f)
+ self.write_to(p.stdin)
+ p.stdin.close()
except OSError as e:
log.alert(f"sending email message failed: {e}")
- f.close()
+ p.kill()
+ p.wait()
return False
- return f.close()
+ return p.wait() or None
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/projects/pld-builder.new.git/commitdiff/389ce5a31104551f35ba9b41daa82bb3d44c89ff
More information about the pld-cvs-commit
mailing list