From a4c970508b899fd9e467b33319d689470908a24c Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Sun, 14 Nov 2010 05:09:14 -0500
Subject: [PATCH] - Re-fix handling of html entity strings in plain/text messages

---
 program/steps/mail/func.inc |   81 ++++++++++++++++++++++------------------
 1 files changed, 44 insertions(+), 37 deletions(-)

diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc
index 678dc04..c7498d5 100644
--- a/program/steps/mail/func.inc
+++ b/program/steps/mail/func.inc
@@ -46,7 +46,7 @@
 }
 
 // set imap properties and session vars
-if ($mbox = get_input_value('_mbox', RCUBE_INPUT_GPC))
+if (strlen(trim($mbox = get_input_value('_mbox', RCUBE_INPUT_GPC, true))))
   $IMAP->set_mailbox(($_SESSION['mbox'] = $mbox));
 else if ($IMAP)
   $_SESSION['mbox'] = $IMAP->get_mailbox_name();
@@ -131,7 +131,8 @@
 
   if (!$OUTPUT->ajax_call)
     $OUTPUT->add_label('checkingmail', 'deletemessage', 'movemessagetotrash',
-      'movingmessage', 'copyingmessage', 'copy', 'move', 'quota');
+      'movingmessage', 'copyingmessage', 'deletingmessage', 'markingmessage',
+      'copy', 'move', 'quota');
 
   $OUTPUT->set_pagetitle(rcmail_localize_foldername($mbox_name));
 }
@@ -255,17 +256,14 @@
   if (empty($a_headers))
     return;
 
-  // remove 'threads', 'attachment', 'flag' columns, we don't need them here
-  if (($key = array_search('attachment', $a_show_cols)) !== FALSE)
-    unset($a_show_cols[$key]);
-  if (($key = array_search('flag', $a_show_cols)) !== FALSE)
-    unset($a_show_cols[$key]);
-  if (($key = array_search('threads', $a_show_cols)) !== FALSE)
-    unset($a_show_cols[$key]);
-  // loop through message headers
+  // remove 'threads', 'attachment', 'flag', 'status' columns, we don't need them here
+  foreach (array('threads', 'attachment', 'flag', 'status') as $col) {
+    if (($key = array_search($col, $a_show_cols)) !== FALSE)
+      unset($a_show_cols[$key]);
+  }
 
-  foreach ($a_headers as $n => $header)
-    {
+  // loop through message headers
+  foreach ($a_headers as $n => $header) {
     if (empty($header))
       continue;
 
@@ -275,16 +273,14 @@
     $IMAP->set_charset(!empty($header->charset) ? $header->charset : $CONFIG['default_charset']);
 
     // format each col; similar as in rcmail_message_list()
-    foreach ($a_show_cols as $col)
-      {
+    foreach ($a_show_cols as $col) {
       if (in_array($col, array('from', 'to', 'cc', 'replyto')))
         $cont = Q(rcmail_address_string($header->$col, 3), 'show');
-      else if ($col=='subject')
-        {
+      else if ($col=='subject') {
         $cont = abbreviate_string(trim($IMAP->decode_header($header->$col)), 160);
         if (!$cont) $cont = rcube_label('nosubject');
         $cont = Q($cont);
-        }
+      }
       else if ($col=='size')
         $cont = show_bytes($header->$col);
       else if ($col=='date')
@@ -293,7 +289,7 @@
         $cont = Q($header->$col);
 
       $a_msg_cols[$col] = $cont;
-      }
+    }
 
     if ($header->depth)
       $a_msg_flags['depth'] = $header->depth;
@@ -332,11 +328,11 @@
       $a_msg_cols,
       $a_msg_flags,
       $insert_top);
-    }
+  }
 
-    if ($IMAP->threading) {
-      $OUTPUT->command('init_threads', (array) $roots);
-    }
+  if ($IMAP->threading) {
+    $OUTPUT->command('init_threads', (array) $roots);
+  }
 }
 
 
@@ -380,7 +376,8 @@
         $col_name = '<span class="flagged">&nbsp;</span>';
         break;
       case 'attachment':
-        $col_name = '<span class="attachment">&nbsp;</span>';
+      case 'status':
+        $col_name = '<span class="' . $col .'">&nbsp;</span>';
         break;
       case 'threads':
         $col_name = $list_menu;
@@ -426,14 +423,16 @@
 
 function rcmail_messagecount_display($attrib)
   {
-  global $IMAP, $OUTPUT;
+  global $RCMAIL;
 
   if (!$attrib['id'])
     $attrib['id'] = 'rcmcountdisplay';
 
-  $OUTPUT->add_gui_object('countdisplay', $attrib['id']);
+  $RCMAIL->output->add_gui_object('countdisplay', $attrib['id']);
 
-  return html::span($attrib, rcmail_get_messagecount_text());
+  $content =  $RCMAIL->action != 'show' ? rcmail_get_messagecount_text() : rcube_label('loading');
+
+  return html::span($attrib, $content);
   }
 
 
@@ -498,14 +497,7 @@
 
 function rcmail_get_messagecount_text($count=NULL, $page=NULL)
   {
-  global $RCMAIL, $IMAP, $MESSAGE;
-
-  if (isset($MESSAGE->index))
-    {
-    return rcube_label(array('name' => 'messagenrof',
-        'vars' => array('nr'  => $MESSAGE->index+1,
-        'count' => $count!==NULL ? $count : $IMAP->messagecount(NULL, 'ALL')))); // Only messages, no threads here
-    }
+  global $RCMAIL, $IMAP;
 
   if ($page===NULL)
     $page = $IMAP->list_page;
@@ -839,8 +831,12 @@
     $quote_level = $q;
   }
 
-  // quote plain text
-  $body = Q(join("\n", $a_lines), 'dummy', false);
+  $body = join("\n", $a_lines);
+
+  // quote plain text (don't use Q() here, to display entities "as is")
+  $table = get_html_translation_table(HTML_SPECIALCHARS);
+  unset($table['?']);
+  $body = strtr($body, $table);
 
   // colorize signature (up to <sig_max_lines> lines)
   $len = strlen($body);
@@ -980,7 +976,7 @@
 
   foreach ($plugin['output'] as $hkey => $row) {
     $table->add(array('class' => 'header-title'), Q($row['title']));
-    $table->add(array('class' => $hkey, 'width' => "90%"), Q($row['value'], ($hkey == 'subject' ? 'strict' : 'show')));
+    $table->add(array('class' => 'header '.$hkey), Q($row['value'], ($hkey == 'subject' ? 'strict' : 'show')));
   }
 
   // all headers division
@@ -1548,6 +1544,7 @@
       $delim   = $RCMAIL->config->header_delimiter();
       $to      = $headers_enc['To'];
       $subject = $headers_enc['Subject'];
+      $header_str = rtrim($header_str);
 
       if ($delim != "\r\n") {
         $header_str = str_replace("\r\n", $delim, $header_str);
@@ -1721,6 +1718,16 @@
   return $date;
 }
 
+// Fixes some content-type names
+function rcmail_fix_mimetype($name)
+{
+  // Some versions of Outlook create garbage Content-Type:
+  // application/pdf.A520491B_3BF7_494D_8855_7FAC2C6C0608
+  if (preg_match('/^application\/pdf.+/', $name))
+    $name = 'application/pdf';
+
+  return $name;
+}
 
 function rcmail_search_filter($attrib)
 {

--
Gitblit v1.9.1