More readable text layout for wiki pages in the skin 'Keynote'
[platal.git] / modules / email.php
index 981b7db..1350ec7 100644 (file)
@@ -32,7 +32,9 @@ class EmailModule extends PLModule
             'emails/send'     => $this->make_hook('send', AUTH_MDP),
             'emails/antispam/submit'  => $this->make_hook('submit', AUTH_COOKIE),
 
-            'admin/emails/duplicated' => $this->make_hook('duplicated', AUTH_MDP, 'admin')
+            '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'),
         );
     }
 
@@ -198,6 +200,11 @@ class EmailModule extends PLModule
 
         $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);
@@ -273,13 +280,14 @@ class EmailModule extends PLModule
         $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;
             }
@@ -289,16 +297,16 @@ class EmailModule extends PLModule
             $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');
 
@@ -321,7 +329,7 @@ class EmailModule extends PLModule
             }
 
             foreach ($_FILES as &$file) {
-                if (!PlUpload::get($file, S::v('forlife'), 'emails.send', false)) {
+                if ($file['name'] && !PlUpload::get($file, S::v('forlife'), 'emails.send', false)) {
                     $page->trig("Impossible de télécharger '" . pl_entities($file['name']) . "'");
                 }
             }
@@ -332,10 +340,10 @@ class EmailModule extends PLModule
             $to   = Env::v('to');
             $subj = Env::v('sujet');
             $from = Env::v('from');
-            $cc   = Env::v('cc');
-            $bcc  = Env::v('bcc');
+            $cc   = trim(Env::v('cc'));
+            $bcc  = trim(Env::v('bcc'));
 
-            if (empty($to) && empty($cc) && empty($to2)) {
+            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 {
@@ -351,7 +359,11 @@ class EmailModule extends PLModule
                 foreach ($files as $name=>&$upload) {
                     $mymail->addUploadAttachment($upload, $name);
                 }
-                $mymail->setTxtBody(wordwrap($txt, 78, "\n"));
+                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);
@@ -374,6 +386,7 @@ class EmailModule extends PLModule
                   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');
     }
 
     function handler_broken(&$page, $warn = null, $email = null)
@@ -416,11 +429,11 @@ consulter la page <{$globals->baseurl}/emails/broken>.
 
 
 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();
@@ -557,6 +570,18 @@ L'équipe d'administration <support@polytechnique.org>";
             $page->assign('doublon', $props);
         }
     }
+    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'));
+    }
 }
 
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: