style: apply ruff format to all source files
This commit is contained in:
@@ -40,8 +40,12 @@ def build_message(
|
||||
period: str,
|
||||
) -> MIMEMultipart:
|
||||
"""Формирует MIME-письмо с подстановками и вложением."""
|
||||
subject = email_config.subject.replace("{author}", author).replace("{period}", period)
|
||||
body = email_config.body_text.replace("{author}", author).replace("{period}", period)
|
||||
subject = email_config.subject.replace("{author}", author).replace(
|
||||
"{period}", period
|
||||
)
|
||||
body = email_config.body_text.replace("{author}", author).replace(
|
||||
"{period}", period
|
||||
)
|
||||
|
||||
msg = MIMEMultipart()
|
||||
msg["Subject"] = subject
|
||||
@@ -91,7 +95,9 @@ def send_report(
|
||||
"""
|
||||
smtp_cfg = email_config.smtp
|
||||
msg = build_message(email_config, file_path, author, period)
|
||||
all_recipients = list(email_config.to) + list(email_config.cc) + list(email_config.bcc)
|
||||
all_recipients = (
|
||||
list(email_config.to) + list(email_config.cc) + list(email_config.bcc)
|
||||
)
|
||||
|
||||
try:
|
||||
with smtplib.SMTP(smtp_cfg.host, smtp_cfg.port, timeout=SMTP_TIMEOUT) as server:
|
||||
@@ -100,21 +106,18 @@ def send_report(
|
||||
if smtp_cfg.user:
|
||||
server.login(smtp_cfg.user, smtp_cfg.password)
|
||||
|
||||
server.send_message(msg, from_addr=email_config.from_, to_addrs=all_recipients)
|
||||
server.send_message(
|
||||
msg, from_addr=email_config.from_, to_addrs=all_recipients
|
||||
)
|
||||
except smtplib.SMTPAuthenticationError:
|
||||
raise RedmineAPIError(
|
||||
"Ошибка аутентификации SMTP. Проверьте логин и пароль."
|
||||
) from None
|
||||
except TimeoutError:
|
||||
raise RedmineAPIError(
|
||||
"Таймаут соединения с SMTP-сервером."
|
||||
) from None
|
||||
raise RedmineAPIError("Таймаут соединения с SMTP-сервером.") from None
|
||||
except smtplib.SMTPException as exc:
|
||||
raise RedmineAPIError(
|
||||
f"Ошибка отправки письма: {exc}"
|
||||
) from exc
|
||||
raise RedmineAPIError(f"Ошибка отправки письма: {exc}") from exc
|
||||
except OSError as exc:
|
||||
raise RedmineAPIError(
|
||||
f"Не удалось подключиться к SMTP-серверу {smtp_cfg.host}:{smtp_cfg.port}"
|
||||
) from exc
|
||||
|
||||
|
||||
Reference in New Issue
Block a user