From 0a6853964fe17bcee7f9dacaa2eff5e86694e0fe Mon Sep 17 00:00:00 2001 From: Kevin Zheng Date: Sat, 4 Jun 2022 13:10:29 -0700 Subject: [PATCH] Add timeout and use text mode --- python/commands/report.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/python/commands/report.py b/python/commands/report.py index a997735f2..15430fb34 100644 --- a/python/commands/report.py +++ b/python/commands/report.py @@ -30,10 +30,17 @@ Report: {DESC} msg["From"] = "crossfire" msg["Subject"] = "Crossfire issue report" - result = subprocess.run(['sendmail', recipient], input=msg.as_bytes()) - if result.returncode == 0: - pl.Message("Thank you for your report.") - else: - pl.Message("There was an error reporting your problem. Please contact a Dungeon Master to report your problem.") + try: + result = subprocess.run(['sendmail', recipient], universal_newlines=True, input=msg.as_string(), timeout=2) + if result.returncode == 0: + pl.Message("Thank you for your report.") + else: + error(pl) + except subprocess.TimeoutExpired: + error(pl) + Crossfire.Log(Crossfire.LogError, "Timed out while reporting a problem") + +def error(pl): + pl.Message("There was an error reporting your problem. Please try again or contact a Dungeon Master to report your problem.") report(Crossfire.WhoAmI())