@@ -23,7 +23,7 @@ class Message implements MailMessageInterface
23
23
*
24
24
* @var string
25
25
*/
26
- private $ messageType = self ::TYPE_TEXT ;
26
+ private $ messageType = Mime ::TYPE_TEXT ;
27
27
28
28
/**
29
29
* Initialize dependencies.
@@ -58,8 +58,8 @@ public function setMessageType($type)
58
58
*/
59
59
public function setBody ($ body )
60
60
{
61
- if (is_string ($ body ) && $ this -> messageType === MailMessageInterface:: TYPE_HTML ) {
62
- $ body = self ::createHtmlMimeFromString ($ body );
61
+ if (is_string ($ body )) {
62
+ $ body = self ::createMimeFromString ($ body, $ this -> messageType );
63
63
}
64
64
$ this ->zendMessage ->setBody ($ body );
65
65
return $ this ;
@@ -161,6 +161,10 @@ public function getRawMessage()
161
161
*
162
162
* @param string $htmlBody
163
163
* @return \Zend\Mime\Message
164
+ *
165
+ * @deprecated All emails that Magento sends should be mime encoded. Therefore
166
+ * use generic function createMimeFromString
167
+ * @see createMimeFromString()
164
168
*/
165
169
private function createHtmlMimeFromString ($ htmlBody )
166
170
{
@@ -172,12 +176,29 @@ private function createHtmlMimeFromString($htmlBody)
172
176
return $ mimeMessage ;
173
177
}
174
178
179
+ /**
180
+ * Create mime message from the string.
181
+ *
182
+ * @param string $body
183
+ * @param string $messageType
184
+ * @return \Zend\Mime\Message
185
+ */
186
+ private function createMimeFromString ($ body , $ messageType )
187
+ {
188
+ $ part = new Part ($ body );
189
+ $ part ->setCharset ($ this ->zendMessage ->getEncoding ());
190
+ $ part ->setType ($ messageType );
191
+ $ mimeMessage = new \Zend \Mime \Message ();
192
+ $ mimeMessage ->addPart ($ part );
193
+ return $ mimeMessage ;
194
+ }
195
+
175
196
/**
176
197
* @inheritdoc
177
198
*/
178
199
public function setBodyHtml ($ html )
179
200
{
180
- $ this ->setMessageType (self ::TYPE_HTML );
201
+ $ this ->setMessageType (Mime ::TYPE_HTML );
181
202
return $ this ->setBody ($ html );
182
203
}
183
204
@@ -186,7 +207,7 @@ public function setBodyHtml($html)
186
207
*/
187
208
public function setBodyText ($ text )
188
209
{
189
- $ this ->setMessageType (self ::TYPE_TEXT );
210
+ $ this ->setMessageType (Mime ::TYPE_TEXT );
190
211
return $ this ->setBody ($ text );
191
212
}
192
213
}
0 commit comments