aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/ircbot/Sourcehut/plugin.py
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2024-08-20 13:51:49 +0200
committerRobin Jarry <robin@jarry.cc>2024-08-20 13:57:33 +0200
commit2d9f949ac9a3369f81142ec7b138a5eadebafaeb (patch)
tree771987206fb3bfbc8ea6ac4097e9f64f74a79621 /contrib/ircbot/Sourcehut/plugin.py
parent11f57b5f3378f944ea54a8a9de4ca040c62f5b12 (diff)
downloadaerc-2d9f949ac9a3369f81142ec7b138a5eadebafaeb.tar.gz
ircbot: sanitize email subjects
Email subjects may contain line breaks if they are too long to fit in 72 columns. The supybot library does not support sending messages with line breaks. It raises an error. Replace all consecutive "white space" characters (including \r and \n) with regular space characters. Signed-off-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'contrib/ircbot/Sourcehut/plugin.py')
-rw-r--r--contrib/ircbot/Sourcehut/plugin.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/contrib/ircbot/Sourcehut/plugin.py b/contrib/ircbot/Sourcehut/plugin.py
index 593ad020..a7d0b46c 100644
--- a/contrib/ircbot/Sourcehut/plugin.py
+++ b/contrib/ircbot/Sourcehut/plugin.py
@@ -4,8 +4,10 @@ import json
import mailbox
from urllib.parse import quote
from urllib.request import urlopen
+import re
+import traceback
-from supybot import callbacks, httpserver, ircmsgs, log, world
+from supybot import callbacks, httpserver, ircmsgs, world
from supybot.ircutils import bold, italic, mircColor, underline
@@ -89,7 +91,7 @@ class SourcehutServerCallback(httpserver.SupyHTTPServerCallback):
print(f"GET {url}/raw")
with urlopen(f"{url}/raw") as u:
msg = mailbox.Message(u.read())
- subject = decode_header(msg["subject"])
+ subject = re.sub(r"\s+", " ", decode_header(msg["subject"]))
if not subject.startswith("[PATCH"):
continue
for name, addr in email.utils.getaddresses([decode_header(msg["from"])]):
@@ -127,7 +129,7 @@ class SourcehutServerCallback(httpserver.SupyHTTPServerCallback):
raise ValueError(f"unsupported webhook: {hook}")
except Exception as e:
- print("ERROR", e)
+ traceback.print_exception(e)
handler.send_response(400)
handler.end_headers()
handler.wfile.write(b"Bad request\n")