Fix posting with canAttach = true;
authorx2003bruneau <x2003bruneau@9869982d-c50d-0410-be91-f2a2ec7c7c7b>
Fri, 11 May 2007 17:15:27 +0000 (17:15 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Fri, 4 Jan 2008 23:35:42 +0000 (00:35 +0100)
git-svn-id: svn+ssh://murphy/home/svn/banana/trunk@251 9869982d-c50d-0410-be91-f2a2ec7c7c7b

banana/banana.inc.php.in
banana/mimepart.inc.php

index 77a4d62..f09dc2b 100644 (file)
@@ -507,8 +507,8 @@ class Banana
             }
             if (empty($hdr_values['Subject'])) {
                 Banana::$page->trig(_b_('Le message doit avoir un sujet'));
-            } elseif (Banana::$msgedit_canattach && isset($_FILES['attachment'])) {
-                $uploaded = $_FILES['attachment'];
+            } elseif (Banana::$msgedit_canattach && isset($_FILES['attachment']) && $_FILES['attachment']['name']) {
+                $uploaded =& $_FILES['attachment'];
                 if (!is_uploaded_file($uploaded['tmp_name'])) {
                     Banana::$page->trig(_b_('Une erreur est survenue lors du tĂ©lĂ©chargement du fichier'));
                 } else {
@@ -522,9 +522,10 @@ class Banana
                     $this->loadSpool($group);
                     $newid = Banana::$spool->updateUnread(Banana::$profile['lastnews']);
                     Banana::$page->redirect(array('group' => $group, 'artid' => $newid ? $newid : $artid));
-                }
-                Banana::$page->trig(_b_('Une erreur est survenue lors de l\'envoi du message :') . '<br />'
+                } else {
+                    Banana::$page->trig(_b_('Une erreur est survenue lors de l\'envoi du message :') . '<br />'
                                    . Banana::$protocole->lastError());
+                }
             }
         } else {
             if (!is_null($artid)) {
index 71e1bee..9270438 100644 (file)
@@ -25,9 +25,13 @@ class BananaMimePart
 
     protected function __construct($data = null)
     {
-        if (!is_null($data)) {
+        if ($data instanceof BananaMimePart) {
+            foreach ($this as $key=>$value) {
+                $this->$key = $data->$key;
+            }
+        } elseif (!is_null($data)) {
             $this->fromRaw($data);
-        }   
+        }
     }
 
     protected function makeTextPart($body, $content_type, $encoding, $charset = null, $format = 'fixed')
@@ -54,7 +58,7 @@ class BananaMimePart
         }
     }
 
-    protected function makeFilePart($file, $content_type =null, $disposition = 'attachment')
+    protected function makeFilePart(array $file, $content_type = null, $disposition = 'attachment')
     {
         $body = file_get_contents($file['tmp_name']);
         if ($body === false || strlen($body) != $file['size']) {
@@ -89,7 +93,7 @@ class BananaMimePart
     protected function convertToMultiPart()
     {
         if (!$this->isType('multipart', 'mixed')) {
-            $newpart = $this;
+            $newpart = new BananaMimePart($this);
             $this->content_type = 'multipart/mixed';
             $this->encoding     = '8bit';
             $this->multipart    = array($newpart);
@@ -106,10 +110,10 @@ class BananaMimePart
 
     public function addAttachment(array $file, $content_type = null, $disposition = 'attachment')
     {
-        $newpart = new BananaMimePart;
         if (!is_uploaded_file($file['tmp_name'])) {
             return false;
         }
+        $newpart = new BananaMimePart;
         if ($newpart->makeFilePart($file, $content_type, $disposition)) {
             $this->convertToMultiPart();
             $this->multipart[] = $newpart;
@@ -219,7 +223,7 @@ class BananaMimePart
     public static function getMimeType($data, $is_filename = true)
     {
         if ($is_filename) {
-            $type = mime_content_type($arg);
+            $type = mime_content_type($data);
         } else {
             $arg = escapeshellarg($data);
             $type = preg_replace('/;.*/', '', trim(shell_exec("echo $arg | file -bi -")));