Gracefully handle buggy messages with either missing or duplicated X-Kolab-Type headers
This commit is contained in:
parent
cf3426a4ae
commit
fb5c1c40d1
1 changed files with 29 additions and 1 deletions
|
@ -458,12 +458,40 @@ class kolab_storage_folder
|
||||||
$this->imap->set_folder($folder);
|
$this->imap->set_folder($folder);
|
||||||
|
|
||||||
$headers = $this->imap->get_message_headers($msguid);
|
$headers = $this->imap->get_message_headers($msguid);
|
||||||
|
$message = null;
|
||||||
|
|
||||||
// Message doesn't exist?
|
// Message doesn't exist?
|
||||||
if (empty($headers)) {
|
if (empty($headers)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// extract the X-Kolab-Type header from the XML attachment part if missing
|
||||||
|
if (empty($headers->others['x-kolab-type'])) {
|
||||||
|
$message = new rcube_message($msguid);
|
||||||
|
foreach ((array)$message->attachments as $part) {
|
||||||
|
if (strpos($part->mimetype, kolab_format::KTYPE_PREFIX) === 0) {
|
||||||
|
$headers->others['x-kolab-type'] = $part->mimetype;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// fix buggy messages stating the X-Kolab-Type header twice
|
||||||
|
else if (is_array($headers->others['x-kolab-type'])) {
|
||||||
|
$headers->others['x-kolab-type'] = reset($headers->others['x-kolab-type']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// no object type header found: abort
|
||||||
|
if (empty($headers->others['x-kolab-type'])) {
|
||||||
|
rcube::raise_error(array(
|
||||||
|
'code' => 600,
|
||||||
|
'type' => 'php',
|
||||||
|
'file' => __FILE__,
|
||||||
|
'line' => __LINE__,
|
||||||
|
'message' => "No X-Kolab-Type information found in message $msguid ($this->name).",
|
||||||
|
), true);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$object_type = kolab_format::mime2object_type($headers->others['x-kolab-type']);
|
$object_type = kolab_format::mime2object_type($headers->others['x-kolab-type']);
|
||||||
$content_type = kolab_format::KTYPE_PREFIX . $object_type;
|
$content_type = kolab_format::KTYPE_PREFIX . $object_type;
|
||||||
|
|
||||||
|
@ -471,7 +499,7 @@ class kolab_storage_folder
|
||||||
if ($type != '*' && $object_type != $type)
|
if ($type != '*' && $object_type != $type)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
$message = new rcube_message($msguid);
|
if (!$message) $message = new rcube_message($msguid);
|
||||||
$attachments = array();
|
$attachments = array();
|
||||||
|
|
||||||
// get XML part
|
// get XML part
|
||||||
|
|
Loading…
Add table
Reference in a new issue