summaryrefslogtreecommitdiff
path: root/program/include/rcube_vcard.php
diff options
context:
space:
mode:
authorThomas Bruederli <thomas@roundcube.net>2012-11-17 16:24:09 +0100
committerThomas Bruederli <thomas@roundcube.net>2012-11-17 16:24:09 +0100
commit6ddb16d181e285d4f0ef0ef55bdd0ba787f1b583 (patch)
tree5f186f89d5d7f77592acf3aec676b48367a96d48 /program/include/rcube_vcard.php
parentbc66f7d6d208ac99dcec57992c4eb955570d85bc (diff)
parent9ab34604d94270f6c1795c7dd7b615273d05db0c (diff)
Merge branch 'master' of github.com:roundcube/roundcubemail
Diffstat (limited to 'program/include/rcube_vcard.php')
-rw-r--r--program/include/rcube_vcard.php66
1 files changed, 17 insertions, 49 deletions
diff --git a/program/include/rcube_vcard.php b/program/include/rcube_vcard.php
index 00903c257..d0a341da1 100644
--- a/program/include/rcube_vcard.php
+++ b/program/include/rcube_vcard.php
@@ -5,7 +5,7 @@
| program/include/rcube_vcard.php |
| |
| This file is part of the Roundcube Webmail client |
- | Copyright (C) 2008-2011, The Roundcube Dev Team |
+ | Copyright (C) 2008-2012, The Roundcube Dev Team |
| |
| Licensed under the GNU General Public License version 3 or |
| any later version with exceptions for skins & plugins. |
@@ -15,6 +15,7 @@
| Logical representation of a vcard address record |
+-----------------------------------------------------------------------+
| Author: Thomas Bruederli <roundcube@gmail.com> |
+ | Author: Aleksander Machniak <alec@alec.pl> |
+-----------------------------------------------------------------------+
*/
@@ -23,8 +24,8 @@
* Logical representation of a vcard-based address record
* Provides functions to parse and export vCard data format
*
- * @package Addressbook
- * @author Thomas Bruederli <roundcube@gmail.com>
+ * @package Framework
+ * @subpackage Addressbook
*/
class rcube_vcard
{
@@ -62,7 +63,6 @@ class rcube_vcard
public $middlename;
public $nickname;
public $organization;
- public $notes;
public $email = array();
public static $eol = "\r\n";
@@ -265,26 +265,25 @@ class rcube_vcard
*/
public function set($field, $value, $type = 'HOME')
{
- $field = strtolower($field);
+ $field = strtolower($field);
$type_uc = strtoupper($type);
- $typemap = array_flip($this->typemap);
switch ($field) {
case 'name':
case 'displayname':
- $this->raw['FN'][0][0] = $value;
+ $this->raw['FN'][0][0] = $this->displayname = $value;
break;
case 'surname':
- $this->raw['N'][0][0] = $value;
+ $this->raw['N'][0][0] = $this->surname = $value;
break;
case 'firstname':
- $this->raw['N'][0][1] = $value;
+ $this->raw['N'][0][1] = $this->firstname = $value;
break;
case 'middlename':
- $this->raw['N'][0][2] = $value;
+ $this->raw['N'][0][2] = $this->middlename = $value;
break;
case 'prefix':
@@ -296,11 +295,11 @@ class rcube_vcard
break;
case 'nickname':
- $this->raw['NICKNAME'][0][0] = $value;
+ $this->raw['NICKNAME'][0][0] = $this->nickname = $value;
break;
case 'organization':
- $this->raw['ORG'][0][0] = $value;
+ $this->raw['ORG'][0][0] = $this->organization = $value;
break;
case 'photo':
@@ -348,8 +347,10 @@ class rcube_vcard
if (($tag = self::$fieldmap[$field]) && (is_array($value) || strlen($value))) {
$index = count($this->raw[$tag]);
$this->raw[$tag][$index] = (array)$value;
- if ($type)
+ if ($type) {
+ $typemap = array_flip($this->typemap);
$this->raw[$tag][$index]['type'] = explode(',', ($typemap[$type_uc] ? $typemap[$type_uc] : $type));
+ }
}
break;
}
@@ -784,42 +785,9 @@ class rcube_vcard
*/
private static function detect_encoding($string)
{
- if (substr($string, 0, 4) == "\0\0\xFE\xFF") return 'UTF-32BE'; // Big Endian
- if (substr($string, 0, 4) == "\xFF\xFE\0\0") return 'UTF-32LE'; // Little Endian
- if (substr($string, 0, 2) == "\xFE\xFF") return 'UTF-16BE'; // Big Endian
- if (substr($string, 0, 2) == "\xFF\xFE") return 'UTF-16LE'; // Little Endian
- if (substr($string, 0, 3) == "\xEF\xBB\xBF") return 'UTF-8';
-
- // heuristics
- if ($string[0] == "\0" && $string[1] == "\0" && $string[2] == "\0" && $string[3] != "\0") return 'UTF-32BE';
- if ($string[0] != "\0" && $string[1] == "\0" && $string[2] == "\0" && $string[3] == "\0") return 'UTF-32LE';
- if ($string[0] == "\0" && $string[1] != "\0" && $string[2] == "\0" && $string[3] != "\0") return 'UTF-16BE';
- if ($string[0] != "\0" && $string[1] == "\0" && $string[2] != "\0" && $string[3] == "\0") return 'UTF-16LE';
-
- // use mb_detect_encoding()
- $encodings = array('UTF-8', 'ISO-8859-1', 'ISO-8859-2', 'ISO-8859-3',
- 'ISO-8859-4', 'ISO-8859-5', 'ISO-8859-6', 'ISO-8859-7', 'ISO-8859-8', 'ISO-8859-9',
- 'ISO-8859-10', 'ISO-8859-13', 'ISO-8859-14', 'ISO-8859-15', 'ISO-8859-16',
- 'WINDOWS-1252', 'WINDOWS-1251', 'BIG5', 'GB2312');
-
- if (function_exists('mb_detect_encoding') && ($enc = mb_detect_encoding($string, $encodings)))
- return $enc;
-
- // No match, check for UTF-8
- // from http://w3.org/International/questions/qa-forms-utf-8.html
- if (preg_match('/\A(
- [\x09\x0A\x0D\x20-\x7E]
- | [\xC2-\xDF][\x80-\xBF]
- | \xE0[\xA0-\xBF][\x80-\xBF]
- | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}
- | \xED[\x80-\x9F][\x80-\xBF]
- | \xF0[\x90-\xBF][\x80-\xBF]{2}
- | [\xF1-\xF3][\x80-\xBF]{3}
- | \xF4[\x80-\x8F][\x80-\xBF]{2}
- )*\z/xs', substr($string, 0, 2048)))
- return 'UTF-8';
-
- return rcube::get_instance()->config->get('default_charset', 'ISO-8859-1'); # fallback to Latin-1
+ $fallback = rcube::get_instance()->config->get('default_charset', 'ISO-8859-1'); // fallback to Latin-1
+
+ return rcube_charset::detect($string, $fallback);
}
}