diff --git a/VERSIONS_HOTLINE/198577 b/VERSIONS_HOTLINE/198577 new file mode 100644 index 0000000000000000000000000000000000000000..312833c301536b977fa2bf21ff8c4f1c1ab279ff --- /dev/null +++ b/VERSIONS_HOTLINE/198577 @@ -0,0 +1 @@ + - correctif #198577 : Lettres d'informations : Amélioration de la diffusion des courriels de lettres d'information en rajoutant une entête List-Unsubscribe. \ No newline at end of file diff --git a/library/Class/Newsletter/Dispatch.php b/library/Class/Newsletter/Dispatch.php index a3555256f71da345a6764d7507ffa01a7dbd997e..4dc1fa0288d0759ec4a41b2642c0bae754b69f32 100644 --- a/library/Class/Newsletter/Dispatch.php +++ b/library/Class/Newsletter/Dispatch.php @@ -100,6 +100,14 @@ class Class_Newsletter_Dispatch extends Storm_Model_Abstract { } + public function getUnsubscribeUrl(): string + { + return ($newsletter = $this->getNewsletter()) + ? $newsletter->getUnsubscribeUrl() + : ''; + } + + public function sendBy($recipient_size) { $this->collectRecipients(); @@ -134,7 +142,7 @@ class Class_Newsletter_Dispatch extends Storm_Model_Abstract { Class_Newsletter_DispatchUser::newInstance(['dispatch_id' => $this->getId(), 'user_id' => $model->getId(), 'mail' => $model->getMail()]) - ->save(); + ->save(); Class_Newsletter_DispatchUser::clearCache(); }; diff --git a/library/Class/Newsletter/DispatchUser.php b/library/Class/Newsletter/DispatchUser.php index b054dddc9f4d7b3f007775d62ba9cf708da0ce4b..9e32a139ad6bcc5c05b198f26a4406da00580b50 100644 --- a/library/Class/Newsletter/DispatchUser.php +++ b/library/Class/Newsletter/DispatchUser.php @@ -37,7 +37,7 @@ class Newsletter_DispatchUserLoader extends Storm_Model_Loader { class Class_Newsletter_DispatchUser extends Storm_Model_Abstract { - protected $_table_name = 'newsletter_dispatch_user'; + protected $_table_name = 'newsletter_dispatch_user'; protected $_loader_class = 'Newsletter_DispatchUserLoader'; protected $_belongs_to = ['dispatch' => ['model' => 'Class_Newsletter_Dispatch'], diff --git a/library/Class/Newsletter/Template.php b/library/Class/Newsletter/Template.php index bc7d636b2c35c33b2297a8b62af9d31da13cc0fd..dc34e225da7aa46370c3813a3071e7f2922474b5 100644 --- a/library/Class/Newsletter/Template.php +++ b/library/Class/Newsletter/Template.php @@ -20,25 +20,116 @@ */ -class Class_Newsletter_Template extends Class_Entity { +class Class_Newsletter_Template +{ + + protected string $_titre = ''; + protected string $_expediteur = ''; + protected string $_body_html = ''; + protected string $_newsltetter_id = ''; + protected string $_body_text = ''; + protected string $_unsubscribe_url = ''; + + + public function setTitre(string $titre): self + { + $this->_titre = $titre; + return $this; + } + + + public function setBodyText(string $text): self + { + $this->_body_text = $text; + return $this; + } + + + public function setBodyHtml(string $html): self + { + $this->_body_html = $html; + return $this; + } + + + public function setExpediteur(string $adress): self + { + $this->_expediteur = $adress; + return $this; + } + + + public function setNewsletterId(string $id): self + { + $this->_newsletter_id = $id; + return $this; + } + + + public function getTitre(): string + { + return $this->_titre; + } + + + public function getBodyText(): string + { + return $this->_body_text; + } + + + public function getNewsletterId(): string + { + return $this->_newsletter_id; + } + + + public function getBodyHTML(): string + { + return $this->_body_html; + } + + + public function getExpediteur(): string + { + return $this->_expediteur; + } + + + public function getUnsubscribeUrl(): string + { + return $this->_unsubscribe_url; + } + + + public function setUnsubscribeUrl(string $url): self + { + $this->_unsubscribe_url = $url; + return $this; + } + + public static function newFrom(Class_Newsletter_Dispatch $dispatch) : self { return (new static()) ->setTitre($dispatch->getTitle()) ->setBodyText($dispatch->getBodyText()) ->setBodyHTML($dispatch->getBodyHtml()) ->setExpediteur($dispatch->getSender()) - ->setNewsletterId($dispatch->getNewsletterId()); + ->setNewsletterId($dispatch->getNewsletterId()) + ->setUnsubscribeUrl($dispatch->getUnsubscribeUrl()); } public function mailFor($dispatch_user) { - $mail = new ZendAfi_Mail(); - $mail + $mail = (new ZendAfi_Mail) ->setSubject($this->getTitre()) ->setBodyText($this->fillTemplate($dispatch_user, $this->getBodyText())) ->setBodyHTML($this->fillTemplate($dispatch_user, $this->getBodyHTML())) ->setFrom($this->getExpediteur()); + if ( $unsubscribe_url = $this->getUnsubscribeUrl()) + $mail->addHeader('List-Unsubscribe', $this->fillTemplate($dispatch_user, $unsubscribe_url)); + return $mail; } diff --git a/library/Class/Newsletter/TemplateHelper.php b/library/Class/Newsletter/TemplateHelper.php index b4967678d166fe425ea354d21cadec85289fc26d..704f2f075256a4da4dc4c61f7c4a1fdca5f2f173 100644 --- a/library/Class/Newsletter/TemplateHelper.php +++ b/library/Class/Newsletter/TemplateHelper.php @@ -107,8 +107,8 @@ class Class_Newsletter_TemplateHelper { return $this->_body_html_cache; return $this->_body_html_cache = $this->_renderNewsletterWith('_getContentAsHTML', - 'renderHtml', - '_getUnsubscribeHTML'); + 'renderHtml', + '_getUnsubscribeHTML'); } diff --git a/tests/library/Class/NewsletterMailingTest.php b/tests/library/Class/NewsletterMailingTest.php index 46063ae9eb57751183298ac8df13d4247c11dad4..ee22267d869dfffcff70a896151e0645dc1a3335 100644 --- a/tests/library/Class/NewsletterMailingTest.php +++ b/tests/library/Class/NewsletterMailingTest.php @@ -234,6 +234,15 @@ class NewsletterMailingAnimationsSendMailTest extends NewsletterMailingTestCase } + /** @test */ + public function mailHeaderListUnsubscribeShouldBePresent() + { + $this->assertContains('/newsletter/unsubscribe/newsletter/1/user/2/hash/' + . $this->_hashForUser(Class_Users::find(2)), + reset($this->mails[0]->getHeaders()['List-Unsubscribe']) ?? 'fail'); + } + + /** @test */ public function bodyTextShouldBeDecouverteCuisineDuMonde() { $this->assertContains('Découverte des cuisines du monde',