Coverage for kwai/core/mail/recipient.py: 96%

26 statements  

« prev     ^ index     » next       coverage.py v7.3.0, created at 2023-09-05 17:55 +0000

1"""Module that defines a recipient.""" 

2from dataclasses import dataclass, field 

3 

4from kwai.core.domain.value_objects.email_address import EmailAddress 

5 

6 

7@dataclass(kw_only=True, frozen=True) 

8class Recipient: 

9 """Defines a recipient.""" 

10 

11 email: EmailAddress 

12 name: str 

13 

14 

15@dataclass(frozen=True) 

16class Recipients: 

17 """Defines all recipients for an email. 

18 

19 All methods are immutable. 

20 """ 

21 

22 from_: Recipient 

23 to: list[Recipient] = field(default_factory=list) 

24 cc: list[Recipient] = field(default_factory=list) 

25 bcc: list[Recipient] = field(default_factory=list) 

26 

27 def with_from(self, from_) -> "Recipients": 

28 """Clone the recipients and set the sender.""" 

29 return Recipients(from_, self.to, self.cc, self.bcc) 

30 

31 def with_to(self, *to: Recipient) -> "Recipients": 

32 """Clone the recipients and set the receiver(s).""" 

33 return Recipients(self.from_, list(to), self.cc, self.bcc) 

34 

35 def add_to(self, *to: Recipient) -> "Recipients": 

36 """Clone the recipients and add a receiver.""" 

37 return Recipients(self.from_, self.to + list(to), self.cc, self.bcc) 

38 

39 def with_cc(self, *cc: Recipient) -> "Recipients": 

40 """Clone the recipients and set the copy recipient.""" 

41 return Recipients(self.from_, self.to, list(cc), self.bcc) 

42 

43 def add_cc(self, *cc: Recipient) -> "Recipients": 

44 """Clone the recipients and add a copy recipient.""" 

45 return Recipients(self.from_, self.to, self.cc + list(cc), self.bcc) 

46 

47 def with_bcc(self, *bcc: Recipient) -> "Recipients": 

48 """Clone the recipients and set the blind copy recipient.""" 

49 return Recipients(self.from_, self.to, self.cc, list(bcc)) 

50 

51 def add_bcc(self, *bcc: Recipient) -> "Recipients": 

52 """Clone the recipients and add a blind copy recipient.""" 

53 return Recipients(self.from_, self.to, self.cc, self.bcc + list(bcc))