1313
1414namespace phpbb \messenger \method ;
1515
16+ use Symfony \Component \Mailer \Exception \TransportExceptionInterface ;
17+ use Symfony \Component \Mailer \MailerInterface ;
1618use Symfony \Component \Mailer \Transport ;
1719use Symfony \Component \Mailer \Mailer ;
20+ use Symfony \Component \Mailer \Transport \AbstractTransport ;
21+ use Symfony \Component \Mailer \Transport \TransportInterface ;
1822use Symfony \Component \Mime \Address ;
1923use Symfony \Component \Mime \Email as symfony_email ;
2024use Symfony \Component \Mime \Header \Headers ;
@@ -38,16 +42,16 @@ class email extends base
3842 *
3943 * Symfony Mailer transport DSN
4044 */
41- protected $ dsn = '' ;
45+ protected string $ dsn = '' ;
4246
4347 /** @var symfony_email */
44- protected $ email ;
48+ protected symfony_email $ email ;
4549
46- /** @var Address */
47- protected $ from ;
50+ /** @var Address From address */
51+ protected Address $ from ;
4852
49- /** @var Headers */
50- protected $ headers ;
53+ /** @var Headers Email headers */
54+ protected Headers $ headers ;
5155
5256 /**
5357 * @var int
@@ -59,16 +63,16 @@ class email extends base
5963 * symfony_email::PRIORITY_LOW
6064 * symfony_email::PRIORITY_LOWEST
6165 */
62- protected $ mail_priority = symfony_email::PRIORITY_NORMAL ;
66+ protected int $ mail_priority = symfony_email::PRIORITY_NORMAL ;
6367
6468 /** @var \phpbb\messenger\queue */
6569 protected $ queue ;
6670
6771 /** @var Address */
68- protected $ reply_to ;
72+ protected Address $ reply_to ;
6973
70- /** @var \Symfony\Component\Mailer\Transport\ AbstractTransport */
71- protected $ transport ;
74+ /** @var AbstractTransport */
75+ protected AbstractTransport $ transport ;
7276
7377 /**
7478 * {@inheritDoc}
@@ -124,7 +128,7 @@ public function set_addresses(array $user_row): void
124128 {
125129 if (!empty ($ user_row ['user_email ' ]))
126130 {
127- $ this ->to ($ user_row ['user_email ' ], $ user_row ['username ' ] ?: '' );
131+ $ this ->to ($ user_row ['user_email ' ], $ user_row ['username ' ] ?? '' );
128132 }
129133 }
130134
@@ -142,10 +146,7 @@ public function to(string $address, string $realname = ''): void
142146 return ;
143147 }
144148
145- // If empty sendmail_path on windows, PHP changes the to line
146- $ windows_empty_sendmail_path = !$ this ->config ['smtp_delivery ' ] && DIRECTORY_SEPARATOR == '\\' ;
147-
148- $ to = new Address ($ address , $ windows_empty_sendmail_path ? '' : trim ($ realname ));
149+ $ to = new Address ($ address , trim ($ realname ));
149150 $ this ->email ->getTo () ? $ this ->email ->addTo ($ to ) : $ this ->email ->to ($ to );
150151 }
151152
@@ -273,7 +274,6 @@ public function set_mail_priority(int $priority = symfony_email::PRIORITY_NORMAL
273274 */
274275 protected function build_headers (): void
275276 {
276-
277277 $ board_contact = trim ($ this ->config ['board_contact ' ]);
278278 $ contact_name = html_entity_decode ($ this ->config ['board_contact_name ' ], ENT_COMPAT );
279279
@@ -315,7 +315,6 @@ protected function build_headers(): void
315315 {
316316 $ this ->header ($ header , $ value );
317317 }
318-
319318 }
320319
321320 /**
@@ -406,7 +405,7 @@ public function process_queue(array &$queue_data): void
406405
407406 $ package_size = $ queue_data [$ queue_object_name ]['package_size ' ] ?? 0 ;
408407 $ num_items = (!$ package_size || $ messages_count < $ package_size ) ? $ messages_count : $ package_size ;
409- $ mailer = new Mailer ( $ this ->transport );
408+ $ mailer = $ this ->get_mailer ( );
410409
411410 for ($ i = 0 ; $ i < $ num_items ; $ i ++)
412411 {
@@ -435,7 +434,7 @@ public function process_queue(array &$queue_data): void
435434 {
436435 $ mailer ->send ($ email );
437436 }
438- catch (\ Symfony \ Component \ Mailer \ Exception \ TransportExceptionInterface $ e )
437+ catch (TransportExceptionInterface $ e )
439438 {
440439 $ this ->error ($ e ->getDebug ());
441440 continue ;
@@ -450,12 +449,22 @@ public function process_queue(array &$queue_data): void
450449 }
451450 }
452451
452+ /**
453+ * Get mailer object
454+ *
455+ * @return MailerInterface Symfony Mailer object
456+ */
457+ protected function get_mailer (): MailerInterface
458+ {
459+ return new Mailer ($ this ->transport );
460+ }
461+
453462 /**
454463 * Get mailer transport object
455464 *
456- * @return \Symfony\Component\Mailer\Transport\ TransportInterface Symfony Mailer transport object
465+ * @return TransportInterface Symfony Mailer transport object
457466 */
458- public function get_transport (): \ Symfony \ Component \ Mailer \ Transport \ TransportInterface
467+ public function get_transport (): TransportInterface
459468 {
460469 return $ this ->transport ;
461470 }
@@ -504,7 +513,7 @@ public function send(): bool
504513 // Send message ...
505514 if (!$ this ->use_queue )
506515 {
507- $ mailer = new Mailer ( $ this ->transport );
516+ $ mailer = $ this ->get_mailer ( );
508517
509518 $ subject = $ this ->subject ;
510519 $ msg = $ this ->msg ;
@@ -538,7 +547,7 @@ public function send(): bool
538547 {
539548 $ mailer ->send ($ this ->email );
540549 }
541- catch (\ Symfony \ Component \ Mailer \ Exception \ TransportExceptionInterface $ e )
550+ catch (TransportExceptionInterface $ e )
542551 {
543552 $ this ->error ($ e ->getDebug ());
544553 return false ;
0 commit comments