From 4cd4938eb4dfdc7b204444d4903dce957ad23d8f Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Thu, 14 May 2020 19:32:45 +0200 Subject: [PATCH] Change logic of --email to avoid sending empty mail is some issues are found but ignored --- src/yunohost/diagnosis.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/yunohost/diagnosis.py b/src/yunohost/diagnosis.py index 3f34f206e..4fad86ffd 100644 --- a/src/yunohost/diagnosis.py +++ b/src/yunohost/diagnosis.py @@ -183,11 +183,10 @@ def diagnosis_run(categories=[], force=False, except_if_never_ran_yet=False, ema if report != {}: issues.extend([item for item in report["items"] if item["status"] in ["WARNING", "ERROR"]]) - if issues: - if email: - _email_diagnosis_issues() - elif msettings.get("interface") == "cli": - logger.warning(m18n.n("diagnosis_display_tip")) + if email: + _email_diagnosis_issues() + if issues and msettings.get("interface") == "cli": + logger.warning(m18n.n("diagnosis_display_tip")) def diagnosis_ignore(add_filter=None, remove_filter=None, list=False): @@ -565,7 +564,11 @@ def _email_diagnosis_issues(): disclaimer = "The automatic diagnosis on your YunoHost server identified some issues on your server. You will find a description of the issues below. You can manage those issues in the 'Diagnosis' section in your webadmin." - content = _dump_human_readable_reports(diagnosis_show(issues=True)["reports"]) + issues = diagnosis_show(issues=True)["reports"] + if not issues: + return + + content = _dump_human_readable_reports(issues) message = """\ From: %s @@ -579,9 +582,6 @@ Subject: %s %s """ % (from_, to_, subject_, disclaimer, content) - print(message) - smtp = smtplib.SMTP("localhost") smtp.sendmail(from_, [to_], message) smtp.quit() -