1
+ from typing import Any , TYPE_CHECKING
2
+ from zope .interface import Interface
3
+
4
+ if TYPE_CHECKING :
5
+ from collections .abc import Sequence
6
+ from email .headerregistry import Address
7
+ from .types import MailState
8
+ from .types import MailParams
9
+ from .types import TemplateMailParams
10
+ from ..certificate .interfaces import ITemplate
11
+ from ..models import Organization
12
+ from ..types import JSONObject
13
+ MailID = Any
14
+
15
+
16
+ class IMailer (Interface ): # pragma: no cover
17
+
18
+ # NOTE: We would like to say that kwargs is OptionalMailParams
19
+ # however there is no way in mypy to express that yet.
20
+ def send (sender : 'Address | None' ,
21
+ receivers : 'Address | Sequence[Address]' ,
22
+ subject : str ,
23
+ content : str ,
24
+ ** kwargs : Any ) -> 'MailID' :
25
+ """
26
+ Send a single email.
27
+
28
+ Returns a message uuid.
29
+ """
30
+ pass
31
+
32
+ def bulk_send (mails : list ['MailParams' ]
33
+ ) -> list ['MailID | MailState' ]:
34
+ """
35
+ Send multiple emails. "mails" is a list of dicts containing
36
+ the arguments to an individual send call.
37
+
38
+ Returns a list of message uuids and their success/failure states
39
+ in the same order as the sending list.
40
+ """
41
+ pass
42
+
43
+ # NOTE: We would like to say that kwargs is OptionalTemplateMailParams
44
+ # however there is no way in mypy to express that yet.
45
+ def send_template (sender : 'Address | None' ,
46
+ receivers : 'Address | Sequence[Address]' ,
47
+ template : str ,
48
+ data : 'JSONObject' ,
49
+ ** kwargs : Any ) -> 'MailID' :
50
+ """
51
+ Send a single email using a template using its id/name.
52
+ "data" contains the template specific data.
53
+
54
+ Returns a message uuid.
55
+ """
56
+ pass
57
+
58
+ def bulk_send_template (mails : list ['TemplateMailParams' ],
59
+ default_template : str | None = None ,
60
+ ) -> list ['MailID | MailState' ]:
61
+ """
62
+ Send multiple template emails using the same template.
63
+
64
+ Returns a list of message uuids. If a message failed to be sent
65
+ the uuid will be replaced by a MailState value.
66
+ """
67
+ pass
68
+
69
+ def template_exists (alias : str ) -> bool :
70
+ """
71
+ Returns whether a template by the given alias exists.
72
+ """
73
+ pass
74
+
75
+ def create_or_update_template (
76
+ template : 'ITemplate' ,
77
+ organization : 'Organization | None' = None ,
78
+ ) -> list [str ]:
79
+ """
80
+ Creates or updates a mailer template based on a certificate template.
81
+
82
+ Returns a list of errors. If the list is empty, it was successful.
83
+ """
84
+ pass
85
+
86
+ def delete_template (template : 'ITemplate' ) -> list [str ]:
87
+ """
88
+ Deletes a mailer template based on a certificate template.
89
+
90
+ Returns a list of errors. If the list is empty, it was successful.
91
+ """
0 commit comments