|
|
|
@ -497,14 +497,16 @@ class rcube_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);
|
|
|
|
|
|
|
|
|
|
$lines = preg_split('/\r?\n/', $vcard);
|
|
|
|
|
$lines = explode("\n", $vcard);
|
|
|
|
|
$data = array();
|
|
|
|
|
|
|
|
|
|
for ($i=0; $i < count($lines); $i++) {
|
|
|
|
|
if (!preg_match('/^([^\\:]*):(.+)$/', $lines[$i], $line))
|
|
|
|
|
if (!preg_match('/^([^:]+):(.+)$/', $lines[$i], $line))
|
|
|
|
|
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:"
|
|
|
|
@ -514,7 +516,7 @@ class rcube_vcard
|
|
|
|
|
$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();
|
|
|
|
|
$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
|
|
|
|
|
*
|
|
|
|
@ -648,7 +628,29 @@ class rcube_vcard
|
|
|
|
|
return(implode($sep, (array)$r));
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|