|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2013 |
|
6
|
|
|
* @copyright Aimeos (aimeos.org), 2014-2020 |
|
7
|
|
|
* @package MW |
|
8
|
|
|
* @subpackage Mail |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
namespace Aimeos\MW\Mail\Message; |
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Zend implementation for creating e-mails. |
|
17
|
|
|
* |
|
18
|
|
|
* @package MW |
|
19
|
|
|
* @subpackage Mail |
|
20
|
|
|
*/ |
|
21
|
|
|
class Typo3 implements \Aimeos\MW\Mail\Message\Iface |
|
22
|
|
|
{ |
|
23
|
|
|
private $object; |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Initializes the message instance. |
|
28
|
|
|
* |
|
29
|
|
|
* @param \TYPO3\CMS\Core\Mail\MailMessage $object TYPO3 mail object |
|
30
|
|
|
* @param string $charset Default charset of the message |
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct( \TYPO3\CMS\Core\Mail\MailMessage $object, string $charset ) |
|
33
|
|
|
{ |
|
34
|
|
|
$object->setCharset( $charset ); |
|
35
|
|
|
|
|
36
|
|
|
$this->object = $object; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Adds a source e-mail address of the message. |
|
42
|
|
|
* |
|
43
|
|
|
* @param string $email Source e-mail address |
|
44
|
|
|
* @param string|null $name Name of the user sending the e-mail or null for no name |
|
45
|
|
|
* @return \Aimeos\MW\Mail\Message\Iface Message object |
|
46
|
|
|
*/ |
|
47
|
|
|
public function addFrom( string $email, string $name = null ) : Iface |
|
48
|
|
|
{ |
|
49
|
|
|
$this->object->addFrom( $email, $name ); |
|
50
|
|
|
return $this; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Adds a destination e-mail address of the target user mailbox. |
|
56
|
|
|
* |
|
57
|
|
|
* @param string $email Destination address of the target mailbox |
|
58
|
|
|
* @param string|null $name Name of the user owning the target mailbox or null for no name |
|
59
|
|
|
* @return \Aimeos\MW\Mail\Message\Iface Message object |
|
60
|
|
|
*/ |
|
61
|
|
|
public function addTo( string $email, string $name = null ) : Iface |
|
62
|
|
|
{ |
|
63
|
|
|
$this->object->addTo( $email, $name ); |
|
64
|
|
|
return $this; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Adds a destination e-mail address for a copy of the message. |
|
70
|
|
|
* |
|
71
|
|
|
* @param string $email Destination address for a copy |
|
72
|
|
|
* @param string|null $name Name of the user owning the target mailbox or null for no name |
|
73
|
|
|
* @return \Aimeos\MW\Mail\Message\Iface Message object |
|
74
|
|
|
*/ |
|
75
|
|
|
public function addCc( string $email, string $name = null ) : Iface |
|
76
|
|
|
{ |
|
77
|
|
|
$this->object->addCc( $email, $name ); |
|
78
|
|
|
return $this; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Adds a destination e-mail address for a hidden copy of the message. |
|
84
|
|
|
* |
|
85
|
|
|
* @param string $email Destination address for a hidden copy |
|
86
|
|
|
* @param string|null $name Name of the user owning the target mailbox or null for no name |
|
87
|
|
|
* @return \Aimeos\MW\Mail\Message\Iface Message object |
|
88
|
|
|
*/ |
|
89
|
|
|
public function addBcc( string $email, string $name = null ) : Iface |
|
90
|
|
|
{ |
|
91
|
|
|
$this->object->addBcc( $email, $name ); |
|
92
|
|
|
return $this; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Adds the return e-mail address for the message. |
|
98
|
|
|
* |
|
99
|
|
|
* @param string $email E-mail address which should receive all replies |
|
100
|
|
|
* @param string|null $name Name of the user which should receive all replies or null for no name |
|
101
|
|
|
* @return \Aimeos\MW\Mail\Message\Iface Message object |
|
102
|
|
|
*/ |
|
103
|
|
|
public function addReplyTo( string $email, string $name = null ) : Iface |
|
104
|
|
|
{ |
|
105
|
|
|
$this->object->addReplyTo( $email, $name ); |
|
106
|
|
|
return $this; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Adds a custom header to the message. |
|
112
|
|
|
* |
|
113
|
|
|
* @param string $name Name of the custom e-mail header |
|
114
|
|
|
* @param string $value Text content of the custom e-mail header |
|
115
|
|
|
* @return \Aimeos\MW\Mail\Message\Iface Message object |
|
116
|
|
|
*/ |
|
117
|
|
|
public function addHeader( string $name, string $value ) : Iface |
|
118
|
|
|
{ |
|
119
|
|
|
$hs = $this->object->getHeaders(); |
|
120
|
|
|
$hs->addTextHeader( $name, $value ); |
|
121
|
|
|
return $this; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Sends the e-mail message to the mail server. |
|
127
|
|
|
* |
|
128
|
|
|
* @return \Aimeos\MW\Mail\Message\Iface Message object |
|
129
|
|
|
*/ |
|
130
|
|
|
public function send() : Iface |
|
131
|
|
|
{ |
|
132
|
|
|
$this->object->send(); |
|
133
|
|
|
return $this; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* Sets the e-mail address and name of the sender of the message (higher precedence than "From"). |
|
139
|
|
|
* |
|
140
|
|
|
* @param string $email Source e-mail address |
|
141
|
|
|
* @param string|null $name Name of the user who sent the message or null for no name |
|
142
|
|
|
* @return \Aimeos\MW\Mail\Message\Iface Message object |
|
143
|
|
|
*/ |
|
144
|
|
|
public function setSender( string $email, string $name = null ) : Iface |
|
145
|
|
|
{ |
|
146
|
|
|
$this->object->setSender( $email, $name ); |
|
147
|
|
|
return $this; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* Sets the subject of the message. |
|
153
|
|
|
* |
|
154
|
|
|
* @param string $subject Subject of the message |
|
155
|
|
|
* @return \Aimeos\MW\Mail\Message\Iface Message object |
|
156
|
|
|
*/ |
|
157
|
|
|
public function setSubject( string $subject ) : Iface |
|
158
|
|
|
{ |
|
159
|
|
|
$this->object->setSubject( $subject ); |
|
160
|
|
|
return $this; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* Sets the text body of the message. |
|
166
|
|
|
* |
|
167
|
|
|
* @param string $message Text body of the message |
|
168
|
|
|
* @return \Aimeos\MW\Mail\Message\Iface Message object |
|
169
|
|
|
*/ |
|
170
|
|
|
public function setBody( string $message ) : Iface |
|
171
|
|
|
{ |
|
172
|
|
|
$this->object->setBody( $message ); |
|
173
|
|
|
return $this; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* Sets the HTML body of the message. |
|
179
|
|
|
* |
|
180
|
|
|
* @param string $message HTML body of the message |
|
181
|
|
|
* @return \Aimeos\MW\Mail\Message\Iface Message object |
|
182
|
|
|
*/ |
|
183
|
|
|
public function setBodyHtml( string $message ) : Iface |
|
184
|
|
|
{ |
|
185
|
|
|
$this->object->addPart( $message, 'text/html' ); |
|
186
|
|
|
return $this; |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
|
|
190
|
|
|
/** |
|
191
|
|
|
* Adds an attachment to the message. |
|
192
|
|
|
* |
|
193
|
|
|
* @param string $data Binary or string |
|
194
|
|
|
* @param string $mimetype Mime type of the attachment (e.g. "text/plain", "application/octet-stream", etc.) |
|
195
|
|
|
* @param string|null $filename Name of the attached file (or null if inline disposition is used) |
|
196
|
|
|
* @param string $disposition Type of the disposition ("attachment" or "inline") |
|
197
|
|
|
* @return \Aimeos\MW\Mail\Message\Iface Message object |
|
198
|
|
|
*/ |
|
199
|
|
|
public function addAttachment( string $data, string $mimetype, string $filename, string $disposition = 'attachment' ) : Iface |
|
200
|
|
|
{ |
|
201
|
|
|
$part = \Swift_Attachment::newInstance( $data, $filename, $mimetype ); |
|
202
|
|
|
$part->setDisposition( $disposition ); |
|
203
|
|
|
|
|
204
|
|
|
$this->object->attach( $part ); |
|
205
|
|
|
return $this; |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
|
|
209
|
|
|
/** |
|
210
|
|
|
* Embeds an attachment into the message and returns its reference. |
|
211
|
|
|
* |
|
212
|
|
|
* @param string $data Binary or string |
|
213
|
|
|
* @param string $mimetype Mime type of the attachment (e.g. "text/plain", "application/octet-stream", etc.) |
|
214
|
|
|
* @param string|null $filename Name of the attached file |
|
215
|
|
|
* @return string Content ID for referencing the attachment in the HTML body |
|
216
|
|
|
*/ |
|
217
|
|
|
public function embedAttachment( string $data, string $mimetype, string $filename ) : string |
|
218
|
|
|
{ |
|
219
|
|
|
$part = \Swift_EmbeddedFile::newInstance( $data, $mimetype, $filename ); |
|
220
|
|
|
|
|
221
|
|
|
return $this->object->embed( $part ); |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
|
|
225
|
|
|
/** |
|
226
|
|
|
* Returns the internal TYPO3 mail message object. |
|
227
|
|
|
* |
|
228
|
|
|
* @return TYPO3\CMS\Core\Mail\MailMessage TYPO3 mail message object |
|
|
|
|
|
|
229
|
|
|
*/ |
|
230
|
|
|
public function getObject() : \TYPO3\CMS\Core\Mail\MailMessage |
|
231
|
|
|
{ |
|
232
|
|
|
return $this->object; |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
|
|
236
|
|
|
/** |
|
237
|
|
|
* Clones the internal objects. |
|
238
|
|
|
*/ |
|
239
|
|
|
public function __clone() |
|
240
|
|
|
{ |
|
241
|
|
|
$this->object = clone $this->object; |
|
242
|
|
|
} |
|
243
|
|
|
} |
|
244
|
|
|
|