From: x2003bruneau Date: Fri, 11 May 2007 17:15:27 +0000 (+0000) Subject: Fix posting with canAttach = true; X-Git-Tag: 1.8~58 X-Git-Url: http://git.polytechnique.org/?p=banana.git;a=commitdiff_plain;h=b2b4d61351dcec375a00d6507c73d7bb122b4074 Fix posting with canAttach = true; git-svn-id: svn+ssh://murphy/home/svn/banana/trunk@251 9869982d-c50d-0410-be91-f2a2ec7c7c7b --- diff --git a/banana/banana.inc.php.in b/banana/banana.inc.php.in index 77a4d62..f09dc2b 100644 --- a/banana/banana.inc.php.in +++ b/banana/banana.inc.php.in @@ -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 :') . '
' + } else { + Banana::$page->trig(_b_('Une erreur est survenue lors de l\'envoi du message :') . '
' . Banana::$protocole->lastError()); + } } } else { if (!is_null($artid)) { diff --git a/banana/mimepart.inc.php b/banana/mimepart.inc.php index 71e1bee..9270438 100644 --- a/banana/mimepart.inc.php +++ b/banana/mimepart.inc.php @@ -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 -")));