Unfound mbox is now handled as if it was empty
authorx2003bruneau <x2003bruneau@9869982d-c50d-0410-be91-f2a2ec7c7c7b>
Mon, 15 Jan 2007 09:57:02 +0000 (09:57 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Fri, 4 Jan 2008 23:35:20 +0000 (00:35 +0100)
git-svn-id: svn+ssh://murphy/home/svn/banana/trunk@171 9869982d-c50d-0410-be91-f2a2ec7c7c7b

banana/mbox.inc.php
banana/spool.inc.php
banana/templates/banana-newmessage.inc.tpl

index 7d6196b..c124041 100644 (file)
@@ -30,16 +30,16 @@ class BananaMBox implements BananaProtocoleInterface
      */
     public function __construct()
     {
-        $filename = $this->getFileName(Banana::$group);
+        $filename = $this->getFileName();
         if (is_null($filename)) {
             return;
         }
-        $this->filesize = filesize($filename);
         $this->file = @fopen($filename, 'r');
         if (!$this->file) {
-            $this->_lasterrno = 1;
-            $this->_lasterror = _b_('Can\'t open file');
             $this->file = null;
+            $this->filesize = 0;
+        } else {
+            $this->filesize = filesize($filename);
         }
         $this->current_id   = 0;
         $this->at_beginning = true;
@@ -58,7 +58,8 @@ class BananaMBox implements BananaProtocoleInterface
      */
     public function isValid()
     {
-        return !Banana::$group || $this->file;
+        return true;
+        //!Banana::$group || $this->file;
     }
     
     /** Indicate last error n°
@@ -100,6 +101,9 @@ class BananaMBox implements BananaProtocoleInterface
     public function &getMessage($id)
     {
         $message = null;
+        if (is_null($this->file)) {
+            return $message;
+        }
         if (!is_numeric($id)) {
             if (!Banana::$spool) {
                 return $message;
@@ -118,6 +122,9 @@ class BananaMBox implements BananaProtocoleInterface
     public function getMessageSource($id)
     {
         $message = null;
+        if (is_null($this->file)) {
+            return $message;
+        }
         if (!is_numeric($id)) {
             if (!Banana::$spool) { 
                 return $message;
@@ -147,6 +154,9 @@ class BananaMBox implements BananaProtocoleInterface
      */
     public function getIndexes()
     {
+        if (is_null($this->file)) {
+            return array(0, 0, 0);
+        }
         if (is_null($this->count)) {
             $this->getCount();
         }
@@ -162,6 +172,9 @@ class BananaMBox implements BananaProtocoleInterface
         $messages =& $this->readMessages(range($firstid, $lastid), true);
         $msg_headers = array_map('strtolower', $msg_headers);
         $headers  = array();
+        if (is_null($this->file)) {
+            return $headers;
+        }
         foreach ($msg_headers as $header) {
             foreach ($messages as $id=>&$message) {
                 if (!isset($headers[$id])) {
@@ -196,6 +209,9 @@ class BananaMBox implements BananaProtocoleInterface
      */
     public function getNewIndexes($since)
     {
+        if (is_null($this->file)) {
+            return array();
+        }
         if (is_null($this->new_messages)) {
             $this->getCount(); 
         }
@@ -278,12 +294,12 @@ class BananaMBox implements BananaProtocoleInterface
 # Filesystem functions
 #######
 
-    protected function getFileName($box)
+    protected function getFileName()
     {
-        if (is_null($box)) {
+        if (is_null(Banana::$group)) {
             return null;
         }
-        @list($mail, $domain) = explode('@', $box);
+        @list($mail, $domain) = explode('@', Banana::$group);
         return Banana::$mbox_path . '/' . $mail;
     }
 
index d6bc579..4ed8ab6 100644 (file)
@@ -303,6 +303,9 @@ class BananaSpool
         if (is_null($array)) {
             $array =& $this->roots;
         }
+        if (!is_array($this->roots)) {
+            return;
+        }
         foreach ($array as $id) {
             if (!$this->overview[$id]->isread) {
                 $this->markAsRead($id);
index 5ad87f4..853e785 100644 (file)
@@ -4,7 +4,7 @@
       <th colspan="2">{"Composer un nouveau message"|b}</th>
     </tr>
     {foreach from=$headers key=header item=values}
-    <tr>
+    <tr class="pair">
       <td>{$values.name}</td>
       <td>
         {if $values.fixed}
       </td>
     </tr>
     {/foreach}
-    <tr class="pair">
+    <tr>
       <td colspan="2" class="center">
         <textarea name="body" cols="74" rows="16">{$body|default:$smarty.request.body}</textarea>
       </td>
     </tr>
     {if $can_attach}
-    <tr class="pair">
+    <tr>
       <td>{"Fichier joint"|b}</td>
       <td>
         {if $maxfilesize}
@@ -31,7 +31,7 @@
       </td>
     </tr>
     {/if}
-    <tr class="pair">
+    <tr>
       <td colspan="2" class="center">
         <input type="submit" name="sendmessage" value="{"Envoyer le message"|b}" />
       </td>