Some fixes
[banana.git] / banana / mbox.inc.php
index a4827a7..f14fbee 100644 (file)
@@ -61,7 +61,7 @@ class BananaMBox implements BananaProtocoleInterface
         return !Banana::$group || $this->file;
     }
     
-    /** Indicate last error n°
+    /** Indicate last error n°
      */
     public function lastErrNo()
     {
@@ -99,32 +99,33 @@ class BananaMBox implements BananaProtocoleInterface
      */
     public function &getMessage($id)
     {
+        $message = null;
         if (!is_numeric($id)) {
             if (!Banana::$spool) {
-                return null;
+                return $message;
             }
             $id = Banana::$spool->ids[$id];
         }
-        $message = $this->readMessages(array($id));
-        if (empty($message)) {
-            return null;
+        $messages = $this->readMessages(array($id));
+        if (!empty($messages)) {
+            $message = new BananaMessage($messages[$id]['message']);
         }
-        $msg = new BananaMessage($message[$id]['message']);
-        return $msg;
+        return $message;    
     }
 
     /** Return the sources of the given message
      */
     public function getMessageSource($id)
     {
+        $message = null;
         if (!is_numeric($id)) {
             if (!Banana::$spool) { 
-                return null;
+                return $message;
             }   
             $id = Banana::$spool->ids[$id];
-        }   
+        } 
         $message = $this->readMessages(array($id));
-        return implode("\n", $message);
+        return implode("\n", $message[$id]['message']);
     }   
 
     /** Compute the number of messages of the box
@@ -231,7 +232,19 @@ class BananaMBox implements BananaProtocoleInterface
      */
     public function send(BananaMessage &$message)
     {
-        return true;
+        $headers = $message->getHeaders();
+        $to      = $headers['To'];
+        $subject = $headers['Subject'];
+        unset($headers['To']);
+        unset($headers['Subject']);
+        $hdrs    = '';
+        foreach ($headers as $key=>$value) {
+            if (!empty($value)) {
+                $hdrs .= "$key: $value\r\n";
+            }    
+        }
+        $body = $message->get(false);
+        return mail($to, $subject, $body, $hdrs);
     }
 
     /** Cancel a message
@@ -431,7 +444,7 @@ class BananaMBox implements BananaProtocoleInterface
             }
             if ($id != $this->current_id || !$this->at_beginning) {
                 if (!$this->goTo($id)) {
-                    continue;
+                    break;
                 }
             }
             $beginning = ftell($this->file);
@@ -446,5 +459,5 @@ class BananaMBox implements BananaProtocoleInterface
     }
 }
 
-// vim:set et sw=4 sts=4 ts=4:
+// vim:set et sw=4 sts=4 ts=4 enc=utf-8:
 ?>