From cb2bc809ef29f349d38c89e202d821e67bb4c947 Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Tue, 21 Sep 2010 14:47:55 -0400
Subject: [PATCH] Fix db_mode check in insert_id()

---
 program/steps/mail/func.inc |   57 ++++++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 38 insertions(+), 19 deletions(-)

diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc
index 75d7b90..91fd05e 100644
--- a/program/steps/mail/func.inc
+++ b/program/steps/mail/func.inc
@@ -26,8 +26,8 @@
 
 $EMAIL_ADDRESS_PATTERN = '([a-z0-9][a-z0-9\-\.\+\_]*@[a-z0-9][a-z0-9\-\.]*\\.[a-z]{2,5})';
 
-// actions that do not require imap connection
-$NOIMAP_ACTIONS = array('addcontact', 'autocomplete', 'upload', 'display-attachment', 'remove-attachment');
+// actions that do not require imap connection here
+$NOIMAP_ACTIONS = array('addcontact', 'autocomplete', 'upload', 'display-attachment', 'remove-attachment', 'get');
 
 // always instantiate imap object (but not yet connect to server)
 $RCMAIL->imap_init();
@@ -171,7 +171,9 @@
       && (($f = array_search('from', $a_show_cols)) !== false) && array_search('to', $a_show_cols) === false)
     $a_show_cols[$f] = 'to';
 
-  // make sure 'threads' column is present 
+  // make sure 'threads' and 'subject' columns are present
+  if (!in_array('subject', $a_show_cols))
+    array_unshift($a_show_cols, 'subject');
   if (!in_array('threads', $a_show_cols))
     array_unshift($a_show_cols, 'threads');
 
@@ -223,28 +225,41 @@
 
 /**
  * return javascript commands to add rows to the message list
- * or to replace the whole list (IE only)
  */
-function rcmail_js_message_list($a_headers, $insert_top=FALSE, $head_replace=FALSE)
+function rcmail_js_message_list($a_headers, $insert_top=FALSE, $a_show_cols=null)
 {
   global $CONFIG, $IMAP, $RCMAIL, $OUTPUT;
 
-  if (!empty($_SESSION['list_attrib']['columns']))
-    $a_show_cols = $_SESSION['list_attrib']['columns'];
-  else
-    $a_show_cols = is_array($CONFIG['list_cols']) ? $CONFIG['list_cols'] : array('subject');
+  if (empty($a_show_cols)) {
+    if (!empty($_SESSION['list_attrib']['columns']))
+      $a_show_cols = $_SESSION['list_attrib']['columns'];
+    else
+      $a_show_cols = is_array($CONFIG['list_cols']) ? $CONFIG['list_cols'] : array('subject');
+  }
+  else {
+    if (!is_array($a_show_cols))
+      $a_show_cols = preg_split('/[\s,;]+/', strip_quotes($a_show_cols));
+    $head_replace = true;
+  }
 
   $mbox = $IMAP->get_mailbox_name();
   $delim = $IMAP->get_hierarchy_delimiter();
+
+  // make sure 'threads' and 'subject' columns are present
+  if (!in_array('subject', $a_show_cols))
+    array_unshift($a_show_cols, 'subject');
+  if (!in_array('threads', $a_show_cols))
+    array_unshift($a_show_cols, 'threads');
+
+  $_SESSION['list_attrib']['columns'] = $a_show_cols;
 
   // show 'to' instead of 'from' in sent/draft messages
   if ((strpos($mbox.$delim, $CONFIG['sent_mbox'].$delim)===0 || strpos($mbox.$delim, $CONFIG['drafts_mbox'].$delim)===0)
       && (($f = array_search('from', $a_show_cols)) !== false) && array_search('to', $a_show_cols) === false)
     $a_show_cols[$f] = 'to';
 
-  // make sure 'threads' column is present 
-  if (!in_array('threads', $a_show_cols))
-    array_unshift($a_show_cols, 'threads');
+  // Make sure there are no duplicated columns (#1486999)
+  $a_show_cols = array_unique($a_show_cols);
 
   // Plugins may set header's list_cols/list_flags and other rcube_mail_header variables
   // and list columns
@@ -754,6 +769,8 @@
  */
 function rcmail_plain_body($body, $flowed=false)
 {
+  global $RCMAIL;
+
   // make links and email-addresses clickable
   $replacer = new rcube_string_replacer;
 
@@ -780,9 +797,9 @@
           str_repeat('</blockquote>', $quote_level - $q))) . $a_lines[$n];
       else if ($flowed) {
         // previous line is flowed
-        if (isset($a_lines[$last])
+        if (isset($a_lines[$last]) && $a_lines[$n]
           && $a_lines[$last][strlen($a_lines[$last])-1] == ' ') {
-          // merge lines (and remove space-stuffing)
+          // merge lines
           $a_lines[$last] .= $a_lines[$n];
           unset($a_lines[$n]);
         }
@@ -803,7 +820,7 @@
             $a_lines[$n] = substr($a_lines[$n], 1);
 
           // previous line is flowed?
-          if (isset($a_lines[$last])
+          if (isset($a_lines[$last]) && $a_lines[$n]
             && $a_lines[$last] != '-- '
             && $a_lines[$last][strlen($a_lines[$last])-1] == ' '
           ) {
@@ -830,12 +847,14 @@
   $body = Q(join("\n", $a_lines), '', false);
 
   // colorize signature
-  if (($sp = strrpos($body, "-- \n")) !== false) {
-    if (($sp == 0 || $body[$sp-1] == "\n")) {
-      // do not touch blocks with more that 10 lines
-      if (substr_count($body, "\n", $sp) < 10)
+  $len = strlen($body);
+  while (($sp = strrpos($body, "-- \n", $sp ? -$len+$sp-1 : 0)) !== false) {
+    if ($sp == 0 || $body[$sp-1] == "\n") {
+      // do not touch blocks with more that X lines
+      if (substr_count($body, "\n", $sp) < $RCMAIL->config->get('sig_max_lines', 15))
         $body = substr($body, 0, max(0, $sp))
           .'<span class="sig">'.substr($body, $sp).'</span>';
+      break;
     }
   }
 

--
Gitblit v1.9.1