<?php
/***************************************************************************
- * Copyright (C) 2003-2007 Polytechnique.org *
+ * Copyright (C) 2003-2008 Polytechnique.org *
* http://opensource.polytechnique.org/ *
* *
* This program is free software; you can redistribute it and/or modify *
'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_COOKIE, 'user', NO_AUTH),
+
+ 'emails/imap/in' => $this->make_hook('imap_in', 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'),
);
}
function handler_emails(&$page, $action = null, $email = null)
{
global $globals;
+ require_once 'emails.inc.php';
$page->changeTpl('emails/index.tpl');
$page->assign('xorg_title','Polytechnique.org - Mes emails');
ORDER BY LENGTH(alias)";
$page->assign('aliases', XDB::iterator($sql, $uid));
- $homonyme = XDB::query("SELECT alias FROM aliases INNER JOIN homonymes ON (id = homonyme_id) WHERE user_id = {?} AND type = 'homonyme'", $uid);
- $page->assign('homonyme', $homonyme->fetchOneCell());
-
- $sql = "SELECT email
- FROM emails
- WHERE uid = {?} AND FIND_IN_SET('active', flags)";
- $page->assign('mails', XDB::iterator($sql, $uid));
+ $homonyme = XDB::query("SELECT alias FROM aliases INNER JOIN homonymes ON (id = homonyme_id) WHERE user_id = {?} AND type = 'homonyme'", $uid);
+ $page->assign('homonyme', $homonyme->fetchOneCell());
+ // Affichage des redirections de l'utilisateur.
+ $redirect = new Redirect($uid);
+ $page->assign('mails', $redirect->active_emails());
// on regarde si l'utilisateur a un alias et si oui on l'affiche !
$forlife = S::v('forlife');
"SELECT alias
FROM virtual AS v
INNER JOIN virtual_redirect AS vr USING(vid)
- WHERE (redirect={?} OR redirect={?})
+ WHERE (redirect={?} OR redirect={?})
AND alias LIKE '%@{$globals->mail->alias_dom}'",
$forlife.'@'.$globals->mail->domain, $forlife.'@'.$globals->mail->domain2);
$page->assign('melix', $res->fetchOneCell());
FROM auth_user_quick, virtual
INNER JOIN virtual_redirect USING(vid)
WHERE ( redirect={?} OR redirect= {?} )
- AND alias LIKE '%@{$globals->mail->alias_dom}' AND user_id = {?}",
+ AND alias LIKE '%@{$globals->mail->alias_dom}' AND user_id = {?}",
$forlife.'@'.$globals->mail->domain,
$forlife.'@'.$globals->mail->domain2, S::v('uid'));
list($alias, $visibility) = $res->fetchOneRow();
//vérifier que l'alias n'est pas déja en demande
$it = new ValidateIterator ();
while($req = $it->next()) {
- if ($req->type == "alias" and $req->alias == $alias) {
+ if ($req->type == "alias" and $req->alias == $alias . '@' . $globals->mail->alias_dom) {
$page->trig("L'alias $alias@{$globals->mail->alias_dom} a déja été demandé.
Tu ne peux donc pas l'obtenir pour l'instant.");
return ;
$redirect = new Redirect(S::v('uid'));
+ // FS#703 : $_GET is urldecoded twice, hence
+ // + (the data) => %2B (in the url) => + (first decoding) => ' ' (second decoding)
+ // Since there can be no spaces in emails, we can fix this with :
+ $email = str_replace(' ', '+', $email);
+
if ($action == 'remove' && $email) {
$retour = $redirect->delete_email($email);
$page->assign('retour', $retour);
}
-
- if ($action == 'active' && $email) {
- $redirect->modify_one_email($email, true);
- }
-
- if ($action == 'inactive' && $email) {
- $redirect->modify_one_email($email, false);
- }
-
- if ($action == 'rewrite' && $email) {
- $rewrite = @func_get_arg(3);
- $redirect->modify_one_email_redirect($email, $rewrite);
- }
-
+
+ if ($action == 'active' && $email) {
+ $redirect->modify_one_email($email, true);
+ }
+
+ if ($action == 'inactive' && $email) {
+ $redirect->modify_one_email($email, false);
+ }
+
+ if ($action == 'rewrite' && $email) {
+ $rewrite = @func_get_arg(3);
+ $redirect->modify_one_email_redirect($email, $rewrite);
+ }
+
if (Env::has('emailop')) {
$actifs = Env::v('emails_actifs', Array());
print_r(Env::v('emails_rewrite'));
FROM virtual
INNER JOIN virtual_redirect USING(vid)
WHERE (redirect={?} OR redirect={?})
- AND alias LIKE '%@{$globals->mail->alias_dom}'",
+ AND alias LIKE '%@{$globals->mail->alias_dom}'",
$forlife.'@'.$globals->mail->domain, $forlife.'@'.$globals->mail->domain2);
$melix = $res->fetchOneCell();
if ($melix) {
FROM aliases
WHERE id={?} AND (type='a_vie' OR type='alias')
ORDER BY !FIND_IN_SET('usage',flags), LENGTH(alias)", $uid);
+
$page->assign('alias', $res->fetchAllAssoc());
$page->assign('emails',$redirect->emails);
+
+ require_once 'googleapps.inc.php';
+ $page->assign('googleapps', GoogleAppsAccount::account_status($uid));
}
function handler_antispam(&$page, $statut_filtre = null)
$bogo = new Bogo(S::v('uid'));
if (isset($statut_filtre)) {
- $bogo->change(S::v('uid'), $statut_filtre + 0);
+ $bogo->change($statut_filtre + 0);
}
$page->assign('filtre',$bogo->level());
}
$page->changeTpl('emails/submit_spam.tpl');
if (Post::has('send_email')) {
- $upload = $_FILES['mail']['tmp_name'];
- if (!is_uploaded_file($upload)) {
+ $upload = PlUpload::get($_FILES['mail'], S::v('forlife'), 'spam.submit', true);
+ if (!$upload) {
$page->trig('Une erreur a été rencontrée lors du transfert du fichier');
return;
}
- $mime = trim(mime_content_type($upload));
+ $mime = $upload->contentType();
if ($mime != 'text/x-mail' && $mime != 'message/rfc822') {
+ $upload->clear();
$page->trig('Le fichier ne contient pas un mail complet');
return;
}
$mailer->addTo($box);
$mailer->setFrom('"' . S::v('prenom') . ' ' . S::v('nom') . '" <web@' . $globals->mail->domain . '>');
$mailer->setTxtBody(Post::v('type') . ' soumis par ' . S::v('forlife') . ' via le web');
- $mailer->addAttachment($upload, 'message/rfc822', $_FILES['mail']['name']);
+ $mailer->addUploadAttachment($upload, Post::v('type') . '.mail');
$mailer->send();
$page->trig('Le message a été transmis à ' . $box);
+ $upload->clear();
}
}
function handler_send(&$page)
{
global $globals;
-
$page->changeTpl('emails/send.tpl');
$page->addJsLink('ajax.js');
$page->assign('xorg_title','Polytechnique.org - Envoyer un email');
// action si on recoit un formulaire
- if (Env::v('submit') == 'Envoyer')
- {
+ if (Post::has('save')) {
+ unset($_POST['save']);
+ if (trim(preg_replace('/-- .*/', '', Post::v('contenu'))) != "") {
+ $_POST['to_contacts'] = explode(';', @$_POST['to_contacts']);
+ $_POST['cc_contacts'] = explode(';', @$_POST['cc_contacts']);
+ $data = serialize($_POST);
+ XDB::execute("REPLACE INTO email_send_save
+ VALUES ({?}, {?})", S::i('uid'), $data);
+ }
+ exit;
+ } else if (Env::v('submit') == 'Envoyer') {
function getEmails($aliases)
{
if (!is_array($aliases)) {
return join(', ', $ret);
}
+ $error = false;
foreach ($_FILES as &$file) {
if ($file['name'] && !PlUpload::get($file, S::v('forlife'), 'emails.send', false)) {
- $page->trig("Impossible de télécharger '" . pl_entities($file['name']) . "'");
+ $page->trig(PlUpload::$lastError);
+ $error = true;
+ break;
}
}
- $to2 = getEmails(Env::v('to_contacts'));
- $cc2 = getEmails(Env::v('cc_contacts'));
- $txt = str_replace('^M', '', Env::v('contenu'));
- $to = Env::v('to');
- $subj = Env::v('sujet');
- $from = Env::v('from');
- $cc = trim(Env::v('cc'));
- $bcc = trim(Env::v('bcc'));
-
- if (empty($to) && empty($cc) && empty($to2) && empty($bcc) && empty($cc2)) {
- $page->trig("Indique au moins un destinataire.");
- $page->assign('uploaded_f', PlUpload::listFilenames(S::v('forlife'), 'emails.send'));
- } else {
- $mymail = new PlMailer();
- $mymail->setFrom($from);
- $mymail->setSubject($subj);
- if (!empty($to)) { $mymail->addTo($to); }
- if (!empty($cc)) { $mymail->addCc($cc); }
- if (!empty($bcc)) { $mymail->addBcc($bcc); }
- if (!empty($to2)) { $mymail->addTo($to2); }
- if (!empty($cc2)) { $mymail->addCc($cc2); }
- $files =& PlUpload::listFiles(S::v('forlife'), 'emails.send');
- foreach ($files as $name=>&$upload) {
- $mymail->addUploadAttachment($upload, $name);
- }
- if (Env::v('nowiki')) {
- $mymail->setTxtBody(wordwrap($txt, 78, "\n"));
- } else {
- $mymail->setWikiBody($txt);
- }
- if ($mymail->send()) {
- $page->trig("Ton mail a bien été envoyé.");
- $_REQUEST = array('bcc' => S::v('bestalias').'@'.$globals->mail->domain);
- PlUpload::clear(S::v('forlife'), 'emails.send');
- } else {
- $page->trig("Erreur lors de l'envoi du courriel, réessaye.");
+ if (!$error) {
+ XDB::execute("DELETE FROM email_send_save
+ WHERE uid = {?}", S::i('uid'));
+
+ $to2 = getEmails(Env::v('to_contacts'));
+ $cc2 = getEmails(Env::v('cc_contacts'));
+ $txt = str_replace('^M', '', Env::v('contenu'));
+ $to = Env::v('to');
+ $subj = Env::v('sujet');
+ $from = Env::v('from');
+ $cc = trim(Env::v('cc'));
+ $bcc = trim(Env::v('bcc'));
+
+ if (empty($to) && empty($cc) && empty($to2) && empty($bcc) && empty($cc2)) {
+ $page->trig("Indique au moins un destinataire.");
$page->assign('uploaded_f', PlUpload::listFilenames(S::v('forlife'), 'emails.send'));
+ } else {
+ $mymail = new PlMailer();
+ $mymail->setFrom($from);
+ $mymail->setSubject($subj);
+ if (!empty($to)) { $mymail->addTo($to); }
+ if (!empty($cc)) { $mymail->addCc($cc); }
+ if (!empty($bcc)) { $mymail->addBcc($bcc); }
+ if (!empty($to2)) { $mymail->addTo($to2); }
+ if (!empty($cc2)) { $mymail->addCc($cc2); }
+ $files =& PlUpload::listFiles(S::v('forlife'), 'emails.send');
+ foreach ($files as $name=>&$upload) {
+ $mymail->addUploadAttachment($upload, $name);
+ }
+ if (Env::v('nowiki')) {
+ $mymail->setTxtBody(wordwrap($txt, 78, "\n"));
+ } else {
+ $mymail->setWikiBody($txt);
+ }
+ if ($mymail->send()) {
+ $page->trig("Ton mail a bien été envoyé.");
+ $_REQUEST = array('bcc' => S::v('bestalias').'@'.$globals->mail->domain);
+ PlUpload::clear(S::v('forlife'), 'emails.send');
+ } else {
+ $page->trig("Erreur lors de l'envoi du courriel, réessaye.");
+ $page->assign('uploaded_f', PlUpload::listFilenames(S::v('forlife'), 'emails.send'));
+ }
}
}
} else {
- PlUpload::clear(S::v('forlife'), 'emails.send');
- $_REQUEST['bcc'] = S::v('bestalias').'@'.$globals->mail->domain;
+ $res = XDB::query("SELECT data
+ FROM email_send_save
+ WHERE uid = {?}", S::i('uid'));
+ if ($res->numRows() == 0) {
+ PlUpload::clear(S::v('forlife'), 'emails.send');
+ $_REQUEST['bcc'] = S::v('bestalias').'@'.$globals->mail->domain;
+ } else {
+ $data = unserialize($res->fetchOneCell());
+ $_REQUEST = array_merge($_REQUEST, $data);
+ }
}
$res = XDB::query(
WHERE c.uid = {?}
ORDER BY u.nom, u.prenom", S::v('uid'));
$page->assign('contacts', $res->fetchAllAssoc());
- $page->assign('maxsize', ini_get('post_max_size') . 'o');
+ $page->assign('maxsize', ini_get('upload_max_filesize') . 'o');
+ }
+
+ function handler_test(&$page, $forlife = null)
+ {
+ global $globals;
+ require_once 'emails.inc.php';
+
+ if (!S::has_perms() || !$forlife) {
+ $forlife = S::v('bestalias');
+ }
+
+ $res = XDB::query("SELECT FIND_IN_SET('femme', u.flags), prenom, user_id
+ FROM auth_user_md5 AS u
+ INNER JOIN aliases AS a ON (a.id = u.user_id)
+ WHERE a.alias = {?}", $forlife);
+ list($sexe, $prenom, $uid) = $res->fetchOneRow();
+ $redirect = new Redirect($uid);
+
+ $mailer = new PlMailer('emails/test.mail.tpl');
+ $mailer->assign('email', $forlife . '@' . $globals->mail->domain);
+ $mailer->assign('redirects', $redirect->active_emails());
+ $mailer->assign('sexe', $sexe);
+ $mailer->assign('prenom', $prenom);
+ $mailer->send();
+ exit;
+ }
+
+ function handler_imap_in(&$page, $hash = null, $login = null)
+ {
+ $page->changeTpl('emails/imap_register.tpl');
+ $id = null;
+ if (!empty($hash) || !empty($login)) {
+ $req = XDB::query("SELECT u.prenom, id
+ FROM aliases AS a
+ INNER JOIN newsletter_ins AS ni ON (a.id = ni.user_id)
+ INNER JOIN auth_user_md5 AS u ON (u.user_id = a.id)
+ WHERE a.alias = {?} AND ni.hash = {?}", $login, $hash);
+ list($prenom, $id) = $req->fetchOneRow();
+ }
+
+ require_once('emails.inc.php');
+ $page->assign('ok', false);
+ if (S::logged() && (is_null($id) || $id == S::i('uid'))) {
+ $storage = new EmailStorage(S::i('uid'), 'imap');
+ $storage->activate();
+ $page->assign('ok', true);
+ $page->assign('prenom', S::v('prenom'));
+ } else if (!S::logged() && $id) {
+ $storage = new EmailStorage($id, 'imap');
+ $storage->activate();
+ $page->assign('ok', true);
+ $page->assign('prenom', $prenom);
+ }
}
function handler_broken(&$page, $warn = null, $email = null)
A bientôt sur Polytechnique.org !
-L'équipe d'administration <support@polytechnique.org>";
+L'équipe d'administration <support@" . $globals->mail->domain . '>';
$mail = new PlMailer();
- $mail->setFrom('"Polytechnique.org" <support@polytechnique.org>');
- $mail->addTo("$dest@polytechnique.org");
+ $mail->setFrom('"Polytechnique.org" <support@' . $globals->mail->domain . '>');
+ $mail->addTo("$dest@" . $globals->mail->domain);
$mail->setSubject("Une de tes adresse de redirection Polytechnique.org ne marche plus !!");
$mail->setTxtBody($message);
$mail->send();
"SELECT e1.uid, e1.panne != 0 AS panne, count(e2.uid) AS nb_mails,
u.nom, u.prenom, u.promo, a.alias AS forlife
FROM emails as e1
- LEFT JOIN emails as e2 ON(e1.uid = e2.uid
+ LEFT JOIN emails as e2 ON(e1.uid = e2.uid
AND FIND_IN_SET('active', e2.flags)
AND e1.email != e2.email)
INNER JOIN auth_user_md5 as u ON(e1.uid = u.user_id)
$sql = "SELECT w.detection, w.state, w.last, w.description,
a1.alias AS edit, a2.alias AS forlife
FROM emails_watch AS w
- LEFT JOIN aliases AS a1 ON (a1.id = w.uid AND a1.type = 'a_vie')
+ LEFT JOIN aliases AS a1 ON (a1.id = w.uid AND a1.type = 'a_vie')
LEFT JOIN emails AS e ON (w.email = e.email)
LEFT JOIN aliases AS a2 ON (a2.id = e.uid AND a2.type = 'a_vie')
WHERE w.email = {?}
function handler_lost(&$page, $action = 'list', $email = null)
{
$page->changeTpl('emails/lost.tpl');
-
+
$page->assign('lost_emails', XDB::iterator('
- SELECT u.user_id, a.alias
- FROM auth_user_md5 AS u
- INNER JOIN aliases AS a ON (a.id = u.user_id AND a.type = "a_vie")
- LEFT JOIN emails AS e ON (u.user_id=e.uid AND FIND_IN_SET("active",e.flags))
- WHERE e.uid IS NULL AND u.deces = 0
- ORDER BY u.promo DESC, u.nom, u.prenom'));
+ SELECT u.user_id, a.alias
+ FROM auth_user_md5 AS u
+ INNER JOIN aliases AS a ON (a.id = u.user_id AND a.type = "a_vie")
+ LEFT JOIN emails AS e ON (u.user_id=e.uid AND FIND_IN_SET("active",e.flags))
+ WHERE e.uid IS NULL AND
+ FIND_IN_SET("googleapps", u.mail_storage) = 0 AND
+ u.deces = 0
+ ORDER BY u.promo DESC, u.nom, u.prenom'));
}
}