From 0a61409eab08ac48807eb01311b1f83636f98f7d Mon Sep 17 00:00:00 2001 From: x2003bruneau Date: Mon, 27 Feb 2006 22:02:16 +0000 Subject: [PATCH] =?utf8?q?Ajoute=20la=20possibilit=C3=83=C2=A9=20de=20post?= =?utf8?q?er=20une=20pi=C3=83=C5=A1ce=20jointe=20par=20message...=20La=20p?= =?utf8?q?ossibilit=C3=83=C2=A9=20d'en=20mettre=20plusieurs=20sera=20pour?= =?utf8?q?=20plus=20tard,=20de=20toute=20fa=C3=83=C2=A7on=20avec=20une=20s?= =?utf8?q?eule,=20tout=20le=20code=20d'inclusion=20dans=20le=20message=20e?= =?utf8?q?t=20de=20cr=C3=83=C2=A9ation=20de=20message=20multipart=20est=20?= =?utf8?q?fait=20donc,=20le=20probl=C3=83=C5=A1me=20sera=20purement=20de?= =?utf8?q?=20g=C3=83=C2=A9rer=20le=20formulaire=20:)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit git-svn-id: svn+ssh://murphy/home/svn/banana/trunk@5 9869982d-c50d-0410-be91-f2a2ec7c7c7b --- banana/banana.inc.php.in | 45 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/banana/banana.inc.php.in b/banana/banana.inc.php.in index f777787..7aa348c 100644 --- a/banana/banana.inc.php.in +++ b/banana/banana.inc.php.in @@ -23,7 +23,10 @@ class Banana var $wrap = 74; + var $boundary = "bananaBoundary42"; var $custom = "Content-Type: text/plain; charset=utf-8\nMime-Version: 1.0\nContent-Transfer-Encoding: 8bit\nUser-Agent: Banana @VERSION@\n"; + var $custom_mp = "Content-Type: multipart/mixed; boundary=\"bananaBoundary42\"\nContent-Transfer-Encoding: 7bit\nUser-Agent: Banana @VERSION@\n"; + var $custom_bd = "Content-Type: text/plain; charset=utf-8\nContent-Transfert-Encoding: 8bit"; var $host = 'news://localhost:119/'; @@ -69,7 +72,6 @@ class Banana return $banana->action_listGroups(); } elseif (is_null($artid)) { - if (isset($_POST['action']) && $_POST['action'] == 'new') { return $banana->action_doFup($group, isset($_POST['artid']) ? intval($_POST['artid']) : -1); } elseif (isset($_GET['action']) && $_GET['action'] == 'new') { @@ -258,7 +260,7 @@ class Banana $cuts = displayshortcuts(); $html = '

'._b_('Nouveau message').'

'.$cuts; - $html .= '
'; + $html .= ''; $html .= ''; $html .= ''; $html .= ''; @@ -269,12 +271,15 @@ class Banana $html .= ''; $html .= ''; - $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; $html .= '
'._b_('En-têtes').'
'._b_('Nom').''.htmlentities($this->profile['name']).'
'._b_('Corps').'
'; + $html .= '
'._b_('Pièces jointes').'
'; + $html .= '
'; if ($id > 0) { $html .= ''; } $html .= ''; - $html .= '
'; return $html.$cuts; @@ -305,7 +310,37 @@ class Banana $msg .= "References: $refs{$post->headers['message-id']}\n"; } - $msg .= $this->custom.$this->profile['customhdr']."\n".wrap($body, "", $this->wrap); + $body = wrap($body, "", $this->wrap); + + // include attachment in the body + if (isset($_FILES['newpj'])) { + $this->custom = $this->custom_mp; + $body = "\n--".$this->boundary."\n".$this->custom_bd."\n\n".$body."\n--".$this->boundary."\n"; + $tmpname = $_FILES['newpj']['tmp_name']; + $file = basename($_FILES['newpj']['name']); + $mime = shell_exec("file -bi $tmpname"); //Because mime_content_type don't work :( + if (preg_match("@([^ ]+/[^ ]+); (.*)@", $mime, $format)) { + $mime = $format[1]; + $encod = $format[2]; + } else { + preg_match("@([^ ]+/[^ ]+)\r?\n@", $mime, $format); + $mime = $format[1]; + $encod = 'base64'; + } + + $body .= 'Content-Type: '.$mime.'; name="'.$file."\"\n"; + $body .= 'Content-Disposition: attachment; filename="'.$file."\"\n"; + $body .= 'Content-Transfer-Encoding: '.$encod."\n\n"; + if ($encod == 'base64') { + $body .= chunk_split(base64_encode(fread(fopen($tmpname, 'r'), filesize($tmpname)))); + } else { + $body .= fread(fopen($tmpname, 'r'), filesize($tmpname)); + } + $body .= '--'.$this->boundary.'--'; + } + + // finalise and post the message + $msg .= $this->custom.$this->profile['customhdr']."\n".$body; if ($this->nntp->post($msg)) { header("Location: ?group=$group".($artid==-1 ? '' : "&first=$artid")); -- 2.1.4