<?php
/***************************************************************************
- * Copyright (C) 2003-2008 Polytechnique.org *
+ * Copyright (C) 2003-2009 Polytechnique.org *
* http://opensource.polytechnique.org/ *
* *
* This program is free software; you can redistribute it and/or modify *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
***************************************************************************/
+// {{{ class MailNotFound
+
+class MailNotFound extends Exception {
+}
+
+// }}}
+
// {{{ class MassMailer
abstract class MassMailer
return $mail ? $this->_title_mail : $this->_title;
}
- public function head($prenom = null, $nom = null, $sexe = null, $type = 'text')
+ public function head($user = null, $type = 'text')
{
- if (is_null($prenom)) {
+ if (is_null($user)) {
return $this->_head;
} else {
$head = $this->_head;
- $head = str_replace('<cher>', $sexe ? 'Chère' : 'Cher', $head);
- $head = str_replace('<prenom>', $prenom, $head);
- $head = str_replace('<nom>', $nom, $head);
+ $head = str_replace('<cher>', $user->isFemale() ? 'Chère' : 'Cher', $head);
+ $head = str_replace('<prenom>', $user->displayName(), $head);
+ $head = str_replace('<nom>', '', $head);
return format_text($head, $type, 2, 64);
}
}
}
}
- public function toText(&$page, $prenom, $nom, $sexe)
+ public function toText(&$page, $user)
{
$this->css($page);
$page->assign('is_mail', false);
$page->assign('mail_part', 'text');
- $page->assign('prenom', $prenom);
- $page->assign('nom', $nom);
- $page->assign('sexe', $sexe);
+ $page->assign('user', $user);
$this->assignData($page);
}
- public function toHtml(&$page, $prenom, $nom, $sexe)
+ public function toHtml(&$page, $user)
{
$this->css($page);
$page->assign('prefix', $this->_prefix . '/' . $this->id());
$page->assign('is_mail', false);
$page->assign('mail_part', 'html');
- $page->assign('prenom', $prenom);
- $page->assign('nom', $nom);
- $page->assign('sexe', $sexe);
+ $page->assign('user', $user);
$this->assignData($page);
}
return $hash;
}
- public function sendTo($prenom, $nom, $login, $sexe, $html, $hash = 0)
+ public function sendTo($user, $hash = null)
{
- 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 (is_null($hash)) {
+ $hash = XDB::fetchOneCell("SELECT hash
+ FROM {$this->_subscriptionTable}
+ WHERE user_id = {?}", $user->id());
}
- if (strpos($alias, '@') === false && (is_null($hash) || $hash == 0)) {
-
- $hash = $this->createHash(array($prenom, $nom, $login, $sexe, $html, rand(), "X.org rulez"));
- XDB::query("UPDATE {$this->_subscriptionTable} as ni
- INNER JOIN aliases AS a ON (ni.user_id = a.id)
- SET ni.hash = {?}
- WHERE ni.user_id != 0 AND a.alias = {?}",
- $hash, $alias);
+ if (is_null($hash)) {
+ $hash = $this->createHash(array($user->displayName(), $user->fullName(),
+ $user->isFemale(), $user->isEmailFormatHtml(),
+ rand(), "X.org rulez"));
+ XDB::execute("UPDATE {$this->_subscriptionTable} as ni
+ SET ni.hash = {?}
+ WHERE ni.user_id != {?}",
+ $hash, $user->id());
}
$mailer = new PlMailer($this->_tpl);
$this->assignData($mailer);
$mailer->assign('is_mail', true);
- $mailer->assign('prenom', $prenom);
- $mailer->assign('nom', $nom);
- $mailer->assign('sexe', $sexe);
+ $mailer->assign('user', $user);
$mailer->assign('prefix', null);
$mailer->assign('hash', $hash);
- $mailer->assign('email', $login);
- $mailer->assign('alias', $alias);
- $mailer->addTo("\"$prenom $nom\" <$login>");
- $mailer->send($html);
+ $mailer->addTo('"' . $user->fullName() . '" <' . $user->bestEmail() . '>');
+ $mailer->send($user->isEmailFormatHtml());
}
protected function getAllRecipients()
{
global $globals;
- return "SELECT u.user_id, 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
+ return "SELECT a.uid
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)
- INNER JOIN aliases AS a ON(u.user_id=a.id AND FIND_IN_SET('bestalias',a.flags))
- LEFT JOIN emails AS e ON(e.uid=u.user_id AND e.flags='active')
+ INNER JOIN accounts AS a ON (ni.user_id = a.uid)
+ LEFT JOIN email_options AS eo ON (eo.uid = a.uid)
+ LEFT JOIN emails AS e ON (e.uid = a.uid AND e.flags='active')
WHERE ni.last < {?} AND ({$this->subscriptionWhere()}) AND
- (e.email IS NOT NULL OR FIND_IN_SET('googleapps', u.mail_storage))
- GROUP BY u.user_id";
+ (e.email IS NOT NULL OR FIND_IN_SET('googleapps', eo.storage))
+ GROUP BY a.uid";
}
public function sendToAll()
{
$this->setSent();
- $query = $this->getAllRecipients() . " LIMIT {?}";
+ $query = XDB::format($this->getAllRecipients(), $this->id()) . ' LIMIT 60';
while (true) {
- $res = XDB::iterRow($query, $this->_id, 60);
- if (!$res->total()) {
+ $users = User::getBulkUsersWithUIDs(XDB::fetchColumn($query));
+ if (count($users) == 0) {
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);
+ foreach ($users as $user) {
+ $sent[] = XDB::format('user_id = {?}', $user->id());
+ $this->sendTo($user, $hash);
}
XDB::execute("UPDATE {$this->_subscriptionTable}
SET last = {?}