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}
+