After replying returns on the last message
[banana.git] / banana / misc.inc.php
index d3eeb2d..fe76cd9 100644 (file)
@@ -300,7 +300,7 @@ function formatDisplayHeader($_header,$_text) {
 
         case "from":
             return formatFrom($_text);
-        
+
         case "references":
             $rsl     = "";
             $ndx     = 1;
@@ -465,11 +465,17 @@ function displayPages($first = -1)
 
 function makeTable($text)
 {
+    $links = null;
+    if (function_exists('hook_browsingAction')) {
+        $links = hook_browsingAction();
+    }
+
     return '<table class="cadre_a_onglet" cellpadding="0" cellspacing="0" width="100%">'
          . '<tr><td>'
          . displayTabs()
          . '</td></tr>'
          . '<tr><td class="conteneur_tab">'
+         . $links
          . $text
          . '</td></tr>'
          . '</table>';
@@ -479,13 +485,13 @@ function makeTable($text)
  *  FORMATTING STUFF : BODY
  */
 
-function autoformat($text)
+function autoformat($text, $force = 0)
 {
     global $banana;
     $length = $banana->wrap;
-    
+    $force  = $force ? 1 : 0; 
     $cmd = 'echo ' . escapeshellarg($text)
-         . ' | perl -MText::Autoformat -e \'autoformat {left=>1, right=>' . $length . ', all=>1 };\'';
+         . ' | perl -MText::Autoformat -e \'autoformat {left=>1, right=>' . $length . ', all=>' . $force . ' };\'';
 
     exec($cmd, $result, $ret);
     if ($ret != 0) {
@@ -494,7 +500,7 @@ function autoformat($text)
     return $result;
 }                                
 
-function wrap($text, $_prefix="", $_force=false)
+function wrap($text, $_prefix="", $_force=false, $firstpass = true)
 {
     $parts = preg_split("/\n-- ?\n/", $text);
     if (count($parts)  >1) {
@@ -524,7 +530,7 @@ function wrap($text, $_prefix="", $_force=false)
                 }
                     
                 if ($format) {
-                    $result = array_merge($result, autoformat(join("\n", $next)));
+                    $result = array_merge($result, autoformat(join("\n", $next), $firstpass));
                 } else {
                     $result = array_merge($result, $next);
                 }
@@ -547,12 +553,22 @@ function wrap($text, $_prefix="", $_force=false)
         }
     }
     if ($format) {
-        $result = array_merge($result, autoformat(join("\n", $next)));
+        $result = array_merge($result, autoformat(join("\n", $next), $firstpass));
     } else {
         $result = array_merge($result, $next);
     }
 
-    return $_prefix.join("\n$_prefix", $result).($_prefix ? '' : $sign);
+    $break = "\n";
+    $prefix = null;
+    if (!$firstpass) {
+        $break .= $_prefix;
+        $prefix = $_prefix;
+    }
+    $result = $prefix.join($break, $result).($prefix ? '' : $sign);
+    if ($firstpass) {
+        return wrap($result, $_prefix, $_force, false);
+    }
+    return $result;
 }
 
 function cutlink($link)
@@ -573,7 +589,13 @@ function cleanurl($url)
 
 function catchMailLink($email)
 {
-    if (strpos($email, '$') !== false) {
+    global $banana;
+    $mid = '<' . $email . '>';
+    if (isset($banana->spool->ids[$mid])) {
+        return makeHREF(Array('group' => $banana->state['group'],
+                              'artid' => $banana->spool->ids[$mid]),
+                        $email);
+    } elseif (strpos($email, '$') !== false) {
         return $email;
     }   
     return '<a href="mailto:' . $email . '">' . $email . '</a>';
@@ -602,8 +624,8 @@ function formatbody($_text, $format='plain', $flowed=false)
         $url  = $banana->url_regexp;
         $res  = preg_replace("/(&lt;|&gt;|&quot;)/", " \\1 ", $res);
         $res  = preg_replace("!$url!ie", "'\\1'.cleanurl('\\2').'\\3'", $res);
-        $res  = preg_replace('/(["\[])?(?:mailto:)?([a-z0-9.\-+_\$]+@[a-z0-9.\-+_]+)(["\]])?/ie',
-                             "'\\1' . catchMailLink('\\2') . '\\3'",
+        $res  = preg_replace('/(["\[])?(?:mailto:|news:)?([a-z0-9.\-+_\$]+@([\-.+_]?[a-z0-9])+)(["\]])?/ie',
+                             "'\\1' . catchMailLink('\\2') . '\\4'",
                              $res);
         $res  = preg_replace("/ (&lt;|&gt;|&quot;) /", "\\1", $res);
 
@@ -620,7 +642,7 @@ function formatbody($_text, $format='plain', $flowed=false)
         $sign  = '<hr style="width: 100%; margin: 1em 0em; " />';
     } else {
         while (preg_match("@(^|<pre>|\n)&gt;@i", $res)) {
-            $res  = preg_replace("@(^|<pre>|\n)((&gt;[^\n]*\n)+)@ie",
+            $res  = preg_replace("@(^|<pre>|\n)((&gt;[^\n]*(?:\n|$))+)@ie",
                 "'\\1</pre><blockquote><pre>'"
                 ." . replaceQuotes('\\2')"
                 ." . '</pre></blockquote><pre>'",