Skip to content

Commit

Permalink
Fix email typings
Browse files Browse the repository at this point in the history
  • Loading branch information
jsangmeister committed Mar 12, 2024
1 parent d697261 commit 0b83486
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ def update_instance(self, instance: dict[str, Any]) -> dict[str, Any]:
return instance

mail_data = self.get_data_from_meeting_or_organization(meeting_id)
from_email: str | Address
if users_email_sender := mail_data.get("users_email_sender", "").strip():
if any(
x in users_email_sender for x in EmailUtils.SENDER_NAME_FORBIDDEN_CHARS
Expand All @@ -192,8 +191,8 @@ def update_instance(self, instance: dict[str, Any]) -> dict[str, Any]:
)
result["type"] = EmailErrorType.SETTINGS_ERROR
return instance
from_email = Address(
users_email_sender, addr_spec=EmailSettings.default_from_email
from_email = str(
Address(users_email_sender, addr_spec=EmailSettings.default_from_email)
)
else:
from_email = EmailSettings.default_from_email
Expand Down
7 changes: 3 additions & 4 deletions openslides_backend/action/mixins/send_email_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from collections.abc import Generator
from contextlib import contextmanager
from datetime import datetime
from email.headerregistry import Address
from email.message import EmailMessage
from email.utils import format_datetime, make_msgid
from typing import Any
Expand Down Expand Up @@ -111,7 +110,7 @@ def get_mail_connection() -> Generator[smtplib.SMTP | smtplib.SMTP_SSL, None, No
@staticmethod
def send_email(
client: smtplib.SMTP | smtplib.SMTP_SSL,
from_: str | Address,
from_: str,
to: str | list[str],
subject: str,
content: str,
Expand Down Expand Up @@ -155,7 +154,7 @@ def send_email(
)

message["From"] = from_
message["To"] = to
message["To"] = to if isinstance(to, str) else ", ".join(to)
message.preamble = "You will not see this in a MIME-aware mail reader.\n"
message.add_header("Subject", subject)
message.add_header("Date", format_datetime(datetime.now()))
Expand All @@ -168,7 +167,7 @@ def send_email(
def send_email_safe(
client: smtplib.SMTP | smtplib.SMTP_SSL,
logger: Any,
from_: str | Address,
from_: str,
to: str | list[str],
subject: str,
content: str,
Expand Down
2 changes: 1 addition & 1 deletion tests/system/action/test_send_email_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ def test_sender_with_name(self) -> None:
EmailSettings.connection_security = "NONE"
EmailSettings.port = 25

sender = Address("Name of sender", addr_spec=self.sender)
sender = str(Address("Name of sender", addr_spec=self.sender))
handler = AIOHandler()
with AiosmtpdServerManager(handler):
with EmailUtils.get_mail_connection() as mail_client:
Expand Down

0 comments on commit 0b83486

Please sign in to comment.