From 5ff3f06b36211092cf9585d5677bd41ee7abc8ee Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Wed, 26 Sep 2007 23:27:50 +0200 Subject: [PATCH] Closes #722: Can send a test email Signed-off-by: Florent Bruneau --- ChangeLog | 3 +++ configs/mails.conf | 3 +++ htdocs/javascript/ajax.js | 32 +++++++++++++++--------- modules/email.php | 28 ++++++++++++++++++++- plugins/function.test_email.php | 34 ++++++++++++++++++++++++++ templates/admin/utilisateurs.tpl | 3 +++ templates/emails/index.tpl | 1 + templates/emails/mail.test.tpl | 53 ++++++++++++++++++++++++++++++++++++++++ templates/emails/redirect.tpl | 3 ++- 9 files changed, 147 insertions(+), 13 deletions(-) create mode 100644 plugins/function.test_email.php create mode 100644 templates/emails/mail.test.tpl diff --git a/ChangeLog b/ChangeLog index 3c4597b..578720c 100644 --- 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 diff --git a/configs/mails.conf b/configs/mails.conf index b3a6082..aabd444 100644 --- a/configs/mails.conf +++ b/configs/mails.conf @@ -41,3 +41,6 @@ replyto=info@amicale.polytechnique.org [payment_ready] from="Gestion des paiements" + +[test_email] +from="Polytechnique.org" diff --git a/htdocs/javascript/ajax.js b/htdocs/javascript/ajax.js index 2d67102..bc91303 100644 --- a/htdocs/javascript/ajax.js +++ b/htdocs/javascript/ajax.js @@ -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: diff --git a/modules/email.php b/modules/email.php index c280f14..a5975cd 100644 --- a/modules/email.php +++ b/modules/email.php @@ -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 index 0000000..7cf3049 --- /dev/null +++ b/plugins/function.test_email.php @@ -0,0 +1,34 @@ +' + . '

' + . '
' + . '
' + . '
' + . ''; +} + +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: +?> diff --git a/templates/admin/utilisateurs.tpl b/templates/admin/utilisateurs.tpl index 1942bd9..07e7fe7 100644 --- a/templates/admin/utilisateurs.tpl +++ b/templates/admin/utilisateurs.tpl @@ -311,6 +311,9 @@ Pour ceci changer ses permissions en 'disabled'. * à ne modifier qu'avec l'accord express de l'utilisateur !!!

+{javascript name="ajax"} +{test_email forlife=$mr.forlife} +
diff --git a/templates/emails/index.tpl b/templates/emails/index.tpl index 8ca1ad6..08e1322 100644 --- a/templates/emails/index.tpl +++ b/templates/emails/index.tpl @@ -99,6 +99,7 @@ ton homonyme et toi-même ne disposeraient plus que des adresses de la forme pre {/iterate} {/if} + {test_email} Si tu souhaites modifier ce reroutage de ton courrier,il te suffit de te rendre ici ! diff --git a/templates/emails/mail.test.tpl b/templates/emails/mail.test.tpl new file mode 100644 index 0000000..bfb355d --- /dev/null +++ b/templates/emails/mail.test.tpl @@ -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: *} diff --git a/templates/emails/redirect.tpl b/templates/emails/redirect.tpl index 84cb0c3..11367a5 100644 --- a/templates/emails/redirect.tpl +++ b/templates/emails/redirect.tpl @@ -104,6 +104,7 @@ {/literal} //]]> {javascript name="jquery"} + {test_email}

@@ -129,7 +130,7 @@ {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)" />
- {assign var=dom1 value=#globals.mail.domain#} {assign var=dom2 value=#globals.mail.domain2#} -- 2.1.4