From fda62dde1d9b78153eb34247116e1cee11dbe6f7 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Sat, 29 Jul 2023 12:03:45 +0200 Subject: [PATCH] Fix for not changing password in email settings Improved ssl certificate check on sending emails --- cps/admin.py | 4 ++-- cps/tasks/mail.py | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/cps/admin.py b/cps/admin.py index 2e235c2c..93c1a3a9 100644 --- a/cps/admin.py +++ b/cps/admin.py @@ -1296,7 +1296,7 @@ def update_mailsettings(): else: _config_int(to_save, "mail_port") _config_int(to_save, "mail_use_ssl") - if "mail_password_e" in to_save: + if to_save.get("mail_password_e", ""): _config_string(to_save, "mail_password_e") _config_int(to_save, "mail_size", lambda y: int(y) * 1024 * 1024) config.mail_server = to_save.get('mail_server', "").strip() @@ -1781,7 +1781,7 @@ def _configuration_update_helper(): # Goodreads configuration _config_checkbox(to_save, "config_use_goodreads") _config_string(to_save, "config_goodreads_api_key") - if "config_goodreads_api_secret_e" in to_save: + if to_save.get("config_goodreads_api_secret_e", ""): _config_string(to_save, "config_goodreads_api_secret_e") if services.goodreads_support: services.goodreads_support.connect(config.config_goodreads_api_key, diff --git a/cps/tasks/mail.py b/cps/tasks/mail.py index 0deb82a2..a305b623 100755 --- a/cps/tasks/mail.py +++ b/cps/tasks/mail.py @@ -18,6 +18,7 @@ import os import smtplib +import ssl import threading import socket import mimetypes @@ -192,8 +193,9 @@ class TaskEmail(CalibreTask): # on python3 debugoutput is caught with overwritten _print_debug function log.debug("Start sending e-mail") if use_ssl == 2: + context = ssl.create_default_context() self.asyncSMTP = EmailSSL(self.settings["mail_server"], self.settings["mail_port"], - timeout=timeout) + timeout=timeout, context=context) else: self.asyncSMTP = Email(self.settings["mail_server"], self.settings["mail_port"], timeout=timeout) @@ -201,7 +203,8 @@ class TaskEmail(CalibreTask): if logger.is_debug_enabled(): self.asyncSMTP.set_debuglevel(1) if use_ssl == 1: - self.asyncSMTP.starttls() + context = ssl.create_default_context() + self.asyncSMTP.starttls(context=context) if self.settings["mail_password_e"]: self.asyncSMTP.login(str(self.settings["mail_login"]), str(self.settings["mail_password_e"]))