|
|
@ -497,15 +497,17 @@ class rcube_vcard
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private static function vcard_decode($vcard)
|
|
|
|
private static function vcard_decode($vcard)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Perform RFC2425 line unfolding
|
|
|
|
// Perform RFC2425 line unfolding and split lines
|
|
|
|
$vcard = preg_replace(array("/\r/", "/\n\s+/"), '', $vcard);
|
|
|
|
$vcard = preg_replace(array("/\r/", "/\n\s+/"), '', $vcard);
|
|
|
|
|
|
|
|
$lines = explode("\n", $vcard);
|
|
|
|
$lines = preg_split('/\r?\n/', $vcard);
|
|
|
|
$data = array();
|
|
|
|
$data = array();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for ($i=0; $i < count($lines); $i++) {
|
|
|
|
for ($i=0; $i < count($lines); $i++) {
|
|
|
|
if (!preg_match('/^([^\\:]*):(.+)$/', $lines[$i], $line))
|
|
|
|
if (!preg_match('/^([^:]+):(.+)$/', $lines[$i], $line))
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (preg_match('/^(BEGIN|END)$/i', $line[1]))
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
// convert 2.1-style "EMAIL;internet;home:" to 3.0-style "EMAIL;TYPE=internet;TYPE=home:"
|
|
|
|
// convert 2.1-style "EMAIL;internet;home:" to 3.0-style "EMAIL;TYPE=internet;TYPE=home:"
|
|
|
|
if (($data['VERSION'][0] == "2.1") && preg_match('/^([^;]+);([^:]+)/', $line[1], $regs2) && !preg_match('/^TYPE=/i', $regs2[2])) {
|
|
|
|
if (($data['VERSION'][0] == "2.1") && preg_match('/^([^;]+);([^:]+)/', $line[1], $regs2) && !preg_match('/^TYPE=/i', $regs2[2])) {
|
|
|
@ -514,7 +516,7 @@ class rcube_vcard
|
|
|
|
$line[1] .= ';' . (strpos($prop, '=') ? $prop : 'TYPE='.$prop);
|
|
|
|
$line[1] .= ';' . (strpos($prop, '=') ? $prop : 'TYPE='.$prop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!preg_match('/^(BEGIN|END)$/i', $line[1]) && preg_match_all('/([^\\;]+);?/', $line[1], $regs2)) {
|
|
|
|
if (preg_match_all('/([^\\;]+);?/', $line[1], $regs2)) {
|
|
|
|
$entry = array();
|
|
|
|
$entry = array();
|
|
|
|
$field = strtoupper($regs2[1][0]);
|
|
|
|
$field = strtoupper($regs2[1][0]);
|
|
|
|
|
|
|
|
|
|
|
@ -546,28 +548,6 @@ class rcube_vcard
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Split quoted string
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param string vCard string to split
|
|
|
|
|
|
|
|
* @param string Separator char/string
|
|
|
|
|
|
|
|
* @return array List with splitted values
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private static function vcard_unquote($s, $sep = ';')
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// break string into parts separated by $sep, but leave escaped $sep alone
|
|
|
|
|
|
|
|
if (count($parts = explode($sep, strtr($s, array("\\$sep" => "\007")))) > 1) {
|
|
|
|
|
|
|
|
foreach($parts as $s) {
|
|
|
|
|
|
|
|
$result[] = self::vcard_unquote(strtr($s, array("\007" => "\\$sep")), $sep);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
return strtr($s, array("\r" => '', '\\\\' => '\\', '\n' => "\n", '\,' => ',', '\;' => ';', '\:' => ':'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Decode a given string with the encoding rule from ENCODING attributes
|
|
|
|
* Decode a given string with the encoding rule from ENCODING attributes
|
|
|
|
*
|
|
|
|
*
|
|
|
@ -648,7 +628,29 @@ class rcube_vcard
|
|
|
|
return(implode($sep, (array)$r));
|
|
|
|
return(implode($sep, (array)$r));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
return strtr($s, array('\\' => '\\\\', "\r" => '', "\n" => '\n', ';' => '\;', ':' => '\:'));
|
|
|
|
return strtr($s, array('\\' => '\\\\', "\r" => '', "\n" => '\n', ',' => '\,', ';' => '\;'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Split quoted string
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param string vCard string to split
|
|
|
|
|
|
|
|
* @param string Separator char/string
|
|
|
|
|
|
|
|
* @return array List with splitted values
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private static function vcard_unquote($s, $sep = ';')
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// break string into parts separated by $sep, but leave escaped $sep alone
|
|
|
|
|
|
|
|
if (count($parts = explode($sep, strtr($s, array("\\$sep" => "\007")))) > 1) {
|
|
|
|
|
|
|
|
foreach($parts as $s) {
|
|
|
|
|
|
|
|
$result[] = self::vcard_unquote(strtr($s, array("\007" => "\\$sep")), $sep);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
return strtr($s, array("\r" => '', '\\\\' => '\\', '\n' => "\n", '\N' => "\n", '\,' => ',', '\;' => ';'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -700,5 +702,3 @@ class rcube_vcard
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|