Can overload the xface generation using a custom image
[banana.git] / banana / message.inc.php
index dcb9d02..ff08fd3 100644 (file)
@@ -134,6 +134,8 @@ final class BananaMessage extends BananaMimePart
         }
         if ($hdr == 'date') {
             return strtotime($this->headers['date']);
+        } else if ($hdr == 'references' || $hdr == 'reply-to') {
+            return str_replace('><', '> <', $this->headers[$hdr]);
         } else {
             return $this->headers[$hdr];
         }
@@ -230,14 +232,13 @@ final class BananaMessage extends BananaMimePart
     {
         if (isset($refs['references'])) {
             $text = preg_split('/\s/', str_replace('><', '> <', $refs['references']));
+            $references = array();
             foreach ($text as $id=>&$value) {
                 if (isset(Banana::$spool->ids[$value])) {
-                    $value = Banana::$spool->ids[$value];
-                } else {
-                    unset($text[$id]);
+                    $references[] = Banana::$spool->ids[$value];
                 }
             }
-            return $text;
+            return $references;
         } elseif (isset($refs['in-reply-to']) && isset(Banana::$spool->ids[$refs['in-reply-to']])) {
             return array(Banana::$spool->ids[$refs['in-reply-to']]);
         } else {
@@ -247,11 +248,16 @@ final class BananaMessage extends BananaMimePart
 
     public function hasXFace()
     {
-        return Banana::$msgshow_xface && isset($this->headers['x-face']);
+        return Banana::$msgshow_xface && 
+               ((function_exists('hook_hasxface') && hook_hasXFace($this->headers))
+               || isset($this->headers['x-face']));
     }
 
     public function getXFace()
     {
+        if (function_exists('hook_getxface') && hook_getXFace($this->headers)) {
+            return;
+        }
         header('Content-Type: image/gif');
         $xface = $this->headers['x-face'];
         passthru('echo ' . escapeshellarg($xface)
@@ -302,13 +308,34 @@ final class BananaMessage extends BananaMimePart
         if (function_exists('hook_checkcancel')) {
             return hook_checkcancel($this->headers);
         }
-        return Banana::$profile['name'] == $this->headers['from'];
+        return Banana::$profile['headers']['From'] == $this->headers['from'];
     }
 
     public function canSend()
     {
         return Banana::$protocole->canSend();
     }
+
+    public function getSignature()
+    {
+        $email = $this->getHeaderValue('from');
+        if (preg_match('/<?([^ <]+@[^ >]+)>?/', $email, $matches)) {
+            $email = $matches[1];
+        }
+        $signature = BananaMimePart::getSignature();
+        if (empty($signature)) {
+            return $signature;
+        } else {
+            foreach ($signature['identity'] as $ident) {
+                if (strpos($ident, "<$email>") !== false) {
+                    return $signature;
+                }
+            }
+            $signature['certified'] = false;
+            $signature['certification_error'] = 'mauvaise identité';
+        }
+        return $signature;
+    }
 }
 
 // vim:set et sw=4 sts=4 ts=4 enc=utf-8: