From: x2003bruneau Date: Wed, 10 Jan 2007 23:48:32 +0000 (+0000) Subject: Can choose to view the message sources X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=9bc195d617ee6d0b8428dc3458b07f6bab36f396;p=banana.git Can choose to view the message sources git-svn-id: svn+ssh://murphy/home/svn/banana/trunk@151 9869982d-c50d-0410-be91-f2a2ec7c7c7b --- diff --git a/banana/banana.inc.php.in b/banana/banana.inc.php.in index f7ae502..3313966 100644 --- a/banana/banana.inc.php.in +++ b/banana/banana.inc.php.in @@ -290,7 +290,9 @@ class Banana protected function action_showMessage($group, $artid, $partid = 'text') { Banana::$page->setPage('message'); - if ($partid == 'text') { + $istext = $partid == 'text' || $partid == 'source' + || preg_match("/[-a-z0-9_]+\/[-a-z0-9_]+/", $partid); + if ($istext) { $this->loadSpool($group); } $msg =& $this->loadMessage($group, $artid); @@ -302,7 +304,7 @@ class Banana if ($partid == 'xface') { $msg->getXFace(); exit; - } elseif ($partid != 'text') { + } elseif (!$istext) { $part = $msg->getPartById($partid); if (!is_null($part)) { $part->send(true); @@ -312,7 +314,15 @@ class Banana $part->send(); } exit; + } elseif ($partid == 'text') { + Banana::$page->assign('body', $msg->getFormattedBody()); + } elseif ($partid == 'source') { + Banana::$page->assign('body', + '
' . banana_htmlentities(Banana::$protocole->getMessageSource($artid)) . '
'); + } else { + Banana::$page->assign('body', $msg->getFormattedBody($partid)); } + if (Banana::$profile['autoup']) { Banana::$spool->markAsRead($artid); } diff --git a/banana/mbox.inc.php b/banana/mbox.inc.php index 4cfa382..a4827a7 100644 --- a/banana/mbox.inc.php +++ b/banana/mbox.inc.php @@ -95,14 +95,12 @@ class BananaMBox implements BananaProtocoleInterface /** Return a message * @param id Id of the emssage (can be either an Message-id or a message index) - * @param msg_headers Headers to process - * @param is_msgid If is set, $id is en Message-Id * @return A BananaMessage or null if the given id can't be retreived */ - public function getMessage($id, array $msg_headers = array(), $is_msgid = false) + public function &getMessage($id) { - if ($is_msgid || !is_numeric($id)) { - if (is_null(Banana::$spool)) { + if (!is_numeric($id)) { + if (!Banana::$spool) { return null; } $id = Banana::$spool->ids[$id]; @@ -115,6 +113,22 @@ class BananaMBox implements BananaProtocoleInterface return $msg; } + /** Return the sources of the given message + */ + public function getMessageSource($id) + { + if (!is_numeric($id)) { + if (!Banana::$spool) { + return null; + } + $id = Banana::$spool->ids[$id]; + } + $message = $this->readMessages(array($id)); + return implode("\n", $message); + } + + /** Compute the number of messages of the box + */ private function getCount() { $this->count = count(Banana::$spool->overview); @@ -153,9 +167,9 @@ class BananaMBox implements BananaProtocoleInterface $headers[$id] = array('beginning' => $message['beginning'], 'end' => $message['end']); } if ($header == 'date') { - $headers[$id][$header] = strtotime($message['message'][$header]); + $headers[$id][$header] = @strtotime($message['message'][$header]); } else { - $headers[$id][$header] = $message['message'][$header]; + $headers[$id][$header] = @$message['message'][$header]; } } } @@ -404,7 +418,7 @@ class BananaMBox implements BananaProtocoleInterface */ private function &readMessages(array $ids, $strip = false, $from = false) { - if (!is_null($this->messages)) { + if ($this->messages) { return $this->messages; } sort($ids); diff --git a/banana/nntp.inc.php b/banana/nntp.inc.php index 1c5ce40..3b02c86 100644 --- a/banana/nntp.inc.php +++ b/banana/nntp.inc.php @@ -99,13 +99,11 @@ class BananaNNTP extends BananaNNTPCore implements BananaProtocoleInterface /** Return a message * @param id Id of the emssage (can be either an Message-id or a message index) - * @param msg_headers Headers to process - * @param is_msgid If is set, $id is en Message-Id * @return A BananaMessage or null if the given id can't be retreived */ - public function getMessage($id, array $msg_headers = array(), $is_msgid = false) + public function &getMessage($id) { - if (!$is_msgid && Banana::$group != $this->ingroup) { + if (is_numeric($id) && Banana::$group != $this->ingroup) { if (is_null(Banana::$spool)) { $this->group(Banana::$group); $this->ingroup = Banana::$group; @@ -120,6 +118,25 @@ class BananaNNTP extends BananaNNTPCore implements BananaProtocoleInterface return null; } + /** Return the sources of the message + */ + public function getMessageSource($id) + { + if (is_numeric($id) && Banana::$group != $this->ingroup) { + if (is_null(Banana::$spool)) { + $this->group(Banana::$group); + $this->ingroup = Banana::$group; + } else { + $id = array_search($id, Banana::$spool->ids); + } + } + $data = $this->article($id); + if ($data !== false) { + return implode("\n", $data); + } + return null; + } + /** Return the indexes of the messages presents in the Box * @return Array(number of messages, MSGNUM of the first message, MSGNUM of the last message) */ diff --git a/banana/protocoleinterface.inc.php b/banana/protocoleinterface.inc.php index 0029c9a..600ff19 100644 --- a/banana/protocoleinterface.inc.php +++ b/banana/protocoleinterface.inc.php @@ -41,11 +41,15 @@ interface BananaProtocoleInterface /** Return a message * @param id Id of the emssage (can be either an Message-id or a message index) - * @param msg_headers Headers to process - * @param is_msgid If is set, $id is en Message-Id * @return A BananaMessage or null if the given id can't be retreived */ - public function getMessage($id, array $msg_headers = array(), $is_msgid = false); + public function &getMessage($id); + + /** Return the sources of a message + * @param id Id of the emssage (can be either an Message-id or a message index) + * @return The sources of the message (or null) + */ + public function getMessageSource($id); /** Return the indexes of the messages presents in the Box * @return Array(number of messages, MSGNUM of the first message, MSGNUM of the last message) diff --git a/banana/templates/banana-message.inc.tpl b/banana/templates/banana-message.inc.tpl index 5dbc3f4..a1d8556 100644 --- a/banana/templates/banana-message.inc.tpl +++ b/banana/templates/banana-message.inc.tpl @@ -54,7 +54,7 @@ {/if} - {$message->getFormattedBody()} + {$body}