X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fmassmailer.inc.php;h=3f7bcdd85e78648ed529e9acef8757f7956232ec;hb=8230e9f8eff954fb1103c8bdcf0d22557d419ae7;hp=0279948c178ab5653273cdb73ad558576bf58863;hpb=c3b45f48b60b3730d1b62c5f49e9372417bda2ab;p=platal.git diff --git a/include/massmailer.inc.php b/include/massmailer.inc.php index 0279948..3f7bcdd 100644 --- a/include/massmailer.inc.php +++ b/include/massmailer.inc.php @@ -1,6 +1,6 @@ assignData($page); } - public function sendTo($prenom, $nom, $login, $sexe, $html, $hash = 0) + private function createHash($line, $key = null) { - global $globals; - if (strpos($login, '@') === false) { - $login = "$login@{$globals->mail->domain}"; + $hash = implode(time(), $line) . rand(); + $hash = md5($hash); + return $hash; + } + + public function sendTo($hruid, $email, $prenom, $nom, $sexe, $html, $hash = 0) + { + // 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 ($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 auth_user_md5 AS u USING (user_id) + SET ni.hash = {?} + WHERE ni.user_id != 0 AND u.hruid = {?}", + $hash, $hruid); } $mailer = new PlMailer($this->_tpl); @@ -167,17 +193,19 @@ abstract class MassMailer $mailer->assign('sexe', $sexe); $mailer->assign('prefix', null); $mailer->assign('hash', $hash); - $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, 0 AS hash + q.core_mail_fmt AS pref, ni.hash AS hash FROM {$this->_subscriptionTable} AS ni INNER JOIN auth_user_md5 AS u USING(user_id) INNER JOIN auth_user_quick AS q ON(q.user_id = u.user_id) @@ -198,9 +226,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 = {?}