From 31e00cb7e94188b5d8f4c1d9a113b13be9dc91a7 Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Mon, 05 Sep 2011 03:28:32 -0400
Subject: [PATCH] Fix vCard WORKFAX issue (#1488046)

---
 program/include/rcube_vcard.php |   30 ++++++++++++++++++++++++++----
 1 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/program/include/rcube_vcard.php b/program/include/rcube_vcard.php
index c7dfe53..ec3ad9c 100644
--- a/program/include/rcube_vcard.php
+++ b/program/include/rcube_vcard.php
@@ -50,8 +50,8 @@
     'spouse'      => 'X-SPOUSE',
     'edit'        => 'X-AB-EDIT',
   );
-  private $typemap = array('iPhone' => 'mobile', 'CELL' => 'mobile');
-  private $phonetypemap = array('HOME1' => 'HOME', 'BUSINESS1' => 'WORK', 'BUSINESS2' => 'WORK2', 'BUSINESSFAX' => 'WORKFAX');
+  private $typemap = array('iPhone' => 'mobile', 'CELL' => 'mobile', 'WORK,FAX' => 'workfax');
+  private $phonetypemap = array('HOME1' => 'HOME', 'BUSINESS1' => 'WORK', 'BUSINESS2' => 'WORK2', 'BUSINESSFAX' => 'WORK,FAX', 'WORKFAX' => 'WORK,FAX');
   private $addresstypemap = array('BUSINESS' => 'WORK');
   private $immap = array('X-JABBER' => 'jabber', 'X-ICQ' => 'icq', 'X-MSN' => 'msn', 'X-AIM' => 'aim', 'X-YAHOO' => 'yahoo', 'X-SKYPE' => 'skype', 'X-SKYPE-USERNAME' => 'skype');
 
@@ -158,7 +158,8 @@
           $subtype = '';
 
           if (!empty($raw['type'])) {
-            $subtype = $typemap[$raw['type'][++$k]] ? $typemap[$raw['type'][$k]] : strtolower($raw['type'][$k]);
+            $combined = join(',', self::array_filter((array)$raw['type'], 'internet,pref', true));
+            $subtype = $typemap[$combined] ? $typemap[$combined] : ($typemap[$raw['type'][++$k]] ? $typemap[$raw['type'][$k]] : strtolower($raw['type'][$k]));
             while ($k < count($raw['type']) && ($subtype == 'internet' || $subtype == 'pref'))
               $subtype = $typemap[$raw['type'][++$k]] ? $typemap[$raw['type'][$k]] : strtolower($raw['type'][$k]);
           }
@@ -334,7 +335,7 @@
           $index = count($this->raw[$tag]);
           $this->raw[$tag][$index] = (array)$value;
           if ($type)
-            $this->raw[$tag][$index]['type'] = array(($typemap[$type] ? $typemap[$type] : $type));
+            $this->raw[$tag][$index]['type'] = explode(',', ($typemap[$type] ? $typemap[$type] : $type));
         }
         break;
     }
@@ -711,6 +712,27 @@
     return true;
   }
 
+  /**
+   * Extract array values by a filter
+   *
+   * @param array Array to filter
+   * @param keys Array or comma separated list of values to keep
+   * @param boolean Invert key selection: remove the listed values
+   * @return array The filtered array
+   */
+  private static function array_filter($arr, $values, $inverse = false)
+  {
+    if (!is_array($values))
+      $values = explode(',', $values);
+
+    $result = array();
+    $keep = array_flip((array)$values);
+    foreach ($arr as $key => $val)
+      if ($inverse != isset($keep[strtolower($val)]))
+        $result[$key] = $val;
+
+    return $result;
+  }
 
   /**
    * Returns UNICODE type based on BOM (Byte Order Mark)

--
Gitblit v1.9.1