Closes #722: Can send a test email
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Wed, 26 Sep 2007 21:27:50 +0000 (23:27 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Wed, 26 Sep 2007 21:27:50 +0000 (23:27 +0200)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
ChangeLog
configs/mails.conf
htdocs/javascript/ajax.js
modules/email.php
plugins/function.test_email.php [new file with mode: 0644]
templates/admin/utilisateurs.tpl
templates/emails/index.tpl
templates/emails/mail.test.tpl [new file with mode: 0644]
templates/emails/redirect.tpl

index 3c4597b..578720c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,6 +6,9 @@ New:
     * Core:
         - Auto-redirect HTML pages to HTTPS                                -FRU
 
+    * Emails:
+        - #722: Can send a test email to check mail routing                -FRU
+
     * Lists:
         - Asynchronous mail moderation (should avoid server overload)      -FRU
 
index b3a6082..aabd444 100644 (file)
@@ -41,3 +41,6 @@ replyto=info@amicale.polytechnique.org
 
 [payment_ready]
 from="Gestion des paiements" <support@polytechnique.org>
+
+[test_email]
+from="Polytechnique.org" <support@polytechnique.org>
index 2d67102..bc91303 100644 (file)
@@ -66,16 +66,16 @@ function AjaxEngine()
     {
         return function()
         {
-            if(ajax.xml_client.readyState == 4) { 
-                if (ajax.xml_client.status == 200) { 
-                    if (ajax.obj != null) {  
-                        document.getElementById(ajax.obj).innerHTML = ajax.xml_client.responseText; 
+            if(ajax.xml_client.readyState == 4) {
+                if (ajax.xml_client.status == 200) {
+                    if (ajax.obj != null) {
+                        document.getElementById(ajax.obj).innerHTML = ajax.xml_client.responseText;
                     }
-                    if (ajax.func != null) { 
-                        ajax.func(ajax.xml_client.responseText); 
+                    if (ajax.func != null) {
+                        ajax.func(ajax.xml_client.responseText);
                     }
-                } else if (ajax.xml_client.status == 403) { 
-                    window.location.reload(); 
+                } else if (ajax.xml_client.status == 403) {
+                    window.location.reload();
                 }
             }
         };
@@ -129,15 +129,25 @@ function previewWiki(idFrom, idTo, withTitle, idShow)
     var text = encodeURIComponent(document.getElementById(idFrom).value);
     if (text == "") {
         return false;
-    }   
+    }
     var url  = "wiki_preview";
     if (!withTitle) {
         url += "/notitle";
-    }   
+    }
     Ajax.update_html(idTo, url + "?text=" + text);
     if (idShow != null) {
         document.getElementById(idShow).style.display = "";
-    }   
+    }
+}
+
+function sendTestEmail(forlife)
+{
+    Ajax.update_html(null, 'emails/test' + (forlife == null ? '' : '/' + forlife),
+                     function() {
+                        showTempMessage('mail_sent', "Un mail a été envoyé avec succès"
+                                        + (forlife == null ? " sur ton adresse." : " sur l'adresse de " + forlife),
+                                        true); });
+    return false;
 }
 
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
index c280f14..a5975cd 100644 (file)
@@ -31,10 +31,11 @@ class EmailModule extends PLModule
             'emails/redirect' => $this->make_hook('redirect', AUTH_MDP),
             'emails/send'     => $this->make_hook('send', AUTH_MDP),
             'emails/antispam/submit'  => $this->make_hook('submit', AUTH_COOKIE),
+            'emails/test'     => $this->make_hook('test', AUTH_PUBLIC),
 
             'admin/emails/duplicated' => $this->make_hook('duplicated', AUTH_MDP, 'admin'),
             'admin/emails/watch'      => $this->make_hook('duplicated', AUTH_MDP, 'admin'),
-            'admin/emails/lost' => $this->make_hook('lost', AUTH_MDP, 'admin'),
+            'admin/emails/lost'       => $this->make_hook('lost', AUTH_MDP, 'admin'),
         );
     }
 
@@ -409,6 +410,31 @@ class EmailModule extends PLModule
         $page->assign('maxsize', ini_get('post_max_size') . 'o');
     }
 
+    function handler_test(&$page, $forlife = null)
+    {
+        global $globals;
+        if (!S::has_perms() || !$forlife) {
+            $forlife = S::v('bestalias');
+        }
+        $mailer = new PlMailer('emails/mail.test.tpl');
+        $mailer->assign('email', $forlife . '@' . $globals->mail->domain);
+        $iterator = XDB::iterator("SELECT  email
+                                     FROM  emails AS e
+                               INNER JOIN  aliases AS a ON (e.uid = a.id)
+                                    WHERE  FIND_IN_SET('active', e.flags) AND a.alias = {?}",
+                                  $forlife);
+        $mailer->assign('redirects', $iterator);
+        $res = XDB::query("SELECT  FIND_IN_SET('femme', u.flags), prenom
+                             FROM  auth_user_md5 AS u
+                       INNER JOIN  aliases AS a ON (a.id = u.user_id)
+                            WHERE  a.alias = {?}", $forlife);
+        list($sexe, $prenom) = $res->fetchOneRow();
+        $mailer->assign('sexe', $sexe);
+        $mailer->assign('prenom', $prenom);
+        $mailer->send();
+        exit;
+    }
+
     function handler_broken(&$page, $warn = null, $email = null)
     {
         require_once 'emails.inc.php';
diff --git a/plugins/function.test_email.php b/plugins/function.test_email.php
new file mode 100644 (file)
index 0000000..7cf3049
--- /dev/null
@@ -0,0 +1,34 @@
+<?php
+/***************************************************************************
+ *  Copyright (C) 2003-2007 Polytechnique.org                              *
+ *  http://opensource.polytechnique.org/                                   *
+ *                                                                         *
+ *  This program is free software; you can redistribute it and/or modify   *
+ *  it under the terms of the GNU General Public License as published by   *
+ *  the Free Software Foundation; either version 2 of the License, or      *
+ *  (at your option) any later version.                                    *
+ *                                                                         *
+ *  This program is distributed in the hope that it will be useful,        *
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
+ *  GNU General Public License for more details.                           *
+ *                                                                         *
+ *  You should have received a copy of the GNU General Public License      *
+ *  along with this program; if not, write to the Free Software            *
+ *  Foundation, Inc.,                                                      *
+ *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
+ ***************************************************************************/
+
+function smarty_function_test_email($params, &$smarty) {
+    $label = isset($params['title']) ? $params['title'] : 'Envoyer un mail de test';
+    $forlife = isset($params['forlife']) ? "'" . $params['forlife'] . "'" : '';
+    return '<div class="center">'
+         . '  <div id="mail_sent" style="position: absolute;"></div><br />'
+         . '  <form action="emails/test" method="get" onsubmit="return sendTestEmail(' . $forlife . ')">'
+         . '    <div><input type="submit" name="send" value="' . $label . '" /></div>'
+         . '  </form>'
+         . '</div>';
+}
+
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
+?>
index 1942bd9..07e7fe7 100644 (file)
@@ -311,6 +311,9 @@ Pour ceci changer ses permissions en 'disabled'.
 <strong>* à ne modifier qu'avec l'accord express de l'utilisateur !!!</strong>
 </p>
 
+{javascript name="ajax"}
+{test_email forlife=$mr.forlife}
+
 <form id="fwds" method="post" action="admin/user#fwds">
   <table class="bicol" cellpadding="2" cellspacing="0">
     <tr>
index 8ca1ad6..08e1322 100644 (file)
@@ -99,6 +99,7 @@ ton homonyme et toi-même ne disposeraient plus que des adresses de la forme pre
         {/iterate}
       </ul>
       {/if}
+      {test_email}
       Si tu souhaites <strong>modifier ce reroutage de ton courrier,</strong>
       <a href="emails/redirect">il te suffit de te rendre ici !</a>
     </td>
diff --git a/templates/emails/mail.test.tpl b/templates/emails/mail.test.tpl
new file mode 100644 (file)
index 0000000..bfb355d
--- /dev/null
@@ -0,0 +1,53 @@
+{**************************************************************************}
+{*                                                                        *}
+{*  Copyright (C) 2003-2007 Polytechnique.org                             *}
+{*  http://opensource.polytechnique.org/                                  *}
+{*                                                                        *}
+{*  This program is free software; you can redistribute it and/or modify  *}
+{*  it under the terms of the GNU General Public License as published by  *}
+{*  the Free Software Foundation; either version 2 of the License, or     *}
+{*  (at your option) any later version.                                   *}
+{*                                                                        *}
+{*  This program is distributed in the hope that it will be useful,       *}
+{*  but WITHOUT ANY WARRANTY; without even the implied warranty of        *}
+{*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *}
+{*  GNU General Public License for more details.                          *}
+{*                                                                        *}
+{*  You should have received a copy of the GNU General Public License     *}
+{*  along with this program; if not, write to the Free Software           *}
+{*  Foundation, Inc.,                                                     *}
+{*  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA               *}
+{*                                                                        *}
+{**************************************************************************}
+
+{config_load file="mails.conf" section="test_email"}
+{if $mail_part eq 'head'}
+{from full=#from#}
+{to addr=$email}
+{subject text="Test de ton adresse `$email`"}
+{elseif $mail_part eq 'wiki'}
+{if $sexe}Chère{else}Cher{/if} {$prenom},
+
+Tu reçois ce mail car tu as demandé la confirmation du bon fonctionnement de ton adresse polytechnicienne {$email}.
+{if $redirects->total() gt 1}Si toutes tes redirections fonctionnent correctement tu devrais recevoir une copie de ce mail
+des boîtes suivantes :
+{iterate from=$redirects item=mail}
+* {$mail.email}
+{/iterate}
+{/if}
+
+Tu trouveras sur le site divers outils pour gérer ton adresse email :
+* [[https://www.polytechnique.org/emails/redirect|La gestion de tes redirections]]
+* [[https://www.polytechnique.org/emails/antispam|La gestion de ton antispam]]
+* [[https://www.polytechnique.org/emails/send|Un formulaire pour envoyer des mails d'où que tu sois]]
+
+N'hésite pas à venir découvrir ou redécouvrir les services du site grâce au [[https://www.polytechnique.org/review|tour d'horizon]].
+
+Merci encore de la confiance que tu portes à nos services.
+
+-- \\
+Très Cordialement,\\
+L'Équipe de Polytechnique.org
+{/if}
+
+{* vim:set et sw=2 sts=2 sws=2: *}
index 84cb0c3..11367a5 100644 (file)
     {/literal}
   //]]></script>
   {javascript name="jquery"}
+  {test_email}
   <div id="redirect-msg" style="position:absolute;"></div><br />
   <div class="center">
     <table class="bicol" summary="Adresses de redirection">
                  {if $smarty.foreach.redirect.total eq 1}disabled="disabled"{/if}
                  onchange="Ajax.update_html(null,'{$globals->baseurl}/emails/redirect/'+(this.checked?'':'in')+'active/{$e->email}', redirectUpdate)" /></td>
         <td>
-          <select onchange="Ajax.update_html(null,'{$globals->baseurl}/emails/redirect/rewrite/{$e->email}/'+this.value, redirectUpdate)">
+          <select onchange="Ajax.update_html(null,'emails/redirect/rewrite/{$e->email}/'+this.value, redirectUpdate)">
             <option value=''>--- aucune ---</option>
             {assign var=dom1 value=#globals.mail.domain#}
             {assign var=dom2 value=#globals.mail.domain2#}