From a03c28a22f194c3cbaee46abd8def0d7b8fa7e60 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Thu, 17 Jan 2013 02:38:40 -0500
Subject: [PATCH] Make sure mimetypes is an array not object in a better way

---
 program/steps/mail/show.inc |   43 ++++++++++++++++++++++++++++++-------------
 1 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/program/steps/mail/show.inc b/program/steps/mail/show.inc
index bf17576..3495df9 100644
--- a/program/steps/mail/show.inc
+++ b/program/steps/mail/show.inc
@@ -59,22 +59,27 @@
   $OUTPUT->set_env('permaurl', rcmail_url('show', array('_uid' => $MESSAGE->uid, '_mbox' => $mbox_name)));
   $OUTPUT->set_env('delimiter', $RCMAIL->storage->get_hierarchy_delimiter());
   $OUTPUT->set_env('mailbox', $mbox_name);
+  $OUTPUT->set_env('compose_extwin', $RCMAIL->config->get('compose_extwin',false));
 
   // mimetypes supported by the browser (default settings)
-  $mimetypes = $RCMAIL->config->get('client_mimetypes', 'text/plain,text/html,text/xml,image/jpeg,image/gif,image/png,image/tiff,application/x-javascript,application/pdf,application/x-shockwave-flash');
-  $mimetypes = is_string($mimetypes) ? explode(',', $mimetypes) : (array)$mimetypes;
+  $mimetypes = (array)$RCMAIL->config->get('client_mimetypes');
 
   // Remove unsupported types, which makes that attachment which cannot be
   // displayed in a browser will be downloaded directly without displaying an overlay page
   if (empty($_SESSION['browser_caps']['pdf']) && ($key = array_search('application/pdf', $mimetypes)) !== false) {
     unset($mimetypes[$key]);
   }
-  // @TODO: we could convert TIFF to JPEG and display it
-  if (empty($_SESSION['browser_caps']['tif']) && ($key = array_search('image/tiff', $mimetypes)) !== false) {
+  if (empty($_SESSION['browser_caps']['flash']) && ($key = array_search('application/x-shockwave-flash', $mimetypes)) !== false) {
     unset($mimetypes[$key]);
   }
+  if (empty($_SESSION['browser_caps']['tif']) && ($key = array_search('image/tiff', $mimetypes)) !== false) {
+    // we can convert tiff to jpeg
+    if (!$RCMAIL->config->get('im_convert_path')) {
+      unset($mimetypes[$key]);
+    }
+  }
 
-  $OUTPUT->set_env('mimetypes', $mimetypes);
+  $OUTPUT->set_env('mimetypes', array_values($mimetypes));
 
   if ($CONFIG['drafts_mbox'])
     $OUTPUT->set_env('drafts_mailbox', $CONFIG['drafts_mbox']);
@@ -99,7 +104,7 @@
 
   if (!$OUTPUT->ajax_call)
     $OUTPUT->add_label('checkingmail', 'deletemessage', 'movemessagetotrash',
-      'movingmessage', 'deletingmessage');
+      'movingmessage', 'deletingmessage', 'markingmessage');
 
   // check for unset disposition notification
   if ($MESSAGE->headers->mdn_to
@@ -139,19 +144,17 @@
 
 function rcmail_message_attachments($attrib)
 {
-  global $PRINT_MODE, $MESSAGE;
+  global $PRINT_MODE, $MESSAGE, $RCMAIL;
 
   $out = $ol = '';
 
   if (sizeof($MESSAGE->attachments)) {
     foreach ($MESSAGE->attachments as $attach_prop) {
-      $filename = $attach_prop->filename;
-      if (empty($filename) && $attach_prop->mimetype == 'text/html') {
-        $filename = rcube_label('htmlmessage');
-      }
+      $filename = rcmail_attachment_name($attach_prop, true);
 
       if ($PRINT_MODE) {
-        $ol .= html::tag('li', null, sprintf("%s (%s)", Q($filename), Q(show_bytes($attach_prop->size))));
+        $size = $RCMAIL->message_part_size($attach_prop);
+        $ol .= html::tag('li', null, Q(sprintf("%s (%s)", $filename, $size)));
       }
       else {
         if (mb_strlen($filename) > 50) {
@@ -251,7 +254,7 @@
 
   if ($email) {
     // @TODO: search in all address books?
-    $CONTACTS = $RCMAIL->get_address_book(null, true);
+    $CONTACTS = $RCMAIL->get_address_book(-1, true);
     $existing = $CONTACTS->search('email', $email, true, false);
     if ($existing->count)
       return true;
@@ -260,11 +263,25 @@
   return false;
 }
 
+function rcmail_message_contactphoto($attrib)
+{
+  global $RCMAIL, $MESSAGE;
+
+  $placeholder = $attrib['placeholder'] ? $RCMAIL->config->get('skin_path') . $attrib['placeholder'] : null;
+  if ($MESSAGE->sender)
+    $photo_img = $RCMAIL->url(array('_task' => 'addressbook', '_action' => 'photo', '_email' => $MESSAGE->sender['mailto'], '_alt' => $placeholder));
+  else
+    $photo_img = $placeholder ? $placeholder : 'program/resources/blank.gif';
+
+  return html::img(array('src' => $photo_img) + $attrib);
+}
+
 
 $OUTPUT->add_handlers(array(
   'messageattachments' => 'rcmail_message_attachments',
   'mailboxname' => 'rcmail_mailbox_name_display',
   'messageobjects' => 'rcmail_message_objects',
+  'contactphoto' => 'rcmail_message_contactphoto',
 ));
 
 

--
Gitblit v1.9.1