Can choose to view the message sources
authorx2003bruneau <x2003bruneau@9869982d-c50d-0410-be91-f2a2ec7c7c7b>
Wed, 10 Jan 2007 23:48:32 +0000 (23:48 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Fri, 4 Jan 2008 23:35:13 +0000 (00:35 +0100)
git-svn-id: svn+ssh://murphy/home/svn/banana/trunk@151 9869982d-c50d-0410-be91-f2a2ec7c7c7b

banana/banana.inc.php.in
banana/mbox.inc.php
banana/nntp.inc.php
banana/protocoleinterface.inc.php
banana/templates/banana-message.inc.tpl

index f7ae502..3313966 100644 (file)
@@ -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',
+                                  '<pre>' . banana_htmlentities(Banana::$protocole->getMessageSource($artid)) . '</pre>');
+        } else {
+            Banana::$page->assign('body', $msg->getFormattedBody($partid));
         }
+
         if (Banana::$profile['autoup']) {
             Banana::$spool->markAsRead($artid);
         }
index 4cfa382..a4827a7 100644 (file)
@@ -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);
index 1c5ce40..3b02c86 100644 (file)
@@ -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)
      */
index 0029c9a..600ff19 100644 (file)
@@ -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)
index 5dbc3f4..a1d8556 100644 (file)
@@ -54,7 +54,7 @@
   {/if}
   <tr>
     <td colspan="3" class="body">
-      {$message->getFormattedBody()}
+      {$body}
     </td>
   </tr>
 </table>