2323use Symfony \Component \HttpFoundation \RequestStack ;
2424use Symfony \Component \Mime \Address ;
2525use Symfony \Component \Mime \Email ;
26- use Symfony \Component \Routing \Annotation \Route ;
26+ use Symfony \Component \Routing \Attribute \Route ;
2727use ZBateson \MailMimeParser \Header \AddressHeader ;
2828use ZBateson \MailMimeParser \Header \DateHeader ;
2929use ZBateson \MailMimeParser \Header \IHeader ;
@@ -37,13 +37,14 @@ class MailArchiveController extends AbstractController
3737 * @param EntityRepository<EntityCollection<MailArchiveAttachmentEntity>> $froshMailArchiveAttachmentRepository
3838 */
3939 public function __construct (
40- private readonly EntityRepository $ froshMailArchiveRepository ,
41- private readonly EntityRepository $ froshMailArchiveAttachmentRepository ,
40+ private readonly EntityRepository $ froshMailArchiveRepository ,
41+ private readonly EntityRepository $ froshMailArchiveAttachmentRepository ,
4242 #[Autowire(service: MailSender::class)]
4343 private readonly AbstractMailSender $ mailSender ,
44- private readonly RequestStack $ requestStack ,
45- private readonly EmlFileManager $ emlFileManager ,
46- ) {}
44+ private readonly RequestStack $ requestStack ,
45+ private readonly EmlFileManager $ emlFileManager ,
46+ ) {
47+ }
4748
4849 #[Route(path: '/api/_action/frosh-mail-archive/resend-mail ' , name: 'api.action.frosh-mail-archive.resend-mail ' )]
4950 public function resend (Request $ request , Context $ context ): JsonResponse
@@ -68,7 +69,7 @@ public function resend(Request $request, Context $context): JsonResponse
6869
6970 $ email = new Email ();
7071 $ emlPath = $ mailArchive ->getEmlPath ();
71- $ isEml = ! empty ( $ emlPath) && \is_string ($ emlPath );
72+ $ isEml = $ emlPath !== '' && $ emlPath !== ' 0 ' && \is_string ($ emlPath );
7273
7374 if ($ isEml ) {
7475 $ this ->enrichFromEml ($ emlPath , $ email );
@@ -110,7 +111,7 @@ public function download(Request $request, Context $context): JsonResponse
110111
111112 $ fileNameParts = [];
112113
113- if ($ mailArchive ->getCreatedAt () !== null ) {
114+ if ($ mailArchive ->getCreatedAt () instanceof \DateTimeInterface ) {
114115 $ fileNameParts [] = $ mailArchive ->getCreatedAt ()->format ('Y-m-d_H-i-s ' );
115116 }
116117
@@ -147,7 +148,7 @@ public function attachment(Request $request, Context $context): JsonResponse
147148 }
148149
149150 $ emlPath = $ mailArchive ->getEmlPath ();
150- $ isEml = ! empty ( $ emlPath) && \is_string ($ emlPath );
151+ $ isEml = $ emlPath !== '' && $ emlPath !== ' 0 ' && \is_string ($ emlPath );
151152
152153 if (!$ isEml ) {
153154 throw new \RuntimeException ('Cannot read eml file or file is empty ' );
@@ -175,7 +176,7 @@ public function attachment(Request $request, Context $context): JsonResponse
175176
176177 $ fileNameParts = [];
177178
178- if ($ mailArchive ->getCreatedAt () !== null ) {
179+ if ($ mailArchive ->getCreatedAt () instanceof \DateTimeInterface ) {
179180 $ fileNameParts [] = $ mailArchive ->getCreatedAt ()->format ('Y-m-d_H-i-s ' );
180181 }
181182
@@ -250,7 +251,7 @@ private function enrichFromDatabase(MailArchiveEntity $mailArchive, Email $email
250251 /**
251252 * @return string|array<string|Address>|\DateTimeImmutable|null
252253 */
253- private function getHeaderValue (IHeader $ header ): string |array |null | \DateTimeImmutable
254+ private function getHeaderValue (IHeader $ header ): string |array |\DateTimeImmutable | null
254255 {
255256 if ($ header instanceof AddressHeader) {
256257 /** @var AddressPart[] $addressParts */
@@ -286,7 +287,7 @@ private function getFileName(array $fileNameParts): string
286287
287288 private function getContent (?string $ emlPath ): false |string
288289 {
289- if (empty ( $ emlPath) || !\is_string ($ emlPath )) {
290+ if ($ emlPath === '' || $ emlPath === ' 0 ' || !\is_string ($ emlPath )) {
290291 return false ;
291292 }
292293
@@ -299,7 +300,7 @@ private function getContent(?string $emlPath): false|string
299300 private function determineReturnPath (\DateTimeImmutable |array |string |null $ headerValue ): ?string
300301 {
301302 // Extract first item for return-path since Symfony/Mailer needs to be a string value here
302- if (is_array ($ headerValue )) {
303+ if (\ is_array ($ headerValue )) {
303304 $ headerValue = array_pop ($ headerValue );
304305 }
305306
@@ -309,15 +310,15 @@ private function determineReturnPath(\DateTimeImmutable|array|string|null $heade
309310 return $ headerValue ->getEncodedAddress ();
310311 }
311312
312- if (is_string ($ headerValue )) {
313+ if (\ is_string ($ headerValue )) {
313314 $ regex = '/[<"]([^<>"\s]+@[^<>"\s]+)[>"]/ ' ;
314315 preg_match ($ regex , $ headerValue , $ matches );
315316 if (isset ($ matches [1 ])) {
316317 $ headerValue = $ matches [1 ];
317318 }
318319 }
319320
320- if (is_string ($ headerValue )) {
321+ if (\ is_string ($ headerValue )) {
321322 try {
322323 return (new Address ($ headerValue ))->getEncodedAddress ();
323324 } catch (\Throwable ) {
0 commit comments