| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | +use AcyMailerPhp\Mailer; | |
| 3 | 4 | use AcyMailing\Classes\CampaignClass; |
| 4 | 5 | use AcyMailing\Classes\MailClass; |
| 5 | 6 | use AcyMailing\Helpers\MailerHelper; |
| 6 | 7 | use AcyMailing\Core\AcymPlugin; |
| @@ -31,31 +32,29 @@ | ||
| 31 | 32 | } |
| 32 | 33 | |
| 33 | 34 | public function onAcymGetSendingMethodsHtmlSetting(&$data) |
| 34 | 35 | { |
| 35 | - ob_start(); | |
| 36 | 36 | ?> |
| 37 | - <div class="send_settings grid-x cell" id="<?php echo self::SENDING_METHOD_ID; ?>_settings"> | |
| 37 | + <div class="send_settings grid-x cell" id="<?php echo esc_attr(self::SENDING_METHOD_ID); ?>_settings"> | |
| 38 | 38 | <div class="cell grid-x acym_vcenter acym__sending__methods__one__settings"> |
| 39 | - <label for="<?php echo self::SENDING_METHOD_ID; ?>_password" class="cell shrink margin-right-1"> | |
| 40 | - <?php echo acym_translation('ACYM_API_KEY'); ?> | |
| 39 | + <label for="<?php echo esc_attr(self::SENDING_METHOD_ID); ?>_password" class="cell shrink margin-right-1"> | |
| 40 | + <?php echo esc_html(acym_translation('ACYM_API_KEY')); ?> | |
| 41 | 41 | </label> |
| 42 | 42 | <?php |
| 43 | - echo $this->getLinks( | |
| 43 | + $this->getLinks( | |
| 44 | 44 | 'https://elasticemail.com/referral-reward?r=7b884a0b-b979-4473-8803-06ae39d76599', |
| 45 | 45 | 'https://elasticemail.com/email-api-pricing?r=7b884a0b-b979-4473-8803-06ae39d76599' |
| 46 | 46 | ); |
| 47 | 47 | ?> |
| 48 | - <input id="<?php echo self::SENDING_METHOD_ID; ?>_password" | |
| 49 | - class="cell" | |
| 50 | - type="text" | |
| 51 | - name="config[<?php echo self::SENDING_METHOD_ID; ?>_password]" | |
| 52 | - value="<?php echo str_repeat('*', strlen($this->config->get(self::SENDING_METHOD_ID.'_password'))); ?>"> | |
| 53 | - <?php echo $this->getTestCredentialsSendingMethodButton(self::SENDING_METHOD_ID); ?> | |
| 48 | + <input id="<?php echo esc_attr(self::SENDING_METHOD_ID); ?>_password" | |
| 49 | + class="cell" | |
| 50 | + type="text" | |
| 51 | + name="config[<?php echo esc_attr(self::SENDING_METHOD_ID); ?>_password]" | |
| 52 | + value="<?php echo esc_attr(str_repeat('*', strlen($this->config->get(self::SENDING_METHOD_ID.'_password')))); ?>"> | |
| 53 | + <?php $this->getTestCredentialsSendingMethodButton(self::SENDING_METHOD_ID); ?> | |
| 54 | 54 | </div> |
| 55 | 55 | </div> |
| 56 | 56 | <?php |
| 57 | - $data['sendingMethodsHtmlSettings'][self::SENDING_METHOD_ID] = ob_get_clean(); | |
| 58 | 57 | } |
| 59 | 58 | |
| 60 | 59 | public function onAcymTestCredentialSendingMethod($sendingMethod, $credentials) |
| 61 | 60 | { |
| @@ -93,8 +92,9 @@ | ||
| 93 | 92 | array $bcc = [], |
| 94 | 93 | array $attachments = [], |
| 95 | 94 | $sendingMethodListParams = [] |
| 96 | 95 | ): void { |
| 96 | + // https://elasticemail.com/developers/api-documentation/rest-api#operation/emailsTransactionalPost | |
| 97 | 97 | if ($mailerHelper->externalMailer !== self::SENDING_METHOD_ID) { |
| 98 | 98 | return; |
| 99 | 99 | } |
| 100 | 100 | |
| @@ -174,8 +174,9 @@ | ||
| 174 | 174 | |
| 175 | 175 | if (!$this->attachmentsFetched) { |
| 176 | 176 | $this->attachmentsFetched = true; |
| 177 | 177 | |
| 178 | + // Uploaded attachments expire after 35 days by default, so 1000 should be more than enough | |
| 178 | 179 | $uploadedAttachments = $this->callApiSendingMethod( |
| 179 | 180 | self::SENDING_METHOD_API_URL.'files?limit=1000', |
| 180 | 181 | [], |
| 181 | 182 | $this->getAuthenticationHeaders() |
| @@ -216,13 +217,15 @@ | ||
| 216 | 217 | } |
| 217 | 218 | |
| 218 | 219 | private function handleHeaders(array &$data, MailerHelper $mailerHelper): void |
| 219 | 220 | { |
| 221 | + $data['content']->Headers = new stdClass(); | |
| 222 | + $data['content']->Headers->Date = Mailer::rfcDate(); | |
| 223 | + | |
| 220 | 224 | if (empty($mailerHelper->CustomHeader)) { |
| 221 | 225 | return; |
| 222 | 226 | } |
| 223 | 227 | |
| 224 | - $data['content']->Headers = new stdClass(); | |
| 225 | 228 | foreach ($mailerHelper->CustomHeader as $oneHeader) { |
| 226 | 229 | $data['content']->Headers->{$oneHeader[0]} = $oneHeader[1]; |
| 227 | 230 | } |
| 228 | 231 | } |
| @@ -272,14 +275,15 @@ | ||
| 272 | 275 | } |
| 273 | 276 | |
| 274 | 277 | private function getAuthenticationHeaders(array $credentials = []): array |
| 275 | 278 | { |
| 276 | - if (!isset($credentials[self::SENDING_METHOD_ID.'_password']) || (!empty($credentials[self::SENDING_METHOD_ID.'_password']) && empty( | |
| 277 | - trim( | |
| 278 | - $credentials[self::SENDING_METHOD_ID.'_password'], | |
| 279 | - '*' | |
| 280 | - ) | |
| 281 | - ))) { | |
| 279 | + if ( | |
| 280 | + !isset($credentials[self::SENDING_METHOD_ID.'_password']) | |
| 281 | + || ( | |
| 282 | + !empty($credentials[self::SENDING_METHOD_ID.'_password']) | |
| 283 | + && empty(trim($credentials[self::SENDING_METHOD_ID.'_password'], '*')) | |
| 284 | + ) | |
| 285 | + ) { | |
| 282 | 286 | return [ |
| 283 | 287 | 'X-ElasticEmail-ApiKey: '.$this->config->get(self::SENDING_METHOD_ID.'_password'), |
| 284 | 288 | 'Content-Type: application/json', |
| 285 | 289 | ]; |
| @@ -292,8 +296,9 @@ | ||
| 292 | 296 | } |
| 293 | 297 | |
| 294 | 298 | private function cleanFileName(string $fileName): string |
| 295 | 299 | { |
| 300 | + // Replace accents with their non-accented equivalent | |
| 296 | 301 | if (function_exists('iconv')) { |
| 297 | 302 | $fileName = iconv('UTF-8', 'ASCII//TRANSLIT', $fileName); |
| 298 | 303 | } |
| 299 | 304 | |