1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
#
# Copyright (c) 2014 ThoughtWorks, Inc.
#
# Pixelated is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pixelated is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
import json
from pixelated.adapter.mail import InputMail
from pixelated.adapter.status import Status
class MailBuilder:
def __init__(self):
self.mail = {
'header': {
'to': ['recipient@to.com'],
'cc': ['recipient@cc.com'],
'bcc': ['recipient@bcc.com'],
'subject': 'Hi! This the subject'
},
'body': "Hello,\nThis is the body of this message\n\nRegards,\n\n--\nPixelated.\n",
'status': []
}
def with_body(self, body):
self.mail['body'] = body
return self
def with_tags(self, tags):
self.mail['tags'] = tags
return self
def with_subject(self, subject):
self.mail['header']['subject'] = subject
return self
def with_to(self, to):
self.mail['header']['to'] = to
return self
def with_cc(self, cc):
self.mail['header']['cc'] = cc
return self
def with_bcc(self, bcc):
self.mail['header']['bcc'] = bcc
return self
def with_status(self, flags):
for status in Status.from_flags(flags):
self.mail['status'].append(status)
return self
def with_date(self, date_string):
self.mail['header']['date'] = date_string
return self
def with_ident(self, ident):
self.mail['ident'] = ident
return self
def build_json(self):
return json.dumps(self.mail)
def build_input_mail(self):
return InputMail.from_dict(self.mail)
class ResponseMail:
def __init__(self, mail_dict):
self.mail_dict = mail_dict
@property
def subject(self):
return self.headers['subject']
@property
def headers(self):
return self.mail_dict['header']
@property
def ident(self):
return self.mail_dict['ident']
@property
def tags(self):
return self.mail_dict['tags']
@property
def status(self):
return self.mail_dict['status']
|