1414use In2code \Powermail \Utility \TypoScriptUtility ;
1515use TYPO3 \CMS \Core \Mail \MailMessage ;
1616use TYPO3 \CMS \Core \TypoScript \TypoScriptService ;
17+ use TYPO3 \CMS \Core \Utility \ArrayUtility as ArrayUtilityCore ;
1718use TYPO3 \CMS \Core \Utility \GeneralUtility ;
1819use TYPO3 \CMS \Extbase \Configuration \Exception \InvalidConfigurationTypeException ;
19- use TYPO3 \CMS \Extbase \Mvc \Exception \InvalidControllerNameException ;
2020use TYPO3 \CMS \Extbase \Mvc \Exception \InvalidExtensionNameException ;
2121use TYPO3 \CMS \Extbase \Object \Exception ;
2222use TYPO3 \CMS \Extbase \SignalSlot \Exception \InvalidSlotException ;
@@ -73,7 +73,6 @@ class SendMailService
7373 * @param string $type Email to "sender" or "receiver"
7474 * @return bool Mail successfully sent
7575 * @throws InvalidConfigurationTypeException
76- * @throws InvalidControllerNameException
7776 * @throws InvalidExtensionNameException
7877 * @throws InvalidSlotException
7978 * @throws InvalidSlotReturnException
@@ -102,15 +101,14 @@ public function sendMail(array $email, Mail $mail, array $settings, string $type
102101 * @param array $email
103102 * @return bool
104103 * @throws InvalidConfigurationTypeException
105- * @throws InvalidControllerNameException
106104 * @throws InvalidExtensionNameException
107105 * @throws InvalidSlotException
108106 * @throws InvalidSlotReturnException
109107 * @throws Exception
110108 */
111109 protected function prepareAndSend (array $ email ): bool
112110 {
113- $ message = ObjectUtility:: getObjectManager ()-> get (MailMessage::class);
111+ $ message = GeneralUtility:: makeInstance (MailMessage::class);
114112 $ message
115113 ->setTo ([$ email ['receiverEmail ' ] => $ email ['receiverName ' ]])
116114 ->setFrom ([$ email ['senderEmail ' ] => $ email ['senderName ' ]])
@@ -156,8 +154,8 @@ protected function prepareAndSend(array $email): bool
156154 protected function addCc (MailMessage $ message ): MailMessage
157155 {
158156 $ ccValue = ObjectUtility::getContentObject ()->cObjGetSingle (
159- $ this ->overwriteConfig ['cc ' ]?? '' ,
160- $ this ->overwriteConfig ['cc. ' ]?? []
157+ $ this ->overwriteConfig ['cc ' ] ?? '' ,
158+ $ this ->overwriteConfig ['cc. ' ] ?? []
161159 );
162160 if (!empty ($ ccValue )) {
163161 $ message ->setCc (GeneralUtility::trimExplode (', ' , $ ccValue , true ));
@@ -175,8 +173,8 @@ protected function addCc(MailMessage $message): MailMessage
175173 protected function addBcc (MailMessage $ message ): MailMessage
176174 {
177175 $ bccValue = ObjectUtility::getContentObject ()->cObjGetSingle (
178- $ this ->overwriteConfig ['bcc ' ]?? '' ,
179- $ this ->overwriteConfig ['bcc. ' ]?? []
176+ $ this ->overwriteConfig ['bcc ' ] ?? '' ,
177+ $ this ->overwriteConfig ['bcc. ' ] ?? []
180178 );
181179 if (!empty ($ bccValue )) {
182180 $ message ->setBcc (GeneralUtility::trimExplode (', ' , $ bccValue , true ));
@@ -194,8 +192,8 @@ protected function addBcc(MailMessage $message): MailMessage
194192 protected function addReturnPath (MailMessage $ message ): MailMessage
195193 {
196194 $ returnPathValue = ObjectUtility::getContentObject ()->cObjGetSingle (
197- $ this ->overwriteConfig ['returnPath ' ]?? '' ,
198- $ this ->overwriteConfig ['returnPath. ' ]?? []
195+ $ this ->overwriteConfig ['returnPath ' ] ?? '' ,
196+ $ this ->overwriteConfig ['returnPath. ' ] ?? []
199197 );
200198 if (!empty ($ returnPathValue )) {
201199 $ message ->setReturnPath ($ returnPathValue );
@@ -221,11 +219,7 @@ protected function addReplyAddresses(MailMessage $message): MailMessage
221219 $ this ->overwriteConfig ['replyToName. ' ]??[]
222220 );
223221 if (!empty ($ replyToEmail ) && !empty ($ replyToName )) {
224- $ message ->setReplyTo (
225- [
226- $ replyToEmail => $ replyToName
227- ]
228- );
222+ $ message ->setReplyTo ([$ replyToEmail => $ replyToName ]);
229223 }
230224 return $ message ;
231225 }
@@ -260,7 +254,7 @@ protected function addAttachmentsFromUploads(MailMessage $message): MailMessage
260254 {
261255 if (!empty ($ this ->settings [$ this ->type ]['attachment ' ]) && !empty ($ this ->settings ['misc ' ]['file ' ]['folder ' ])) {
262256 /** @var UploadService $uploadService */
263- $ uploadService = ObjectUtility:: getObjectManager ()-> get (UploadService::class);
257+ $ uploadService = GeneralUtility:: makeInstance (UploadService::class);
264258 foreach ($ uploadService ->getFiles () as $ file ) {
265259 if ($ file ->isUploaded () && $ file ->isValid () && $ file ->isFileExisting ()) {
266260 $ message ->attachFromPath ($ file ->getNewPathAndFilename (true ));
@@ -303,7 +297,6 @@ protected function addAttachmentsFromTypoScript(MailMessage $message): MailMessa
303297 * @param array $email
304298 * @return MailMessage
305299 * @throws InvalidConfigurationTypeException
306- * @throws InvalidControllerNameException
307300 * @throws InvalidExtensionNameException
308301 * @throws InvalidSlotException
309302 * @throws InvalidSlotReturnException
@@ -322,7 +315,6 @@ protected function addHtmlBody(MailMessage $message, array $email): MailMessage
322315 * @param array $email
323316 * @return MailMessage
324317 * @throws InvalidConfigurationTypeException
325- * @throws InvalidControllerNameException
326318 * @throws InvalidExtensionNameException
327319 * @throws InvalidSlotException
328320 * @throws InvalidSlotReturnException
@@ -331,7 +323,7 @@ protected function addHtmlBody(MailMessage $message, array $email): MailMessage
331323 protected function addPlainBody (MailMessage $ message , array $ email ): MailMessage
332324 {
333325 if ($ email ['format ' ] !== 'html ' ) {
334- $ plaintextService = ObjectUtility:: getObjectManager ()-> get (PlaintextService::class);
326+ $ plaintextService = GeneralUtility:: makeInstance (PlaintextService::class);
335327 $ message ->text ($ plaintextService ->makePlain ($ this ->createEmailBody ($ email )), FrontendUtility::getCharset ());
336328 }
337329 return $ message ;
@@ -372,7 +364,6 @@ protected function addSenderHeader(MailMessage $message): MailMessage
372364 /**
373365 * @param array $email
374366 * @return string
375- * @throws InvalidControllerNameException
376367 * @throws InvalidSlotException
377368 * @throws InvalidSlotReturnException
378369 * @throws InvalidConfigurationTypeException
@@ -386,7 +377,7 @@ protected function createEmailBody(array $email): string
386377 $ standaloneView ->setTemplatePathAndFilename (TemplateUtility::getTemplatePath ($ email ['template ' ] . '.html ' ));
387378
388379 // variables
389- $ mailRepository = ObjectUtility:: getObjectManager ()-> get (MailRepository::class);
380+ $ mailRepository = GeneralUtility:: makeInstance (MailRepository::class);
390381 $ variablesWithMarkers = $ mailRepository ->getVariablesWithMarkersFromMail ($ this ->mail );
391382 $ standaloneView ->assignMultiple ($ variablesWithMarkers );
392383 $ standaloneView ->assignMultiple ($ mailRepository ->getLabelsWithMarkersFromMail ($ this ->mail ));
@@ -429,11 +420,10 @@ protected function updateMail(array $email): void
429420 /**
430421 * @param array $settings
431422 * @return array
432- * @throws Exception
433423 */
434424 protected function getConfigurationFromSettings (array $ settings ): array
435425 {
436- $ typoScriptService = ObjectUtility:: getObjectManager ()-> get (TypoScriptService::class);
426+ $ typoScriptService = GeneralUtility:: makeInstance (TypoScriptService::class);
437427 return $ typoScriptService ->convertPlainArrayToTypoScriptArray ($ settings );
438428 }
439429
@@ -449,7 +439,7 @@ protected function getConfigurationFromSettings(array $settings): array
449439 */
450440 protected function parseAndOverwriteVariables (array &$ email , Mail $ mail ): void
451441 {
452- $ mailRepository = ObjectUtility:: getObjectManager ()-> get (MailRepository::class);
442+ $ mailRepository = GeneralUtility:: makeInstance (MailRepository::class);
453443 $ email ['subject ' ] = TypoScriptUtility::overwriteValueFromTypoScript (
454444 $ email ['subject ' ],
455445 $ this ->overwriteConfig ,
@@ -507,10 +497,10 @@ protected function initialize(Mail $mail, array $settings, string $type): void
507497 $ this ->mail = $ mail ;
508498 $ this ->settings = $ settings ;
509499 $ this ->configuration = $ this ->getConfigurationFromSettings ($ settings );
510- if (\ TYPO3 \ CMS \ Core \ Utility \ArrayUtility ::isValidPath ($ this ->configuration , $ type . './overwrite ' )) {
500+ if (ArrayUtilityCore ::isValidPath ($ this ->configuration , $ type . './overwrite. ' )) {
511501 $ this ->overwriteConfig = $ this ->configuration [$ type . '. ' ]['overwrite. ' ];
512502 }
513- $ mailRepository = ObjectUtility:: getObjectManager ()-> get (MailRepository::class);
503+ $ mailRepository = GeneralUtility:: makeInstance (MailRepository::class);
514504 ObjectUtility::getContentObject ()->start ($ mailRepository ->getVariablesWithMarkersFromMail ($ mail ));
515505 $ this ->type = $ type ;
516506 }
0 commit comments