Fixes vim mode line.
[banana.git] / banana / spool.inc.php
index 6899532..011ec1f 100644 (file)
@@ -54,28 +54,19 @@ class BananaSpoolHead
      */
     public function __construct($id, array &$message)
     {
+        list($name, $from) = BananaMessage::extractMail($message['from']);
         $this->id         = $id;
         $this->msgid      = @$message['message-id'];
         $this->date       = $message['date'];
         $this->subject    = @$message['subject'];
         $this->from       = $message['from'];
-        $this->color      = sprintf('#%06x', abs(crc32($this->from) % 0xffffff));
+        $this->color      = sprintf('#%06x', abs(crc32($from) % 0xffffff));
         $this->desc       = 1;
         $this->isread     = true;
         $this->descunread = 0;
-        if (preg_match("/^([^ ]+@[^ ]+) \((.*)\)$/", $this->from, $regs)) {
-            $this->name = $regs[2];
-        }
-        if (preg_match("/^\"?([^<>\"]+)\"? +<(.+@.+)>$/", $this->from, $regs)) {
-            $this->name = preg_replace("/^'(.*)'$/", '\1', $regs[1]);
-            $this->name = stripslashes($this->name);
-        }
-        if ($this->name) {
-            $this->name =  preg_replace("/\\\(\(|\))/","\\1", $this->name);
-        } else if (preg_match("/([^< ]+)@([^> ]+)/", $this->from, $regs)) {
-            $this->name = $regs[1];
-        } else {
-            $this->name = 'Anonymous';
+        $this->name       = $name;
+        if ($name === $from) {
+            $this->name   = 'Anonymous';
         }
     }
 }
@@ -241,38 +232,42 @@ class BananaSpool
 
         // Build all the new Spool Heads
         $time = time();
-        foreach ($messages as $id=>&$message) {
-            if (!isset($this->overview[$id])) {
-                $this->overview[$id] = new BananaSpoolHead($id, $message);
-                $head =& $this->overview[$id];
-                $this->ids[$head->msgid] =& $head;
-                $head->time = $time;
-            }
-        }
-
-        // Build tree
-        $null = null;
-        foreach ($messages as $id=>&$message) {
-            $msg         =& $this->overview[$id];
-            $parents     =& $this->getReferences($message);
-            while (!empty($parents) && ($msg->parent === $msg || is_null($msg->parent))) {
-                @$msg->parent =& array_pop($parents);
-            }
-
-            if (!is_null($msg->parent)) {
-                $parent =& $msg->parent;
-                $parent->children[] =& $msg;
-                while (!is_null($parent)) {
-                    $parent->desc += $msg->desc;
-                    $parent->time  = $time;
-                    $prev =& $parent;
-                    if ($parent !== $parent->parent) {
-                        $parent =& $parent->parent;
-                    } else {
-                        $parent =& $null;
+        if (!empty($messages)) {
+            foreach ($messages as $id=>&$message) {
+                if (!isset($this->overview[$id])) {
+                    $this->overview[$id] = new BananaSpoolHead($id, $message);
+                    $head =& $this->overview[$id];
+                    $this->ids[$head->msgid] =& $head;
+                    $head->time = $time;
+                }
+            }
+
+            // Build tree
+            $null = null;
+            foreach ($messages as $id=>&$message) {
+                $msg         =& $this->overview[$id];
+                $parents     =& $this->getReferences($message);
+                while (!empty($parents) && ($msg->parent === $msg || is_null($msg->parent))) {
+                    @$msg->parent =& array_pop($parents);
+                }
+
+                if (!is_null($msg->parent)) {
+                    $parent =& $msg->parent;
+                    $parent->children[] =& $msg;
+                    while (!is_null($parent)) {
+                        $parent->desc += $msg->desc;
+                        $parent->time  = $time;
+                        $prev =& $parent;
+                        if ($parent !== $parent->parent) {
+                            $parent =& $parent->parent;
+                        } else {
+                            $parent =& $null;
+                        }
                     }
                 }
             }
+        } else {
+            $messages = array();
         }
         Banana::$protocole->updateSpool($messages);
         return true;
@@ -302,6 +297,22 @@ class BananaSpool
             }
         }
         $this->unreadnb += count($newpostsids);
+
+        if (function_exists('hook_listReadMessages')) {
+            $msgs = hook_listReadMessages($this->group);
+            if (!is_array($msgs)) {
+                return;
+            }
+            foreach ($msgs as $msg) {
+                if (!is_numeric($msg)) {
+                    if (!isset($this->ids[$msg])) {
+                        continue;
+                    }
+                    $msg = $this->ids[$msg]->id;
+                }
+                $this->markAsRead($msg);
+            }
+        }
     }
 
     public function setMode($mode)
@@ -501,6 +512,9 @@ class BananaSpool
         if (empty($subject)) {
             $subject = _b_('(pas de sujet)');
         }
+        if (mb_strlen($subject) > 100) {
+            $subject = mb_substr($subject, 0, 99) . '&hellip;';
+        }
         if ($head->id !== Banana::$artid) {
             $subject = Banana::$page->makeLink(Array('group' => $this->group, 'artid' => $head->id,
                                                      'text'  => $subject, 'popup' => $popup));
@@ -720,5 +734,5 @@ class BananaSpool
         return null;
     }
 }
-// vim:set et sw=4 sts=4 ts=4 enc=utf-8:
+// vim:set et sw=4 sts=4 ts=4 fenc=utf-8:
 ?>