From 330a10b95294bcc082b880f30d9548891d63a1b0 Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Tue, 15 Jun 2010 06:15:41 -0400
Subject: [PATCH] - remove debug code

---
 program/steps/mail/func.inc |   79 +++++++++++++++++++++++++++++++++++----
 1 files changed, 70 insertions(+), 9 deletions(-)

diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc
index 384074b..a63b509 100644
--- a/program/steps/mail/func.inc
+++ b/program/steps/mail/func.inc
@@ -227,7 +227,7 @@
  */
 function rcmail_js_message_list($a_headers, $insert_top=FALSE, $head_replace=FALSE)
 {
-  global $CONFIG, $IMAP, $OUTPUT;
+  global $CONFIG, $IMAP, $RCMAIL, $OUTPUT;
 
   if (!empty($_SESSION['list_attrib']['columns']))
     $a_show_cols = $_SESSION['list_attrib']['columns'];
@@ -246,6 +246,14 @@
   if (!in_array('threads', $a_show_cols))
     array_unshift($a_show_cols, 'threads');
 
+  // Plugins may set header's list_cols/list_flags and other rcube_mail_header variables
+  // and list columns
+  $plugin = $RCMAIL->plugins->exec_hook('messages_list',
+    array('messages' => $a_headers, 'cols' => $a_show_cols));
+
+  $a_show_cols = $plugin['cols'];
+  $a_headers   = $plugin['messages'];
+
   $thead = $head_replace ? rcmail_message_list_head($_SESSION['list_attrib'], $a_show_cols) : NULL;
 
   $OUTPUT->command('set_message_coltypes', $a_show_cols, $thead);
@@ -260,15 +268,15 @@
     unset($a_show_cols[$key]);
   if (($key = array_search('threads', $a_show_cols)) !== FALSE)
     unset($a_show_cols[$key]);
-
   // loop through message headers
+
   foreach ($a_headers as $n => $header)
     {
-    $a_msg_cols = array();
-    $a_msg_flags = array();
-
     if (empty($header))
       continue;
+
+    $a_msg_cols = array();
+    $a_msg_flags = array();
 
     $IMAP->set_charset(!empty($header->charset) ? $header->charset : $CONFIG['default_charset']);
 
@@ -317,6 +325,12 @@
       $a_msg_flags['attachment'] = 1;
     $a_msg_flags['mbox'] = $mbox;
 
+    // merge with plugin result
+    if (!empty($header->list_flags) && is_array($header->list_flags))
+      $a_msg_flags = array_merge($a_msg_flags, $header->list_flags);
+    if (!empty($header->list_cols) && is_array($header->list_cols))
+      $a_msg_cols = array_merge($a_msg_cols, $header->list_cols);
+
     $OUTPUT->command('add_message_row',
       $header->uid,
       $a_msg_cols,
@@ -324,7 +338,7 @@
       $insert_top);
     }
 
-    if ($IMAP->threading && $a_headers) {
+    if ($IMAP->threading) {
       $OUTPUT->command('init_threads', (array) $roots);
     }
 }
@@ -537,12 +551,16 @@
 }
 
 
-function rcmail_send_unread_count($mbox_name, $force=false)
+function rcmail_send_unread_count($mbox_name, $force=false, $count=null)
 {
   global $RCMAIL;
 
   $old_unseen = $_SESSION['unseen_count'][$mbox_name];
-  $unseen = $RCMAIL->imap->messagecount($mbox_name, 'UNSEEN', $force);
+
+  if ($count === null)
+    $unseen = $RCMAIL->imap->messagecount($mbox_name, 'UNSEEN', $force);
+  else
+    $unseen = $count;
 
   if ($unseen != $old_unseen || ($mbox_name == 'INBOX'))
     $RCMAIL->output->command('set_unread_count', $mbox_name, $unseen, ($mbox_name == 'INBOX'));
@@ -945,6 +963,11 @@
         // fetch part if not available
         if (!isset($part->body))
           $part->body = $MESSAGE->get_part_content($part->mime_id);
+
+        // message is cached but not exists (#1485443), or other error
+        if ($part->body === false) {
+          rcmail_message_error($MESSAGE->uid);
+        }
 
         // re-format format=flowed content
         if ($part->ctype_secondary == "plain" && $part->ctype_parameters['format'] == "flowed")
@@ -1455,7 +1478,7 @@
 
     // compose headers array
     $headers = array(
-      'Date' => date('r'),
+      'Date' => rcmail_user_date(),
       'From' => $sender,
       'To'   => $message->headers->mdn_to,
       'Subject' => rcube_label('receiptread') . ': ' . $message->subject,
@@ -1500,6 +1523,29 @@
   return false;
 }
 
+// Returns RFC2822 formatted current date in user's timezone
+function rcmail_user_date()
+{
+  global $CONFIG;
+
+  // get user's timezone
+  if ($CONFIG['timezone'] === 'auto') {
+    $tz = isset($_SESSION['timezone']) ? $_SESSION['timezone'] : date('Z')/3600;
+  }
+  else {
+    $tz = $CONFIG['timezone'];
+    if ($CONFIG['dst_active'])
+      $tz++;
+  }
+
+  $date = time() + $tz * 60 * 60;
+  $date = gmdate('r', $date);
+  $date = preg_replace('/[+-][0-9]{4}$/', sprintf('%+05d', $tz * 100), $date);
+
+  return $date;
+}
+
+
 function rcmail_search_filter($attrib)
 {
   global $OUTPUT, $CONFIG;
@@ -1532,6 +1578,21 @@
   return $out;
 }
 
+function rcmail_message_error($uid=null)
+{
+  global $RCMAIL;
+
+  // Set env variables for messageerror.html template
+  if ($RCMAIL->action == 'show') {
+    $mbox_name = $RCMAIL->imap->get_mailbox_name();
+    $RCMAIL->output->set_env('mailbox', $mbox_name);
+    $RCMAIL->output->set_env('uid', null);
+  }
+  // display error message
+  $RCMAIL->output->show_message('messageopenerror', 'error');
+  // ... display message error page
+  $RCMAIL->output->send('messageerror');
+}
 
 // register UI objects
 $OUTPUT->add_handlers(array(

--
Gitblit v1.9.1