+ $page->assign('maxsize', ini_get('upload_max_filesize') . 'o');
+ $page->assign('user', S::user());
+ }
+
+ function handler_test(&$page, $hruid = null)
+ {
+ require_once 'emails.inc.php';
+
+ if (!S::has_xsrf_token()) {
+ return PL_FORBIDDEN;
+ }
+
+ // Retrieves the User object for the test email recipient.
+ if (S::has_perms() && $hruid) {
+ $user = User::getSilent($hruid);
+ } else {
+ $user = S::user();
+ }
+ if (!$user) {
+ return PL_NOT_FOUND;
+ }
+
+ // Sends the test email.
+ $redirect = new Redirect($user);
+
+ $mailer = new PlMailer('emails/test.mail.tpl');
+ $mailer->assign('email', $user->bestEmail());
+ $mailer->assign('redirects', $redirect->active_emails());
+ $mailer->assign('display_name', $user->displayName());
+ $mailer->assign('sexe', $user->isFemale());
+ $mailer->send($user->isEmailFormatHtml());
+ exit;
+ }
+
+ function handler_rewrite_in(&$page, $mail, $hash)
+ {
+ $page->changeTpl('emails/rewrite.tpl');
+ $page->assign('option', 'in');
+ if (empty($mail) || empty($hash)) {
+ return PL_NOT_FOUND;
+ }
+ $pos = strrpos($mail, '_');
+ if ($pos === false) {
+ return PL_NOT_FOUND;
+ }
+ $mail{$pos} = '@';
+ $res = XDB::query("SELECT COUNT(*)
+ FROM emails
+ WHERE email = {?} AND hash = {?}",
+ $mail, $hash);
+ $count = intval($res->fetchOneCell());
+ if ($count > 0) {
+ XDB::query("UPDATE emails
+ SET allow_rewrite = true, hash = NULL
+ WHERE email = {?} AND hash = {?}",
+ $mail, $hash);
+ $page->trigSuccess("Réécriture activée pour l'adresse " . $mail);
+ return;
+ }
+ return PL_NOT_FOUND;
+ }
+
+ function handler_rewrite_out(&$page, $mail, $hash)
+ {
+ $page->changeTpl('emails/rewrite.tpl');
+ $page->assign('option', 'out');
+ if (empty($mail) || empty($hash)) {
+ return PL_NOT_FOUND;
+ }
+ $pos = strrpos($mail, '_');
+ if ($pos === false) {
+ return PL_NOT_FOUND;
+ }
+ $mail{$pos} = '@';
+ $res = XDB::query("SELECT COUNT(*)
+ FROM emails
+ WHERE email = {?} AND hash = {?}",
+ $mail, $hash);
+ $count = intval($res->fetchOneCell());
+ if ($count > 0) {
+ global $globals;
+ $res = XDB::query("SELECT e.email, e.rewrite, a.alias
+ FROM emails AS e
+ INNER JOIN aliases AS a ON (a.id = e.uid AND a.type = 'a_vie')
+ WHERE e.email = {?} AND e.hash = {?}",
+ $mail, $hash);
+ XDB::query("UPDATE emails
+ SET allow_rewrite = false, hash = NULL
+ WHERE email = {?} AND hash = {?}",
+ $mail, $hash);
+ list($mail, $rewrite, $forlife) = $res->fetchOneRow();
+ $mail = new PlMailer();
+ $mail->setFrom("webmaster@" . $globals->mail->domain);
+ $mail->addTo("support@" . $globals->mail->domain);
+ $mail->setSubject("Tentative de détournement de correspondance via le rewrite");
+ $mail->setTxtBody("$forlife a tenté un rewrite de $mail vers $rewrite. Cette demande a été rejetée via le web");
+ $mail->send();
+ $page->trigWarning("Un mail d'alerte a été envoyé à l'équipe de " . $globals->core->sitename);
+ return;
+ }
+ return PL_NOT_FOUND;
+ }
+
+ function handler_imap_in(&$page, $hash = null, $login = null)
+ {
+ $page->changeTpl('emails/imap_register.tpl');
+ $user = null;
+ if (!empty($hash) || !empty($login)) {
+ $user = User::getSilent($login);
+ if ($user) {
+ $req = XDB::query("SELECT 1 FROM newsletter_ins WHERE user_id = {?} AND hash = {?}", $user->id(), $hash);
+ if ($req->numRows() == 0) {
+ $user = null;
+ }
+ }
+ }
+
+ require_once('emails.inc.php');
+ $page->assign('ok', false);
+ if (S::logged() && (is_null($user) || $user->id() == S::i('uid'))) {
+ $storage = new EmailStorage(S::user(), 'imap');
+ $storage->activate();
+ $page->assign('ok', true);
+ $page->assign('prenom', S::v('prenom'));
+ $page->assign('sexe', S::v('femme'));
+ } else if (!S::logged() && $user) {
+ $storage = new EmailStorage($user, 'imap');
+ $storage->activate();
+ $page->assign('ok', true);
+ $page->assign('prenom', $user->displayName());
+ $page->assign('sexe', $user->isFemale());
+ }