Coverage for src/kwai/core/mail/recipient.py: 96%
26 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 defines a recipient."""
3from dataclasses import dataclass, field
5from kwai.core.domain.value_objects.email_address import EmailAddress
8@dataclass(kw_only=True, frozen=True)
9class Recipient:
10 """Defines a recipient."""
12 email: EmailAddress
13 name: str
16@dataclass(frozen=True)
17class Recipients:
18 """Defines all recipients for an email.
20 All methods are immutable.
21 """
23 from_: Recipient
24 to: list[Recipient] = field(default_factory=list)
25 cc: list[Recipient] = field(default_factory=list)
26 bcc: list[Recipient] = field(default_factory=list)
28 def with_from(self, from_) -> "Recipients":
29 """Clone the recipients and set the sender."""
30 return Recipients(from_, self.to, self.cc, self.bcc)
32 def with_to(self, *to: Recipient) -> "Recipients":
33 """Clone the recipients and set the receiver(s)."""
34 return Recipients(self.from_, list(to), self.cc, self.bcc)
36 def add_to(self, *to: Recipient) -> "Recipients":
37 """Clone the recipients and add a receiver."""
38 return Recipients(self.from_, self.to + list(to), self.cc, self.bcc)
40 def with_cc(self, *cc: Recipient) -> "Recipients":
41 """Clone the recipients and set the copy recipient."""
42 return Recipients(self.from_, self.to, list(cc), self.bcc)
44 def add_cc(self, *cc: Recipient) -> "Recipients":
45 """Clone the recipients and add a copy recipient."""
46 return Recipients(self.from_, self.to, self.cc + list(cc), self.bcc)
48 def with_bcc(self, *bcc: Recipient) -> "Recipients":
49 """Clone the recipients and set the blind copy recipient."""
50 return Recipients(self.from_, self.to, self.cc, list(bcc))
52 def add_bcc(self, *bcc: Recipient) -> "Recipients":
53 """Clone the recipients and add a blind copy recipient."""
54 return Recipients(self.from_, self.to, self.cc, self.bcc + list(bcc))