Coverage for kwai/core/mail/mail.py: 85%
34 statements
« prev ^ index » next coverage.py v7.3.0, created at 2023-09-05 17:55 +0000
« prev ^ index » next coverage.py v7.3.0, created at 2023-09-05 17:55 +0000
1"""Module that implements the Message interface for a mail."""
2from .message import Message
3from .recipient import Recipients
6class Mail(Message):
7 """Implements a text/html mail message."""
9 def __init__(
10 self,
11 recipients: Recipients,
12 subject: str,
13 text: str = "",
14 html: str = "",
15 headers: dict[str, str] = None,
16 ):
17 self._recipients = recipients
18 self._subject = subject
19 self._text = text
20 self._html = html
21 self._headers = headers or {}
23 @property
24 def recipients(self) -> Recipients:
25 """Return the recipients."""
26 return self._recipients
28 def with_recipients(self, recipients: Recipients) -> "Message":
29 """Clone the current mail and set the recipients."""
30 return Mail(recipients, self._subject, self._text, self._html, self._headers)
32 @property
33 def subject(self) -> str:
34 """Return the subject of the mail."""
35 return self._subject
37 def with_subject(self, subject: str) -> "Message":
38 """Clone the current mail and set the subject."""
39 return Mail(self._recipients, subject, self._text, self._html, self._headers)
41 @property
42 def headers(self) -> dict[str, str]:
43 """Return the headers."""
44 return self._headers
46 def with_headers(self, headers: dict[str, str]) -> "Message":
47 """Clone the current mail and set the headers."""
48 return Mail(self._recipients, self._subject, self._text, self._html, headers)
50 @property
51 def html(self) -> str | None:
52 """Return the HTML content."""
53 return self._html
55 def with_html(self, html: str) -> "Message":
56 """Clone the current mail and set the HTML content."""
57 return Mail(self._recipients, self._subject, self._text, html, self._headers)
59 @property
60 def text(self) -> str | None:
61 """Return the text content."""
62 return self._text
64 def with_text(self, text: str) -> "Message":
65 """Clone the current mail and set the text content."""
66 return Mail(self._recipients, self._subject, text, self._html, self._headers)