Completed
Push — 2016.04 ( 690368...e61816 )
by Aimeos
04:37
created

Typo3::getObject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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
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, $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( $email, $name = null )
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( $email, $name = null )
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( $email, $name = null )
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( $email, $name = null )
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( $email, $name = null )
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( $name, $value )
118
	{
119
		$hs = $this->object->getHeaders();
120
		$hs->addTextHeader( $name, $value );
121
		return $this;
122
	}
123
124
125
	/**
126
	 * Sets the e-mail address and name of the sender of the message (higher precedence than "From").
127
	 *
128
	 * @param string $email Source e-mail address
129
	 * @param string|null $name Name of the user who sent the message or null for no name
130
	 * @return \Aimeos\MW\Mail\Message\Iface Message object
131
	 */
132
	public function setSender( $email, $name = null )
133
	{
134
		$this->object->setSender( $email, $name );
135
		return $this;
136
	}
137
138
139
	/**
140
	 * Sets the subject of the message.
141
	 *
142
	 * @param string $subject Subject of the message
143
	 * @return \Aimeos\MW\Mail\Message\Iface Message object
144
	 */
145
	public function setSubject( $subject )
146
	{
147
		$this->object->setSubject( $subject );
148
		return $this;
149
	}
150
151
152
	/**
153
	 * Sets the text body of the message.
154
	 *
155
	 * @param string $message Text body of the message
156
	 * @return \Aimeos\MW\Mail\Message\Iface Message object
157
	 */
158
	public function setBody( $message )
159
	{
160
		$this->object->setBody( $message );
161
		return $this;
162
	}
163
164
165
	/**
166
	 * Sets the HTML body of the message.
167
	 *
168
	 * @param string $message HTML body of the message
169
	 * @return \Aimeos\MW\Mail\Message\Iface Message object
170
	 */
171
	public function setBodyHtml( $message )
172
	{
173
		$this->object->addPart( $message, 'text/html' );
174
		return $this;
175
	}
176
177
178
	/**
179
	 * Adds an attachment to the message.
180
	 *
181
	 * @param string $data Binary or string
182
	 * @param string $mimetype Mime type of the attachment (e.g. "text/plain", "application/octet-stream", etc.)
183
	 * @param string|null $filename Name of the attached file (or null if inline disposition is used)
184
	 * @param string $disposition Type of the disposition ("attachment" or "inline")
185
	 * @return \Aimeos\MW\Mail\Message\Iface Message object
186
	 */
187
	public function addAttachment( $data, $mimetype, $filename, $disposition = 'attachment' )
188
	{
189
		$part = Swift_Attachment::newInstance( $data, $filename, $mimetype );
190
		$part->setDisposition( $disposition );
191
192
		$this->object->attach( $part );
193
		return $this;
194
	}
195
196
197
	/**
198
	 * Embeds an attachment into the message and returns its reference.
199
	 *
200
	 * @param string $data Binary or string
201
	 * @param string $mimetype Mime type of the attachment (e.g. "text/plain", "application/octet-stream", etc.)
202
	 * @param string|null $filename Name of the attached file
203
	 * @return string Content ID for referencing the attachment in the HTML body
204
	 */
205
	public function embedAttachment( $data, $mimetype, $filename )
206
	{
207
		$part = Swift_EmbeddedFile::newInstance( $data, $mimetype, $filename );
208
209
		return $this->object->embed( $part );
210
	}
211
212
213
	/**
214
	 * Returns the internal TYPO3 mail message object.
215
	 *
216
	 * @return TYPO3\CMS\Core\Mail\MailMessage TYPO3 mail message object
217
	 */
218
	public function getObject()
219
	{
220
		return $this->object;
221
	}
222
223
224
	/**
225
	 * Clones the internal objects.
226
	 */
227
	public function __clone()
228
	{
229
		$this->object = clone $this->object;
230
	}
231
}
232