|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Qodeboy\Mailman\Message; |
|
4
|
|
|
|
|
5
|
|
|
use Swift_Mime_Message; |
|
6
|
|
|
use Qodeboy\Mailman\Contracts\MailmanSwiftMessageAdapter; |
|
7
|
|
|
|
|
8
|
|
|
class MailmanMimeMessage implements MailmanSwiftMessageAdapter |
|
9
|
|
|
{ |
|
10
|
|
|
const STATUS_ALLOWED = 'allowed'; |
|
11
|
|
|
const STATUS_DENIED = 'denied'; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Swift_Mime_Message instance. |
|
15
|
|
|
* |
|
16
|
|
|
* @var Swift_Mime_Message |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $message; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Message delivery status. |
|
22
|
|
|
* |
|
23
|
|
|
* @var |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $status; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* {@inheritdoc} |
|
29
|
|
|
*/ |
|
30
|
|
|
public function __construct(Swift_Mime_Message $message) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->message = $message; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* {@inheritdoc} |
|
37
|
|
|
*/ |
|
38
|
|
|
public function getStatus() |
|
39
|
|
|
{ |
|
40
|
|
|
return $this->status; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* {@inheritdoc} |
|
45
|
|
|
*/ |
|
46
|
|
|
public function getId() |
|
47
|
|
|
{ |
|
48
|
|
|
return $this->message->getId(); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* {@inheritdoc} |
|
53
|
|
|
*/ |
|
54
|
|
|
public function getContentType() |
|
55
|
|
|
{ |
|
56
|
|
|
return $this->message->getContentType(); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* {@inheritdoc} |
|
61
|
|
|
*/ |
|
62
|
|
|
public function getFrom() |
|
63
|
|
|
{ |
|
64
|
|
|
return $this->message->getFrom(); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* {@inheritdoc} |
|
69
|
|
|
*/ |
|
70
|
|
|
public function getTo() |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->message->getTo(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* {@inheritdoc} |
|
77
|
|
|
*/ |
|
78
|
|
|
public function getReplyTo() |
|
79
|
|
|
{ |
|
80
|
|
|
return $this->message->getReplyTo(); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* {@inheritdoc} |
|
85
|
|
|
*/ |
|
86
|
|
|
public function getCc() |
|
87
|
|
|
{ |
|
88
|
|
|
return $this->message->getCc(); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* {@inheritdoc} |
|
93
|
|
|
*/ |
|
94
|
|
|
public function getBcc() |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->message->getBcc(); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* {@inheritdoc} |
|
101
|
|
|
*/ |
|
102
|
|
|
public function getSubject() |
|
103
|
|
|
{ |
|
104
|
|
|
return $this->message->getSubject(); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* {@inheritdoc} |
|
109
|
|
|
*/ |
|
110
|
|
|
public function getBody() |
|
111
|
|
|
{ |
|
112
|
|
|
return $this->message->getBody(); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* {@inheritdoc} |
|
117
|
|
|
*/ |
|
118
|
|
|
public function toString() |
|
119
|
|
|
{ |
|
120
|
|
|
return $this->message->toString(); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* {@inheritdoc} |
|
125
|
|
|
*/ |
|
126
|
|
|
public function getSwiftMessage() |
|
127
|
|
|
{ |
|
128
|
|
|
return $this->message; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* Mark message as allowed for sending. |
|
133
|
|
|
*/ |
|
134
|
|
|
public function allow() |
|
135
|
|
|
{ |
|
136
|
|
|
$this->setStatus(self::STATUS_ALLOWED); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* Mark message as denied for sending. |
|
141
|
|
|
*/ |
|
142
|
|
|
public function deny() |
|
143
|
|
|
{ |
|
144
|
|
|
$this->setStatus(self::STATUS_DENIED); |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* Check if message is allowed for delivery. |
|
149
|
|
|
* |
|
150
|
|
|
* @return bool |
|
151
|
|
|
*/ |
|
152
|
|
|
public function allowed() |
|
153
|
|
|
{ |
|
154
|
|
|
return $this->getStatus() === self::STATUS_ALLOWED; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* Check if message is denied for delivery. |
|
159
|
|
|
* |
|
160
|
|
|
* @return bool |
|
161
|
|
|
*/ |
|
162
|
|
|
public function denied() |
|
163
|
|
|
{ |
|
164
|
|
|
return $this->getStatus() === self::STATUS_DENIED; |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* Set message status. |
|
169
|
|
|
* |
|
170
|
|
|
* @param $status |
|
171
|
|
|
*/ |
|
172
|
|
|
protected function setStatus($status) |
|
173
|
|
|
{ |
|
174
|
|
|
if (! in_array($status, ['allowed', 'denied'])) { |
|
175
|
|
|
throw new \RuntimeException('Invalid message status supplied!'); |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
$this->status = $status; |
|
179
|
|
|
} |
|
180
|
|
|
} |
|
181
|
|
|
|