Coverage for src/kwai/core/mail/mail.py: 85%
34 statements
« prev ^ index » next coverage.py v7.6.10, created at 2024-01-01 00:00 +0000
« prev ^ index » next coverage.py v7.6.10, created at 2024-01-01 00:00 +0000
1"""Module that implements the Message interface for a mail."""
3from .message import Message
4from .recipient import Recipients
7class Mail(Message):
8 """Implements a text/html mail message."""
10 def __init__(
11 self,
12 recipients: Recipients,
13 subject: str,
14 text: str = "",
15 html: str = "",
16 headers: dict[str, str] = None,
17 ):
18 self._recipients = recipients
19 self._subject = subject
20 self._text = text
21 self._html = html
22 self._headers = headers or {}
24 @property
25 def recipients(self) -> Recipients:
26 """Return the recipients."""
27 return self._recipients
29 def with_recipients(self, recipients: Recipients) -> "Message":
30 """Clone the current mail and set the recipients."""
31 return Mail(recipients, self._subject, self._text, self._html, self._headers)
33 @property
34 def subject(self) -> str:
35 """Return the subject of the mail."""
36 return self._subject
38 def with_subject(self, subject: str) -> "Message":
39 """Clone the current mail and set the subject."""
40 return Mail(self._recipients, subject, self._text, self._html, self._headers)
42 @property
43 def headers(self) -> dict[str, str]:
44 """Return the headers."""
45 return self._headers
47 def with_headers(self, headers: dict[str, str]) -> "Message":
48 """Clone the current mail and set the headers."""
49 return Mail(self._recipients, self._subject, self._text, self._html, headers)
51 @property
52 def html(self) -> str | None:
53 """Return the HTML content."""
54 return self._html
56 def with_html(self, html: str) -> "Message":
57 """Clone the current mail and set the HTML content."""
58 return Mail(self._recipients, self._subject, self._text, html, self._headers)
60 @property
61 def text(self) -> str | None:
62 """Return the text content."""
63 return self._text
65 def with_text(self, text: str) -> "Message":
66 """Clone the current mail and set the text content."""
67 return Mail(self._recipients, self._subject, text, self._html, self._headers)