mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-14 20:14:11 +01:00
Fix old format vCard/vCalendar quoting issue
This commit is contained in:
parent
68cf0235e2
commit
ed79fca436
@ -650,233 +650,238 @@ class Horde_iCalendar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Charset and encoding handling.
|
// Charset and encoding handling.
|
||||||
if (isset($params['QUOTED-PRINTABLE'])) {
|
if (isset($params['QUOTED-PRINTABLE'])) {
|
||||||
$params['ENCODING'] = 'QUOTED-PRINTABLE';
|
$params['ENCODING'] = 'QUOTED-PRINTABLE';
|
||||||
}
|
}
|
||||||
if (isset($params['BASE64'])) {
|
if (isset($params['BASE64'])) {
|
||||||
$params['ENCODING'] = 'BASE64';
|
$params['ENCODING'] = 'BASE64';
|
||||||
}
|
}
|
||||||
if (isset($params['ENCODING'])) {
|
if (isset($params['ENCODING'])) {
|
||||||
switch (String::upper($params['ENCODING'])) {
|
switch (String::upper($params['ENCODING'])) {
|
||||||
case 'Q':
|
case 'Q':
|
||||||
case 'QUOTED-PRINTABLE':
|
case 'QUOTED-PRINTABLE':
|
||||||
$value = quoted_printable_decode($value);
|
$value = quoted_printable_decode($value);
|
||||||
if (isset($params['CHARSET'])) {
|
if (isset($params['CHARSET'])) {
|
||||||
$value = $GLOBALS['egw']->translation->convert($value, $params['CHARSET']);
|
$value = $GLOBALS['egw']->translation->convert($value, $params['CHARSET']);
|
||||||
} else {
|
} else {
|
||||||
$value = $GLOBALS['egw']->translation->convert($value,
|
$value = $GLOBALS['egw']->translation->convert($value,
|
||||||
empty($charset) ? ($this->isOldFormat() ? 'iso-8859-1' : 'utf-8') : $charset);
|
empty($charset) ? ($this->isOldFormat() ? 'iso-8859-1' : 'utf-8') : $charset);
|
||||||
}
|
}
|
||||||
// Funambol hack :-(
|
// Funambol hack :-(
|
||||||
$value = str_replace('\\\\n', "\n", $value);
|
$value = str_replace('\\\\n', "\n", $value);
|
||||||
break;
|
break;
|
||||||
case 'B':
|
case 'B':
|
||||||
case 'BASE64':
|
case 'BASE64':
|
||||||
$value = base64_decode($value);
|
$value = base64_decode($value);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} elseif (isset($params['CHARSET'])) {
|
} elseif (isset($params['CHARSET'])) {
|
||||||
$value = $GLOBALS['egw']->translation->convert($value, $params['CHARSET']);
|
$value = $GLOBALS['egw']->translation->convert($value, $params['CHARSET']);
|
||||||
} else {
|
} else {
|
||||||
// As per RFC 2279, assume UTF8 if we don't have an
|
// As per RFC 2279, assume UTF8 if we don't have an
|
||||||
// explicit charset parameter.
|
// explicit charset parameter.
|
||||||
$value = $GLOBALS['egw']->translation->convert($value,
|
$value = $GLOBALS['egw']->translation->convert($value,
|
||||||
empty($charset) ? ($this->isOldFormat() ? 'iso-8859-1' : 'utf-8') : $charset);
|
empty($charset) ? ($this->isOldFormat() ? 'iso-8859-1' : 'utf-8') : $charset);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get timezone info for date fields from $params.
|
// Get timezone info for date fields from $params.
|
||||||
$tzid = isset($params['TZID']) ? trim($params['TZID'], '\"') : false;
|
$tzid = isset($params['TZID']) ? trim($params['TZID'], '\"') : false;
|
||||||
|
|
||||||
switch ($tag) {
|
switch ($tag) {
|
||||||
case 'VERSION': // already processed
|
case 'VERSION': // already processed
|
||||||
break;
|
break;
|
||||||
// Date fields.
|
// Date fields.
|
||||||
case 'COMPLETED':
|
case 'COMPLETED':
|
||||||
case 'CREATED':
|
case 'CREATED':
|
||||||
case 'LAST-MODIFIED':
|
case 'LAST-MODIFIED':
|
||||||
$this->setAttribute($tag, $this->_parseDateTime($value, $tzid), $params);
|
$this->setAttribute($tag, $this->_parseDateTime($value, $tzid), $params);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'BDAY':
|
case 'BDAY':
|
||||||
case 'X-SYNCJE-ANNIVERSARY':
|
case 'X-SYNCJE-ANNIVERSARY':
|
||||||
$this->setAttribute($tag, $value, $params, true, $this->_parseDate($value));
|
$this->setAttribute($tag, $value, $params, true, $this->_parseDate($value));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'DTEND':
|
case 'DTEND':
|
||||||
case 'DTSTART':
|
case 'DTSTART':
|
||||||
case 'DTSTAMP':
|
case 'DTSTAMP':
|
||||||
case 'DUE':
|
case 'DUE':
|
||||||
case 'AALARM':
|
case 'AALARM':
|
||||||
case 'DALARM':
|
case 'DALARM':
|
||||||
case 'RECURRENCE-ID':
|
case 'RECURRENCE-ID':
|
||||||
case 'X-RECURRENCE-ID':
|
case 'X-RECURRENCE-ID':
|
||||||
// types like AALARM may contain additional data after a ;
|
// types like AALARM may contain additional data after a ;
|
||||||
// ignore these.
|
// ignore these.
|
||||||
$ts = explode(';', $value);
|
$ts = explode(';', $value);
|
||||||
if (isset($params['VALUE']) && $params['VALUE'] == 'DATE') {
|
if (isset($params['VALUE']) && $params['VALUE'] == 'DATE') {
|
||||||
$isDate = true;
|
$isDate = true;
|
||||||
$this->setAttribute($tag, $this->_parseDateTime($ts[0], $tzid), $params, true, $this->_parseDate($ts[0]));
|
$this->setAttribute($tag, $this->_parseDateTime($ts[0], $tzid), $params, true, $this->_parseDate($ts[0]));
|
||||||
} else {
|
} else {
|
||||||
$this->setAttribute($tag, $this->_parseDateTime($ts[0], $tzid), $params);
|
$this->setAttribute($tag, $this->_parseDateTime($ts[0], $tzid), $params);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'TRIGGER':
|
case 'TRIGGER':
|
||||||
if (isset($params['VALUE'])) {
|
if (isset($params['VALUE'])) {
|
||||||
if ($params['VALUE'] == 'DATE-TIME') {
|
if ($params['VALUE'] == 'DATE-TIME') {
|
||||||
$this->setAttribute($tag, $this->_parseDateTime($value, $tzid), $params);
|
$this->setAttribute($tag, $this->_parseDateTime($value, $tzid), $params);
|
||||||
} else {
|
} else {
|
||||||
$this->setAttribute($tag, $this->_parseDuration($value), $params);
|
$this->setAttribute($tag, $this->_parseDuration($value), $params);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->setAttribute($tag, $this->_parseDuration($value), $params);
|
$this->setAttribute($tag, $this->_parseDuration($value), $params);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Comma or semicolon seperated dates.
|
// Comma or semicolon seperated dates.
|
||||||
case 'EXDATE':
|
case 'EXDATE':
|
||||||
case 'RDATE':
|
case 'RDATE':
|
||||||
$dates = array();
|
$dates = array();
|
||||||
preg_match_all('/[;,]([^;,]*)/', ';' . $value, $values);
|
preg_match_all('/[;,]([^;,]*)/', ';' . $value, $values);
|
||||||
|
|
||||||
foreach ($values[1] as $value) {
|
foreach ($values[1] as $value) {
|
||||||
if ((isset($params['VALUE'])
|
if ((isset($params['VALUE'])
|
||||||
&& $params['VALUE'] == 'DATE') || (!isset($params['VALUE']) && $isDate)) {
|
&& $params['VALUE'] == 'DATE') || (!isset($params['VALUE']) && $isDate)) {
|
||||||
$dates[] = $this->_parseDate(trim($value));
|
$dates[] = $this->_parseDate(trim($value));
|
||||||
} else {
|
} else {
|
||||||
$dates[] = $this->_parseDateTime(trim($value), $tzid);
|
$dates[] = $this->_parseDateTime(trim($value), $tzid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->setAttribute($tag, isset($dates[0]) ? $dates[0] : null, $params, true, $dates);
|
$this->setAttribute($tag, isset($dates[0]) ? $dates[0] : null, $params, true, $dates);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Duration fields.
|
// Duration fields.
|
||||||
case 'DURATION':
|
case 'DURATION':
|
||||||
$this->setAttribute($tag, $this->_parseDuration($value), $params);
|
$this->setAttribute($tag, $this->_parseDuration($value), $params);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Period of time fields.
|
// Period of time fields.
|
||||||
case 'FREEBUSY':
|
case 'FREEBUSY':
|
||||||
$periods = array();
|
$periods = array();
|
||||||
preg_match_all('/,([^,]*)/', ',' . $value, $values);
|
preg_match_all('/,([^,]*)/', ',' . $value, $values);
|
||||||
foreach ($values[1] as $value) {
|
foreach ($values[1] as $value) {
|
||||||
$periods[] = $this->_parsePeriod($value);
|
$periods[] = $this->_parsePeriod($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setAttribute($tag, isset($periods[0]) ? $periods[0] : null, $params, true, $periods);
|
$this->setAttribute($tag, isset($periods[0]) ? $periods[0] : null, $params, true, $periods);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// UTC offset fields.
|
// UTC offset fields.
|
||||||
case 'TZOFFSETFROM':
|
case 'TZOFFSETFROM':
|
||||||
case 'TZOFFSETTO':
|
case 'TZOFFSETTO':
|
||||||
$this->setAttribute($tag, $this->_parseUtcOffset($value), $params);
|
$this->setAttribute($tag, $this->_parseUtcOffset($value), $params);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Integer fields.
|
// Integer fields.
|
||||||
case 'PERCENT-COMPLETE':
|
case 'PERCENT-COMPLETE':
|
||||||
case 'PRIORITY':
|
case 'PRIORITY':
|
||||||
case 'REPEAT':
|
case 'REPEAT':
|
||||||
case 'SEQUENCE':
|
case 'SEQUENCE':
|
||||||
$this->setAttribute($tag, intval($value), $params);
|
$this->setAttribute($tag, intval($value), $params);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Geo fields.
|
// Geo fields.
|
||||||
case 'GEO':
|
case 'GEO':
|
||||||
if ($this->isOldFormat()) {
|
if ($this->isOldFormat()) {
|
||||||
$floats = explode(',', $value);
|
$floats = explode(',', $value);
|
||||||
$value = array('latitude' => floatval($floats[1]),
|
$value = array('latitude' => floatval($floats[1]),
|
||||||
'longitude' => floatval($floats[0]));
|
'longitude' => floatval($floats[0]));
|
||||||
} else {
|
} else {
|
||||||
$floats = explode(';', $value);
|
$floats = explode(';', $value);
|
||||||
$value = array('latitude' => floatval($floats[0]),
|
$value = array('latitude' => floatval($floats[0]),
|
||||||
'longitude' => floatval($floats[1]));
|
'longitude' => floatval($floats[1]));
|
||||||
}
|
}
|
||||||
$this->setAttribute($tag, $value, $params);
|
$this->setAttribute($tag, $value, $params);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Recursion fields. # add more flexibility
|
// Recursion fields. # add more flexibility
|
||||||
#case 'EXRULE':
|
#case 'EXRULE':
|
||||||
#case 'RRULE':
|
#case 'RRULE':
|
||||||
# $this->setAttribute($tag, trim($value), $params);
|
# $this->setAttribute($tag, trim($value), $params);
|
||||||
# break;
|
# break;
|
||||||
|
|
||||||
// Binary fields.
|
// Binary fields.
|
||||||
case 'PHOTO':
|
case 'PHOTO':
|
||||||
$this->setAttribute($tag, $value, $params);
|
$this->setAttribute($tag, $value, $params);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// ADR, ORG and N are lists seperated by unescaped semicolons
|
// ADR, ORG and N are lists seperated by unescaped semicolons
|
||||||
// with a specific number of slots.
|
// with a specific number of slots.
|
||||||
case 'ADR':
|
case 'ADR':
|
||||||
case 'N':
|
case 'N':
|
||||||
case 'ORG':
|
case 'ORG':
|
||||||
$value = trim($value);
|
$value = trim($value);
|
||||||
// As of rfc 2426 2.4.2 semicolon, comma, and colon must
|
// As of rfc 2426 2.4.2 semicolon, comma, and colon must
|
||||||
// be escaped (comma is unescaped after splitting below).
|
// be escaped (comma is unescaped after splitting below).
|
||||||
$value = str_replace(array('\\n', '\\N', '\\;', '\\:'),
|
$value = str_replace(array('\\n', '\\N', '\\;', '\\:'),
|
||||||
array("\n", "\n", ';', ':'),
|
array("\n", "\n", ';', ':'),
|
||||||
$value);
|
$value);
|
||||||
|
|
||||||
// Split by unescaped semicolons:
|
// Split by unescaped semicolons:
|
||||||
$values = preg_split('/(?<!\\\\);/', $value);
|
$values = preg_split('/(?<!\\\\);/', $value);
|
||||||
$value = str_replace('\\;', ';', $value);
|
$value = str_replace('\\;', ';', $value);
|
||||||
$values = str_replace('\\;', ';', $values);
|
$values = str_replace('\\;', ';', $values);
|
||||||
$value = str_replace('\\,', ',', $value);
|
$value = str_replace('\\,', ',', $value);
|
||||||
$values = str_replace('\\,', ',', $values);
|
$values = str_replace('\\,', ',', $values);
|
||||||
$this->setAttribute($tag, trim($value), $params, true, $values);
|
$this->setAttribute($tag, trim($value), $params, true, $values);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// CATEGORIES is a lists seperated by unescaped commas
|
// CATEGORIES is a lists seperated by unescaped commas
|
||||||
// with a unspecific number of slots.
|
// with a unspecific number of slots.
|
||||||
case 'CATEGORIES':
|
case 'CATEGORIES':
|
||||||
$value = trim($value);
|
$value = trim($value);
|
||||||
// As of rfc 2426 2.4.2 semicolon, comma, and colon must
|
// As of rfc 2426 2.4.2 semicolon, comma, and colon must
|
||||||
// be escaped (semicolon is unescaped after splitting below).
|
// be escaped (semicolon is unescaped after splitting below).
|
||||||
$value = str_replace(array('\\n', '\\N', '\\,', '\\:'),
|
$value = str_replace(array('\\n', '\\N', '\\,', '\\:'),
|
||||||
array("\n", "\n", ',', ':'),
|
array("\n", "\n", ',', ':'),
|
||||||
$value);
|
$value);
|
||||||
|
|
||||||
// Split by unescaped commas:
|
// Split by unescaped commas:
|
||||||
$values = preg_split('/(?<!\\\\),/', $value);
|
$values = preg_split('/(?<!\\\\),/', $value);
|
||||||
$value = str_replace('\\;', ';', $value);
|
$value = str_replace('\\;', ';', $value);
|
||||||
$values = str_replace('\\;', ';', $values);
|
$values = str_replace('\\;', ';', $values);
|
||||||
$value = str_replace('\\,', ',', $value);
|
$value = str_replace('\\,', ',', $value);
|
||||||
$values = str_replace('\\,', ',', $values);
|
$values = str_replace('\\,', ',', $values);
|
||||||
$this->setAttribute($tag, trim($value), $params, true, $values);
|
$this->setAttribute($tag, trim($value), $params, true, $values);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// String fields.
|
// String fields.
|
||||||
default:
|
default:
|
||||||
if ($this->isOldFormat()) {
|
if ($this->isOldFormat()) {
|
||||||
// vCalendar 1.0 and vCard 2.1 only escape semicolons
|
$value = trim($value);
|
||||||
// and use unescaped semicolons to create lists.
|
// vCalendar 1.0 and vCard 2.1 only escape semicolons
|
||||||
$value = trim($value);
|
// and use unescaped semicolons to create lists.
|
||||||
// Split by unescaped semicolons:
|
$value = str_replace(array('\\n', '\\N', '\\;', '\\:'),
|
||||||
$values = preg_split('/(?<!\\\\);/', $value);
|
array("\n", "\n", ';', ':'),
|
||||||
$value = str_replace('\\;', ';', $value);
|
$value);
|
||||||
$values = str_replace('\\;', ';', $values);
|
|
||||||
$this->setAttribute($tag, trim($value), $params, true, $values);
|
// Split by unescaped semicolons:
|
||||||
} else {
|
$values = preg_split('/(?<!\\\\);/', $value);
|
||||||
$value = trim($value);
|
$value = str_replace('\\;', ';', $value);
|
||||||
// As of rfc 2426 2.4.2 semicolon, comma, and colon
|
$values = str_replace('\\;', ';', $values);
|
||||||
// must be escaped (comma is unescaped after splitting
|
$value = str_replace('\\,', ',', $value);
|
||||||
// below).
|
$values = str_replace('\\,', ',', $values);
|
||||||
$value = str_replace(array('\\n', '\\N', '\\;', '\\:', '\\\\'),
|
$this->setAttribute($tag, trim($value), $params, true, $values);
|
||||||
array("\n", "\n", ';', ':', '\\'),
|
} else {
|
||||||
$value);
|
$value = trim($value);
|
||||||
|
// As of rfc 2426 2.4.2 semicolon, comma, and colon
|
||||||
// Split by unescaped commas.
|
// must be escaped (comma is unescaped after splitting
|
||||||
$values = preg_split('/(?<!\\\\),/', $value);
|
// below).
|
||||||
$value = str_replace('\\,', ',', $value);
|
$value = str_replace(array('\\n', '\\N', '\\;', '\\:', '\\\\'),
|
||||||
$values = str_replace('\\,', ',', $values);
|
array("\n", "\n", ';', ':', '\\'),
|
||||||
|
$value);
|
||||||
$this->setAttribute($tag, trim($value), $params, true, $values);
|
|
||||||
}
|
// Split by unescaped commas.
|
||||||
break;
|
$values = preg_split('/(?<!\\\\),/', $value);
|
||||||
}
|
$value = str_replace('\\,', ',', $value);
|
||||||
|
$values = str_replace('\\,', ',', $values);
|
||||||
|
$this->setAttribute($tag, trim($value), $params, true, $values);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user