X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=banana%2Fbanana.inc.php.in;h=7aa348cb695fdd619009e61b933c46bcec7e99c9;hb=0a61409eab08ac48807eb01311b1f83636f98f7d;hp=bb8475d62cdfc234f2ac5d3214ff3214943eb195;hpb=78cd27b3ec8300e0a8ed7e6b909e3ea99fa75911;p=banana.git diff --git a/banana/banana.inc.php.in b/banana/banana.inc.php.in index bb8475d..7aa348c 100644 --- a/banana/banana.inc.php.in +++ b/banana/banana.inc.php.in @@ -12,7 +12,7 @@ class Banana var $maxspool = 3000; var $hdecode = array('from','name','organization','subject'); - var $parse_hdr = array('content-transfer-encoding', 'content-type', 'date', 'followup-to', 'from', + var $parse_hdr = array('content-disposition', 'content-transfer-encoding', 'content-type', 'date', 'followup-to', 'from', 'message-id', 'newsgroups', 'organization', 'references', 'subject', 'x-face'); var $show_hdr = array('from', 'subject', 'newsgroups', 'followup', 'date', 'organization', 'references', 'x-face'); @@ -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/'; @@ -56,6 +59,7 @@ class Banana $group = empty($_GET['group']) ? null : strtolower($_GET['group']); $artid = empty($_GET['artid']) ? null : strtolower($_GET['artid']); + $partid = empty($_GET['part']) ? 0 : $_GET['part']; $banana->state = Array ('group' => $group, 'artid' => $artid); if (is_null($group)) { @@ -68,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') { @@ -88,7 +91,7 @@ class Banana if (isset($_GET['action'])) { switch ($_GET['action']) { case 'cancel': - $res .= $banana->action_showArticle($group, $artid); + $res .= $banana->action_showArticle($group, $artid, $partid); if ($banana->post->checkcancel()) { $form = '

'._b_('Voulez-vous vraiment annuler ce message ?').'

' . "

" @@ -103,7 +106,16 @@ class Banana return $banana->action_newFup($group, $artid); } } - return $res . $banana->action_showArticle($group, $artid); + + if (isset($_GET['pj'])) { + $action = false; + if (isset($_GET['action']) && $_GET['action'] == 'view') { + $action = true; + } + return $banana->action_getAttachment($group, $artid, $_GET['pj'], $action); + } + + return $res . $banana->action_showArticle($group, $artid, $partid); } } @@ -163,7 +175,7 @@ class Banana return $res.$cuts; } - function action_showArticle($group, $id) + function action_showArticle($group, $id, $part) { $this->_newSpool($group, $this->profile['display'], $this->profile['lastnews']); $this->_newPost($id); @@ -177,13 +189,33 @@ class Banana $cuts = displayshortcuts(); $res = '

'._b_('Message').'

'.$cuts; - $res .= $this->post->to_html(); + $res .= $this->post->to_html($part); $this->nntp->quit(); return $res.$cuts; } + function action_getAttachment($group, $id, $pjid, $action) + { + $this->_newSpool($group, $this->profile['display'], $this->profile['lastnews']); + $this->_newPost($id); + if (!$this->post) { + if ($this->nntp->lasterrorcode == "423") { + $this->spool->delid($id); + } + $this->nntp->quit(); + return displayshortcuts().'

'._b_('Impossible d\'accéder au message. Le message a peut-être été annulé').'

'; + } + + $this->nntp->quit(); + if ($this->post->get_attachment($pjid, $action)) { + return ""; + } else { + return displayshortcuts().'

'._b_('Impossible d\'accéder à la pièce jointe.').'

'; + } + } + function action_cancelArticle($group, $id) { $this->_newSpool($group, $this->profile['display'], $this->profile['lastnews']); @@ -228,7 +260,7 @@ class Banana $cuts = displayshortcuts(); $html = '

'._b_('Nouveau message').'

'.$cuts; - $html .= ''; + $html .= ''; $html .= ''; $html .= ''; $html .= ''; @@ -239,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; @@ -275,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"));