From 584e356920ced0e4cac68824062a7179926f3ad0 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Sun, 18 Nov 2012 06:42:55 -0500
Subject: [PATCH] Fix so mobile phone has TYPE=CELL in exported vCard (#1488812)

---
 CHANGELOG                       |    1 +
 tests/Framework/VCard.php       |   17 +++++++++++++++++
 program/include/rcube_vcard.php |    2 +-
 tests/src/johndoe.vcf           |    1 +
 4 files changed, 20 insertions(+), 1 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index dea5cda..065bdbc 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,7 @@
 CHANGELOG Roundcube Webmail
 ===========================
 
+- Fix so mobile phone has TYPE=CELL in exported vCard (#1488812)
 - Support contacts import from CSV file (#1486399)
 - Improved keep-alive action. Now the interval is based on session_lifetime (#1488507)
 - Added cross-task 'refresh' request for system state updates (#1488507)
diff --git a/program/include/rcube_vcard.php b/program/include/rcube_vcard.php
index d0a341d..72919d8 100644
--- a/program/include/rcube_vcard.php
+++ b/program/include/rcube_vcard.php
@@ -52,7 +52,7 @@
     'edit'        => 'X-AB-EDIT',
   );
   private $typemap = array('IPHONE' => 'mobile', 'CELL' => 'mobile', 'WORK,FAX' => 'workfax');
-  private $phonetypemap = array('HOME1' => 'HOME', 'BUSINESS1' => 'WORK', 'BUSINESS2' => 'WORK2', 'BUSINESSFAX' => 'WORK,FAX');
+  private $phonetypemap = array('HOME1' => 'HOME', 'BUSINESS1' => 'WORK', 'BUSINESS2' => 'WORK2', 'BUSINESSFAX' => 'WORK,FAX', 'MOBILE' => 'CELL');
   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');
 
diff --git a/tests/Framework/VCard.php b/tests/Framework/VCard.php
index 56ca9d7..79d2976 100644
--- a/tests/Framework/VCard.php
+++ b/tests/Framework/VCard.php
@@ -33,6 +33,23 @@
         $this->assertEquals("roundcube@gmail.com", $vcard->email[0], "Use PREF e-mail as primary");
     }
 
+    /**
+     * Make sure MOBILE phone is returned as CELL (as specified in standard)
+     */
+    function test_parse_three()
+    {
+        $vcard = new rcube_vcard(file_get_contents($this->_srcpath('johndoe.vcf')), null);
+
+        $vcf = $vcard->export();
+        $this->assertRegExp('/TEL;CELL:\+987654321/', $vcf, "Return CELL instead of MOBILE (import)");
+
+        $vcard = new rcube_vcard();
+        $vcard->set('phone', '+987654321', 'MOBILE');
+
+        $vcf = $vcard->export();
+        $this->assertRegExp('/TEL;TYPE=CELL:\+987654321/', $vcf, "Return CELL instead of MOBILE (set)");
+    }
+
     function test_import()
     {
         $input = file_get_contents($this->_srcpath('apple.vcf'));
diff --git a/tests/src/johndoe.vcf b/tests/src/johndoe.vcf
index 67b649d..386afaf 100644
--- a/tests/src/johndoe.vcf
+++ b/tests/src/johndoe.vcf
@@ -6,6 +6,7 @@
 EMAIL;INTERNET;WORK:inbox@roundcube.net
 EMAIL;INTERNET;HOME;TYPE=pref:roundcube@gmail.com
 TEL;WORK:+123456789
+TEL;CELL:+987654321
 ADR;WORK:;;The street;Hometown;;5555;Cayman Islands
 NOTE:The notes...
 END:VCARD

--
Gitblit v1.9.1