22
33namespace Aitoc \Smtp \Model \Framework \Mail ;
44
5- use Magento \Framework \Exception \MailException ;
6- use Magento \Framework \Phrase ;
7- use Zend \Mail \Message as ZendMessage ;
8- use Zend \Mail \Address ;
9- use Zend \Mail \Transport \Smtp ;
10- use Magento \Framework \Mail \MessageInterface ;
11- use Magento \Email \Model \Template \SenderResolver ;
5+ use Aitoc \Smtp \Controller \RegistryConstants ;
126use Aitoc \Smtp \Model \Config ;
13- use Zend \Mail \Transport \SmtpOptions ;
14- use Aitoc \Smtp \Model \Resolver \From ;
15- use Aitoc \Smtp \Model \LogFactory ;
167use Aitoc \Smtp \Model \Config \Options \Status ;
8+ use Aitoc \Smtp \Model \LogFactory ;
9+ use Aitoc \Smtp \Model \Resolver \From ;
10+ use Magento \Email \Model \Template \SenderResolver ;
11+ use Magento \Framework \Exception \MailException ;
12+ use Magento \Framework \Mail \MessageInterface ;
13+ use Magento \Framework \Phrase ;
1714use Magento \Framework \Registry ;
18- use Aitoc \Smtp \Controller \RegistryConstants ;
19- use Zend_Mail_Transport_Smtp ;
2015
2116class Transport implements \Magento \Framework \Mail \TransportInterface
2217{
@@ -26,9 +21,9 @@ class Transport implements \Magento\Framework\Mail\TransportInterface
2621 "Now, your store uses an Aitoc SMTP. Please, hit ‘Save Config’ to use this connection. " ;
2722
2823 /**
29- * @var Sendmail
24+ * @var \Laminas\Mail\Transport\Smtp
3025 */
31- private $ zendTransport ;
26+ private $ smtp ;
3227
3328 /**
3429 * @var MessageInterface
@@ -80,13 +75,7 @@ public function __construct(
8075 $ this ->fromResolver = $ from ;
8176 $ this ->logFactory = $ logFactory ;
8277 $ this ->registry = $ registry ;
83-
84- if ($ this ->aitConfig ->isNewSender (RegistryConstants::VERSION_COMPARISON_OLD_MAIL )) {
85- $ this ->zendTransport = new Smtp ($ this ->prepareOptions ($ config ));
86- } else {
87- $ this ->zendTransport = new Zend_Mail_Transport_Smtp ($ config ['host ' ], $ config );
88- }
89-
78+ $ this ->smtp = new \Laminas \Mail \Transport \Smtp ($ this ->prepareOptions ($ config ));
9079 $ this ->message = $ message ;
9180 $ this ->setFrom ();
9281 }
@@ -97,13 +86,13 @@ public function __construct(
9786 public function setFrom ()
9887 {
9988 $ fromData = $ this ->fromResolver ->getFrom ();
100- $ message = ZendMessage ::fromString ($ this ->message ->getRawMessage ());
89+ $ message = \ Laminas \ Mail \Message ::fromString ($ this ->message ->getRawMessage ());
10190
10291 if ($ fromData ) {
103- if (($ message instanceof ZendMessage && !$ message ->getFrom ()->count ())
104- || (( is_array ( $ message -> getHeaders ()) && !array_key_exists ("From " , $ message ->getHeaders ())))
92+ if (($ message instanceof \ Laminas \ Mail \Message && !$ message ->getFrom ()->count ())
93+ || (!array_key_exists ("From " , $ message ->getHeaders ()-> toArray ( )))
10594 ) {
106- $ this ->message ->setFrom ($ this ->aitConfig ->getNewAddress ($ fromData ));
95+ $ this ->message ->setFromAddress ($ this ->aitConfig ->getNewAddress ($ fromData ));
10796 }
10897 }
10998
@@ -112,23 +101,20 @@ public function setFrom()
112101
113102 /**
114103 * @param $config
115- * @return SmtpOptions
104+ * @return \Laminas\Mail\Transport\ SmtpOptions
116105 */
117106 private function prepareOptions ($ config )
118107 {
119108 if (!isset ($ config ['name ' ]) || !$ config ['name ' ]) {
120109 $ config ['name ' ] = self ::DEFAULT_LOCAL_CLIENT_HOSTNAME ;
121110 }
122111
123- $ options = new SmtpOptions ([
124- 'name ' => isset ($ config ['name ' ]) ? $ config ['name ' ] : '' ,
125- 'host ' => isset ($ config ['host ' ]) ? $ config ['host ' ] : '' ,
126- 'port ' => isset ($ config ['port ' ]) ? $ config ['port ' ] : 465 ,
127- ]);
128-
112+ $ options = new \Laminas \Mail \Transport \SmtpOptions ();
113+ $ options ->setName ($ config ['name ' ] ?? '' );
114+ $ options ->setHost ($ config ['host ' ] ?? '' );
115+ $ options ->setPort ($ config ['port ' ] ?? 465 );
129116 $ connectionConfig = [];
130117
131-
132118 if (isset ($ config ['auth ' ]) && $ config ['auth ' ] != '' ) {
133119 $ options ->setConnectionClass ($ config ['auth ' ]);
134120 $ connectionConfig = [
@@ -159,7 +145,7 @@ public function sendMessage()
159145 $ this ->message = $ this ->aitConfig ->prepareMessageToSend ($ this ->getMessage ());
160146
161147 if ($ this ->aitConfig ->isNewSender (RegistryConstants::VERSION_COMPARISON_OLD_MAIL )) {
162- $ message = ZendMessage ::fromString ($ this ->message ->getRawMessage ())->setEncoding ('utf-8 ' );
148+ $ message = \ Laminas \ Mail \Message ::fromString ($ this ->message ->getRawMessage ())->setEncoding ('utf-8 ' );
163149 } else {
164150 $ message = $ this ->message ;
165151 }
@@ -182,7 +168,9 @@ public function sendMessage()
182168 $ message = $ modifiedRecipient ;
183169 }
184170
185- $ this ->zendTransport ->send ($ message );
171+ if ($ message ) {
172+ $ this ->smtp ->send ($ message );
173+ }
186174
187175 if (!$ logDisabled ) {
188176 $ this ->getLoger ()->log ($ message );
@@ -209,12 +197,12 @@ private function getLoger()
209197 }
210198
211199 /**
212- * @return bool|ZendMessage
200+ * @return bool|\Laminas\Mail\Message
213201 */
214202 public function modifyTo ()
215203 {
216204 if ($ this ->aitConfig ->isNewSender (RegistryConstants::VERSION_COMPARISON_OLD_MAIL )) {
217- $ message = ZendMessage ::fromString ($ this ->message ->getRawMessage ())->setEncoding ('utf-8 ' );
205+ $ message = \ Laminas \ Mail \Message ::fromString ($ this ->message ->getRawMessage ())->setEncoding ('utf-8 ' );
218206 } else {
219207 $ message = $ this ->message ;
220208 }
@@ -226,7 +214,7 @@ public function modifyTo()
226214 if ($ toEmails ) {
227215 foreach ($ toEmails as $ email ) {
228216 $ name = '' ;
229- if ($ email instanceof Address) {
217+ if ($ email instanceof \ Laminas \ Mail \ Address \AddressInterface ) {
230218 $ name = $ email ->getName ();
231219 $ email = $ email ->getEmail ();
232220 }
@@ -268,12 +256,12 @@ public function testSend($to)
268256 ->setBodyText (__ (self ::TEST_MESSAGE_BODY ));
269257
270258 if ($ this ->aitConfig ->isNewSender (RegistryConstants::VERSION_COMPARISON_OLD_MAIL )) {
271- $ message = ZendMessage ::fromString ($ this ->message ->getRawMessage ())->setEncoding ('utf-8 ' );
259+ $ message = \ Laminas \ Mail \Message ::fromString ($ this ->message ->getRawMessage ())->setEncoding ('utf-8 ' );
272260 } else {
273261 $ message = $ this ->message ;
274262 }
275263
276- $ this ->zendTransport ->send ($ message );
264+ $ this ->smtp ->send ($ message );
277265
278266 return $ result ;
279267 } catch (\Exception $ e ) {
0 commit comments