From 7ae5432fbfc0e923f2fe8dc62ff77afb8ecc80cf Mon Sep 17 00:00:00 2001
From: Thomas Bruederli <thomas@roundcube.net>
Date: Wed, 30 May 2012 04:42:27 -0400
Subject: [PATCH] Abbreviate long attachment file names with ellipsis (#1488499)

---
 program/include/rcube_imap_generic.php |   63 +++++++++++++++++++++++++++++--
 1 files changed, 58 insertions(+), 5 deletions(-)

diff --git a/program/include/rcube_imap_generic.php b/program/include/rcube_imap_generic.php
index cffb250..29dff86 100644
--- a/program/include/rcube_imap_generic.php
+++ b/program/include/rcube_imap_generic.php
@@ -59,6 +59,55 @@
     public $mdn_to;
     public $others = array();
     public $flags = array();
+
+    // map header to rcube_message_header object property
+    private $obj_headers = array(
+        'date'      => 'date',
+        'from'      => 'from',
+        'to'        => 'to',
+        'subject'   => 'subject',
+        'reply-to'  => 'replyto',
+        'cc'        => 'cc',
+        'bcc'       => 'bcc',
+        'content-transfer-encoding' => 'encoding',
+        'in-reply-to'               => 'in_reply_to',
+        'content-type'              => 'ctype',
+        'references'                => 'references',
+        'return-receipt-to'         => 'mdn_to',
+        'disposition-notification-to' => 'mdn_to',
+        'x-confirm-reading-to'      => 'mdn_to',
+        'message-id'                => 'messageID',
+        'x-priority'                => 'priority',
+    );
+
+    /**
+     * Returns header value
+     */
+    public function get($name)
+    {
+        $name = strtolower($name);
+
+        if (isset($this->obj_headers[$name])) {
+            return $this->{$this->obj_headers[$name]};
+        }
+
+        return $this->others[$name];
+    }
+
+    /**
+     * Sets header value
+     */
+    public function set($name, $value)
+    {
+        $name = strtolower($name);
+
+        if (isset($this->obj_headers[$name])) {
+            $this->{$this->obj_headers[$name]} = $value;
+        }
+        else {
+            $this->others[$name] = $value;
+        }
+    }
 }
 
 // For backward compatibility with cached messages (#1486602)
@@ -1650,7 +1699,7 @@
 
         // If ESEARCH is supported always use ALL
         // but not when items are specified or using simple id2uid search
-        if (empty($items) && ((int) $criteria != $criteria)) {
+        if (empty($items) && preg_match('/[^0-9]/', $criteria)) {
             $items = array('ALL');
         }
 
@@ -2079,9 +2128,10 @@
                 $result[$id]->subject   = '';
                 $result[$id]->messageID = 'mid:' . $id;
 
-                $lines = array();
-                $line  = substr($line, strlen($m[0]) + 2);
-                $ln    = 0;
+                $headers = null;
+                $lines   = array();
+                $line    = substr($line, strlen($m[0]) + 2);
+                $ln      = 0;
 
                 // get complete entry
                 while (preg_match('/\{([0-9]+)\}\r\n$/', $line, $m)) {
@@ -3616,13 +3666,16 @@
         if ($string === null) {
             return 'NIL';
         }
+
         if ($string === '') {
             return '""';
         }
+
         // atom-string (only safe characters)
-        if (!$force_quotes && !preg_match('/[\x00-\x20\x22\x28-\x2A\x5B-\x5D\x7B\x7D\x80-\xFF]/', $string)) {
+        if (!$force_quotes && !preg_match('/[\x00-\x20\x22\x25\x28-\x2A\x5B-\x5D\x7B\x7D\x80-\xFF]/', $string)) {
             return $string;
         }
+
         // quoted-string
         if (!preg_match('/[\r\n\x00\x80-\xFF]/', $string)) {
             return '"' . addcslashes($string, '\\"') . '"';

--
Gitblit v1.9.1