@@ -20,7 +20,7 @@ class Message implements MailMessageInterface
2020 *
2121 * @var string
2222 */
23- private $ messageType = self ::TYPE_TEXT ;
23+ private $ messageType = Mime ::TYPE_TEXT ;
2424
2525 /**
2626 * Initialize dependencies.
@@ -55,8 +55,8 @@ public function setMessageType($type)
5555 */
5656 public function setBody ($ body )
5757 {
58- if (is_string ($ body ) && $ this -> messageType === MailMessageInterface:: TYPE_HTML ) {
59- $ body = $ this ->createHtmlMimeFromString ($ body );
58+ if (is_string ($ body )) {
59+ $ body = $ this ->createMimeFromString ($ body, $ this -> messageType );
6060 }
6161 $ this ->zendMessage ->setBody ($ body );
6262 return $ this ;
@@ -158,7 +158,7 @@ public function getRawMessage()
158158 */
159159 public function setBodyHtml ($ html )
160160 {
161- $ this ->setMessageType (self ::TYPE_HTML );
161+ $ this ->setMessageType (Mime ::TYPE_HTML );
162162 return $ this ->setBody ($ html );
163163 }
164164
@@ -167,7 +167,7 @@ public function setBodyHtml($html)
167167 */
168168 public function setBodyText ($ text )
169169 {
170- $ this ->setMessageType (self ::TYPE_TEXT );
170+ $ this ->setMessageType (Mime ::TYPE_TEXT );
171171 return $ this ->setBody ($ text );
172172 }
173173
@@ -176,6 +176,10 @@ public function setBodyText($text)
176176 *
177177 * @param string $htmlBody
178178 * @return \Zend\Mime\Message
179+ *
180+ * @deprecated All emails that Magento sends should be mime encoded. Therefore
181+ * use generic function createMimeFromString
182+ * @see createMimeFromString()
179183 */
180184 private function createHtmlMimeFromString ($ htmlBody )
181185 {
@@ -186,4 +190,21 @@ private function createHtmlMimeFromString($htmlBody)
186190 $ mimeMessage ->addPart ($ htmlPart );
187191 return $ mimeMessage ;
188192 }
193+
194+ /**
195+ * Create mime message from the string.
196+ *
197+ * @param string $body
198+ * @param string $messageType
199+ * @return \Zend\Mime\Message
200+ */
201+ private function createMimeFromString ($ body , $ messageType )
202+ {
203+ $ part = new Part ($ body );
204+ $ part ->setCharset ($ this ->zendMessage ->getEncoding ());
205+ $ part ->setType ($ messageType );
206+ $ mimeMessage = new \Zend \Mime \Message ();
207+ $ mimeMessage ->addPart ($ part );
208+ return $ mimeMessage ;
209+ }
189210}
0 commit comments