Adds a Reply-To field for newsletters
authorBrice Gelineau <brice.gelineau@polytechnique.org>
Fri, 23 Sep 2011 18:50:32 +0000 (20:50 +0200)
committerBrice Gelineau <brice.gelineau@polytechnique.org>
Fri, 23 Sep 2011 18:50:32 +0000 (20:50 +0200)
Signed-off-by: Brice Gelineau <brice.gelineau@polytechnique.org>
include/newsletter.inc.php
modules/newsletter.php
templates/newsletter/edit.tpl
upgrade/1.1.4/02_newsletter_issues.sql [new file with mode: 0644]

index 0b521b4..7944c7d 100644 (file)
@@ -637,6 +637,7 @@ class NLIssue
     public $send_before;  // Date at which issue should be sent
     public $head;  // Foreword of the issue (or body for letters with no articles)
     public $signature;  // Signature of the letter
+    public $reply_to;  // Adress to reply to the message (can be empty)
     public $arts = array();  // Articles of the issue
 
     const BATCH_SIZE = 60;  // Number of emails to send every minute.
@@ -661,7 +662,7 @@ class NLIssue
     {
         // Load this issue
         $res = XDB::query('SELECT  nlid, short_name, date, send_before, state, sufb_json,
-                                   title, mail_title, head, signature
+                                   title, mail_title, head, signature, reply_to
                              FROM  newsletter_issues
                             WHERE  id = {?}',
                           $id);
@@ -684,6 +685,7 @@ class NLIssue
         $this->title_mail  = $issue['mail_title'];
         $this->head        = $issue['head'];
         $this->signature   = $issue['signature'];
+        $this->reply_to    = $issue['reply_to'];
         $this->sufb        = $this->importJSonStoredUFB($issue['sufb_json']);
 
         if ($fetch_articles) {
@@ -886,6 +888,7 @@ class NLIssue
     // }}}
     // {{{ Edition, articles
 
+    const ERROR_INVALID_REPLY_TO = 'invalid_reply_to';
     const ERROR_INVALID_SHORTNAME = 'invalid_shortname';
     const ERROR_INVALID_UFC = 'invalid_ufc';
     const ERROR_TOO_LONG_UFC = 'too_long_ufc';
@@ -905,6 +908,12 @@ class NLIssue
             'signature' => $this->signature,
         );
 
+        if (!empty($this->reply_to) && !isvalid_email($this->reply_to)) {
+            $errors[] = self::ERROR_INVALID_REPLY_TO ;
+        } else {
+            $fields['reply_to'] = $this->reply_to;
+        }
+
         if ($this->isEditable()) {
             $fields['date'] = $this->date;
             if (!preg_match('/^[-a-z0-9]+$/i', $this->shortname) || is_numeric($this->shortname)) {
@@ -1181,6 +1190,9 @@ class NLIssue
         $mailer->assign('user', $user);
         $mailer->assign('prefix',  null);
         $mailer->assign('hash',    $hash);
+        if (!empty($this->reply_to)) {
+            $mailer->addHeader('Reply-To', $this->reply_to);
+        }
         $mailer->sendTo($user);
     }
 
index 7ea958e..ff3f749 100644 (file)
@@ -247,6 +247,7 @@ class NewsletterModule extends PLModule
 
         // Convert NLIssue error messages to human-readable errors
         $error_msgs = array(
+            NLIssue::ERROR_INVALID_REPLY_TO => "L'adresse de réponse est invalide.",
             NLIssue::ERROR_INVALID_SHORTNAME => "Le nom court est invalide ou vide.",
             NLIssue::ERROR_INVALID_UFC => "Le filtre des destinataires est invalide.",
             NLIssue::ERROR_TOO_LONG_UFC => "Le nombre de matricules AX renseigné est trop élevé.",
@@ -261,6 +262,7 @@ class NewsletterModule extends PLModule
             $issue->title_mail = Post::s('title_mail');
             $issue->head       = Post::s('head');
             $issue->signature  = Post::s('signature');
+            $issue->reply_to   = Post::s('reply_to');
 
             if ($issue->isEditable()) {
                 // Date and shortname may only be modified for pending NLs, otherwise all links get broken.
index c6a3a1a..6ec0b3e 100644 (file)
         <input type='text' size='60' name='signature' value="{$issue->signature}" />
       </td>
     </tr>
+    <tr>
+      <td class='titre'>
+        Adresse de réponse (optionnelle)
+      </td>
+      <td>
+        <input type='text' size='60' name='reply_to' value="{$issue->reply_to}" />
+      </td>
+    </tr>
     {if $nl->automaticMailingEnabled() && ($issue->isEditable() || $issue->isPending())}
     <tr>
       <td class='titre'>
diff --git a/upgrade/1.1.4/02_newsletter_issues.sql b/upgrade/1.1.4/02_newsletter_issues.sql
new file mode 100644 (file)
index 0000000..a12b70a
--- /dev/null
@@ -0,0 +1,3 @@
+ALTER TABLE newsletter_issues ADD COLUMN reply_to varchar(255) NOT NULL DEFAULT '';
+
+-- vim:set syntax=mysql: