From 74f583b3308a61b2cdb5fa789595f322d8e190df Mon Sep 17 00:00:00 2001 From: Vincent Zanotti Date: Sun, 20 Jul 2008 20:06:36 +0200 Subject: [PATCH] Removes the call to get_user_forlife in massmailer, and updates dependencies of method sendTo(). Signed-off-by: Vincent Zanotti --- include/massmailer.inc.php | 43 +++++++++++++++++++-------------------- modules/axletter.php | 6 +++--- modules/axletter/axletter.inc.php | 4 +++- modules/newsletter.php | 6 +++--- 4 files changed, 30 insertions(+), 29 deletions(-) diff --git a/include/massmailer.inc.php b/include/massmailer.inc.php index a1d49f3..261fb8b 100644 --- a/include/massmailer.inc.php +++ b/include/massmailer.inc.php @@ -157,26 +157,25 @@ abstract class MassMailer return $hash; } - public function sendTo($prenom, $nom, $login, $sexe, $html, $hash = 0) + public function sendTo($hruid, $email, $prenom, $nom, $sexe, $html, $hash = 0) { - global $globals; - $alias = $login; - if (strpos($login, '@') === false) { - $login = "$login@{$globals->mail->domain}"; - } - require_once('user.func.inc.php'); - $forlife = get_user_forlife($login, '_silent_user_callback'); - if ($forlife) { - $alias = $forlife; + // If $email is not a real email address, tries to compute it up from + // the hruid. Otherwise, we suppose that caller will have used a valid + // and canonical email address. + if (strpos($email, '@') === false) { + if (!($user = User::getSilent($email))) { + Platal::page()->trigError("'$email' is neither a valid email address nor a valid login; did not send the email."); + } + $email = $user->bestEmail(); } - if (strpos($alias, '@') === false && (is_null($hash) || $hash == 0)) { - $hash = $this->createHash(array($prenom, $nom, $login, $sexe, $html, rand(), "X.org rulez")); + if ($hruid && (is_null($hash) || $hash == 0)) { + $hash = $this->createHash(array($email, $prenom, $nom, $sexe, $html, rand(), "X.org rulez")); XDB::query("UPDATE {$this->_subscriptionTable} as ni - INNER JOIN aliases AS a ON (ni.user_id = a.id) + INNER JOIN auth_user_md5 AS u USING (user_id) SET ni.hash = {?} - WHERE ni.user_id != 0 AND a.alias = {?}", - $hash, $alias); + WHERE ni.user_id != 0 AND u.hruid = {?}", + $hash, $hruid); } $mailer = new PlMailer($this->_tpl); @@ -187,16 +186,16 @@ abstract class MassMailer $mailer->assign('sexe', $sexe); $mailer->assign('prefix', null); $mailer->assign('hash', $hash); - $mailer->assign('email', $login); - $mailer->assign('alias', $alias); - $mailer->addTo("\"$prenom $nom\" <$login>"); + $mailer->assign('email', $email); + $mailer->assign('alias', $hruid); + $mailer->addTo("\"$prenom $nom\" <$email>"); $mailer->send($html); } protected function getAllRecipients() { global $globals; - return "SELECT u.user_id, CONCAT(a.alias, '@{$globals->mail->domain}'), + return "SELECT u.user_id, u.hruid, CONCAT(a.alias, '@{$globals->mail->domain}'), u.prenom, IF(u.nom_usage='', u.nom, u.nom_usage), FIND_IN_SET('femme', u.flags), q.core_mail_fmt AS pref, ni.hash AS hash @@ -220,9 +219,9 @@ abstract class MassMailer return; } $sent = array(); - while (list($uid, $bestalias, $prenom, $nom, $sexe, $fmt, $hash) = $res->next()) { - $sent[] = "(user_id='$uid'" . (!$uid ? " AND email='$bestalias')": ')'); - $this->sendTo($prenom, $nom, $bestalias, $sexe, $fmt=='html', $hash); + while (list($uid, $hruid, $email, $prenom, $nom, $sexe, $fmt, $hash) = $res->next()) { + $sent[] = "(user_id='$uid'" . (!$uid ? " AND email='$email')": ')'); + $this->sendTo($hruid, $email, $prenom, $nom, $sexe, $fmt=='html', $hash); } XDB::execute("UPDATE {$this->_subscriptionTable} SET last = {?} diff --git a/modules/axletter.php b/modules/axletter.php index d78311c..7b7f754 100644 --- a/modules/axletter.php +++ b/modules/axletter.php @@ -275,9 +275,9 @@ class AXLetterModule extends PLModule $nl->toHtml($page, S::v('prenom'), S::v('nom'), S::v('femme')); } if (Post::has('send')) { - $nl->sendTo(S::v('prenom'), S::v('nom'), - S::v('bestalias'), S::v('femme'), - S::v('mail_fmt') != 'texte'); + $nl->sendTo(S::user()->login(), S::user()->bestEmail(), + S::v('prenom'), S::v('nom'), + S::v('femme'), S::v('mail_fmt') != 'texte'); } } diff --git a/modules/axletter/axletter.inc.php b/modules/axletter/axletter.inc.php index f8c7ca1..eed37b6 100644 --- a/modules/axletter/axletter.inc.php +++ b/modules/axletter/axletter.inc.php @@ -99,7 +99,9 @@ class AXLetter extends MassMailer protected function getAllRecipients() { - return "SELECT ni.user_id, IF(ni.user_id = 0, ni.email, a.alias) AS alias, + global $globals; + return "SELECT ni.user_id, IF(ni.user_id = 0, NULL, u.hruid) AS hruid, + IF(ni.user_id = 0, ni.email, CONCAT(a.alias, '@{$globals->mail->domain}')) AS alias, IF(ni.user_id = 0, ni.prenom, u.prenom) AS prenom, IF(ni.user_id = 0, ni.nom, IF(u.nom_usage='', u.nom, u.nom_usage)) AS nom, FIND_IN_SET('femme', IF(ni.user_id = 0, ni.flag, u.flags)) AS sexe, diff --git a/modules/newsletter.php b/modules/newsletter.php index 42b31b5..6f85eb0 100644 --- a/modules/newsletter.php +++ b/modules/newsletter.php @@ -64,9 +64,9 @@ class NewsletterModule extends PLModule } if (Post::has('send')) { $res = XDB::query("SELECT hash FROM newsletter_ins WHERE user_id = {?}", S::i('uid')); - $nl->sendTo(S::v('prenom'), S::v('nom'), - S::v('bestalias'), S::v('femme'), - S::v('mail_fmt') != 'texte', + $nl->sendTo(S::user()->login(), S::user()->bestEmail(), + S::v('prenom'), S::v('nom'), + S::v('femme'), S::v('mail_fmt') != 'texte', $res->fetchOneCell()); } } -- 2.1.4