Changeset View
Changeset View
Standalone View
Standalone View
plugins/libkolab/lib/kolab_storage_folder.php
Show First 20 Lines • Show All 152 Lines • ▼ Show 20 Lines | class kolab_storage_folder extends kolab_storage_folder_api | ||||
public function get_uid() | public function get_uid() | ||||
{ | { | ||||
// UID is defined in folder METADATA | // UID is defined in folder METADATA | ||||
$metakeys = array(kolab_storage::UID_KEY_SHARED, kolab_storage::UID_KEY_CYRUS); | $metakeys = array(kolab_storage::UID_KEY_SHARED, kolab_storage::UID_KEY_CYRUS); | ||||
$metadata = $this->get_metadata(); | $metadata = $this->get_metadata(); | ||||
if ($metadata !== null) { | if ($metadata !== null) { | ||||
foreach ($metakeys as $key) { | foreach ($metakeys as $key) { | ||||
if ($uid = $metadata[$key]) { | if ($uid = ($metadata[$key] ?? null)) { | ||||
return $uid; | return $uid; | ||||
} | } | ||||
} | } | ||||
// generate a folder UID and set it to IMAP | // generate a folder UID and set it to IMAP | ||||
$uid = rtrim(chunk_split(md5($this->name . $this->get_owner() . uniqid('-', true)), 12, '-'), '-'); | $uid = rtrim(chunk_split(md5($this->name . $this->get_owner() . uniqid('-', true)), 12, '-'), '-'); | ||||
if ($this->set_uid($uid)) { | if ($this->set_uid($uid)) { | ||||
return $uid; | return $uid; | ||||
Show All 22 Lines | class kolab_storage_folder extends kolab_storage_folder_api | ||||
/** | /** | ||||
* Compose a folder Etag identifier | * Compose a folder Etag identifier | ||||
*/ | */ | ||||
public function get_ctag() | public function get_ctag() | ||||
{ | { | ||||
$fdata = $this->get_imap_data(); | $fdata = $this->get_imap_data(); | ||||
$this->check_error(); | $this->check_error(); | ||||
return sprintf('%d-%d-%d', $fdata['UIDVALIDITY'], $fdata['HIGHESTMODSEQ'], $fdata['UIDNEXT']); | return sprintf('%d-%d-%d', $fdata['UIDVALIDITY'] ?? null, $fdata['HIGHESTMODSEQ'] ?? null, $fdata['UIDNEXT'] ?? null); | ||||
} | } | ||||
/** | /** | ||||
* Check activation status of this folder | * Check activation status of this folder | ||||
* | * | ||||
* @return boolean True if enabled, false if not | * @return boolean True if enabled, false if not | ||||
*/ | */ | ||||
public function is_active() | public function is_active() | ||||
▲ Show 20 Lines • Show All 286 Lines • ▼ Show 20 Lines | public function read_object($msguid, $type = null, $folder = null) | ||||
// check object type header and abort on mismatch | // check object type header and abort on mismatch | ||||
if ($type != '*' && strpos($object_type, $type) !== 0 && !($object_type == 'distribution-list' && $type == 'contact')) { | if ($type != '*' && strpos($object_type, $type) !== 0 && !($object_type == 'distribution-list' && $type == 'contact')) { | ||||
return false; | return false; | ||||
} | } | ||||
$attachments = array(); | $attachments = array(); | ||||
// get XML part | // get XML part | ||||
$xml = null; | |||||
foreach ((array)$message->attachments as $part) { | foreach ((array)$message->attachments as $part) { | ||||
if (!$xml && ($part->mimetype == $content_type || preg_match('!application/([a-z.]+\+)?xml!i', $part->mimetype))) { | if (!$xml && ($part->mimetype == $content_type || preg_match('!application/([a-z.]+\+)?xml!i', $part->mimetype))) { | ||||
$xml = $message->get_part_body($part->mime_id, true); | $xml = $message->get_part_body($part->mime_id, true); | ||||
} | } | ||||
else if ($part->filename || $part->content_id) { | else if ($part->filename || $part->content_id) { | ||||
$key = $part->content_id ? trim($part->content_id, '<>') : $part->filename; | $key = $part->content_id ? trim($part->content_id, '<>') : $part->filename; | ||||
$size = null; | $size = null; | ||||
▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | public function save(&$object, $type = null, $uid = null) | ||||
if (!$this->valid || empty($object)) { | if (!$this->valid || empty($object)) { | ||||
return false; | return false; | ||||
} | } | ||||
if (!$type) | if (!$type) | ||||
$type = $this->type; | $type = $this->type; | ||||
// copy attachments from old message | // copy attachments from old message | ||||
$copyfrom = $object['_copyfrom'] ?: $object['_msguid']; | $copyfrom = $object['_copyfrom'] ?? ($object['_msguid'] ?? null); | ||||
if (!empty($copyfrom) && ($old = $this->cache->get($copyfrom, $type, $object['_mailbox']))) { | if (!empty($copyfrom) && ($old = $this->cache->get($copyfrom, $type, $object['_mailbox']))) { | ||||
foreach ((array)$old['_attachments'] as $key => $att) { | foreach ((array)$old['_attachments'] as $key => $att) { | ||||
if (!isset($object['_attachments'][$key])) { | if (!isset($object['_attachments'][$key])) { | ||||
$object['_attachments'][$key] = $old['_attachments'][$key]; | $object['_attachments'][$key] = $old['_attachments'][$key]; | ||||
} | } | ||||
// unset deleted attachment entries | // unset deleted attachment entries | ||||
if ($object['_attachments'][$key] == false) { | if ($object['_attachments'][$key] == false) { | ||||
unset($object['_attachments'][$key]); | unset($object['_attachments'][$key]); | ||||
Show All 12 Lines | public function save(&$object, $type = null, $uid = null) | ||||
$attkey = 'kolab-picture.png'; // this file name is hard-coded in libkolab/kolabformatV2/contact.cpp | $attkey = 'kolab-picture.png'; // this file name is hard-coded in libkolab/kolabformatV2/contact.cpp | ||||
$object['_attachments'][$attkey] = array( | $object['_attachments'][$attkey] = array( | ||||
'mimetype'=> rcube_mime::image_content_type($object['photo']), | 'mimetype'=> rcube_mime::image_content_type($object['photo']), | ||||
'content' => preg_match('![^a-z0-9/=+-]!i', $object['photo']) ? $object['photo'] : base64_decode($object['photo']), | 'content' => preg_match('![^a-z0-9/=+-]!i', $object['photo']) ? $object['photo'] : base64_decode($object['photo']), | ||||
); | ); | ||||
} | } | ||||
// process attachments | // process attachments | ||||
if (is_array($object['_attachments'])) { | if (is_array($object['_attachments'] ?? null)) { | ||||
$numatt = count($object['_attachments']); | $numatt = count($object['_attachments']); | ||||
foreach ($object['_attachments'] as $key => $attachment) { | foreach ($object['_attachments'] as $key => $attachment) { | ||||
// FIXME: kolab_storage and Roundcube attachment hooks use different fields! | // FIXME: kolab_storage and Roundcube attachment hooks use different fields! | ||||
if (empty($attachment['content']) && !empty($attachment['data'])) { | if (empty($attachment['content']) && !empty($attachment['data'])) { | ||||
$attachment['content'] = $attachment['data']; | $attachment['content'] = $attachment['data']; | ||||
unset($attachment['data'], $object['_attachments'][$key]['data']); | unset($attachment['data'], $object['_attachments'][$key]['data']); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | public function save(&$object, $type = null, $uid = null) | ||||
$object['_msguid'] = $msguid; | $object['_msguid'] = $msguid; | ||||
$object['_mailbox'] = $this->name; | $object['_mailbox'] = $this->name; | ||||
} | } | ||||
$result = $this->imap->save_message($this->name, $raw_msg, null, false, null, null, $binary); | $result = $this->imap->save_message($this->name, $raw_msg, null, false, null, null, $binary); | ||||
// update cache with new UID | // update cache with new UID | ||||
if ($result) { | if ($result) { | ||||
$old_uid = $object['_msguid']; | $old_uid = $object['_msguid'] ?? null; | ||||
$object['_msguid'] = $result; | $object['_msguid'] = $result; | ||||
$object['_mailbox'] = $this->name; | $object['_mailbox'] = $this->name; | ||||
if ($old_uid) { | if ($old_uid) { | ||||
// delete old message | // delete old message | ||||
$this->cache->imap_mode(true); | $this->cache->imap_mode(true); | ||||
$this->imap->delete_message($old_uid, $object['_mailbox']); | $this->imap->delete_message($old_uid, $object['_mailbox']); | ||||
▲ Show 20 Lines • Show All 200 Lines • ▼ Show 20 Lines | class kolab_storage_folder extends kolab_storage_folder_api | ||||
* @param string $body_file Reference to filename of message body | * @param string $body_file Reference to filename of message body | ||||
* | * | ||||
* @return mixed Message as string or array with two elements | * @return mixed Message as string or array with two elements | ||||
* (one for message file path, second for message headers) | * (one for message file path, second for message headers) | ||||
*/ | */ | ||||
private function build_message(&$object, $type, $binary, &$body_file) | private function build_message(&$object, $type, $binary, &$body_file) | ||||
{ | { | ||||
// load old object to preserve data we don't understand/process | // load old object to preserve data we don't understand/process | ||||
if (is_object($object['_formatobj'])) | $format = null; | ||||
if (is_object($object['_formatobj'] ?? null)) | |||||
$format = $object['_formatobj']; | $format = $object['_formatobj']; | ||||
else if ($object['_msguid'] && ($old = $this->cache->get($object['_msguid'], $type, $object['_mailbox']))) | else if ($object['_msguid'] ?? null && ($old = $this->cache->get($object['_msguid'], $type, $object['_mailbox'] ?? null))) | ||||
$format = $old['_formatobj']; | $format = $old['_formatobj'] ?? null; | ||||
// create new kolab_format instance | // create new kolab_format instance | ||||
if (!$format) | if (!$format) | ||||
$format = kolab_format::factory($type, kolab_storage::$version); | $format = kolab_format::factory($type, kolab_storage::$version); | ||||
if (PEAR::isError($format)) | if (PEAR::isError($format)) | ||||
return false; | return false; | ||||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | // $headers['Message-ID'] = $rcmail->gen_message_id(); | ||||
'kolab.xml', // filename | 'kolab.xml', // filename | ||||
false, // is_file | false, // is_file | ||||
'8bit', // encoding | '8bit', // encoding | ||||
'attachment', // disposition | 'attachment', // disposition | ||||
RCUBE_CHARSET // charset | RCUBE_CHARSET // charset | ||||
); | ); | ||||
$part_id++; | $part_id++; | ||||
$is_file = false; | |||||
// save object attachments as separate parts | // save object attachments as separate parts | ||||
foreach ((array)$object['_attachments'] as $key => $att) { | foreach ((array)($object['_attachments'] ?? []) as $key => $att) { | ||||
if (empty($att['content']) && !empty($att['id'])) { | if (empty($att['content']) && !empty($att['id'])) { | ||||
// @TODO: use IMAP CATENATE to skip attachment fetch+push operation | // @TODO: use IMAP CATENATE to skip attachment fetch+push operation | ||||
$msguid = $object['_copyfrom'] ?: ($object['_msguid'] ?: $object['uid']); | $msguid = $object['_copyfrom'] ?: ($object['_msguid'] ?: $object['uid']); | ||||
if ($is_file) { | if ($is_file) { | ||||
$att['path'] = tempnam($temp_dir, 'rcmAttmnt'); | $att['path'] = tempnam($temp_dir, 'rcmAttmnt'); | ||||
if (($fp = fopen($att['path'], 'w')) && $this->get_attachment($msguid, $att['id'], $object['_mailbox'], false, $fp, true)) { | if (($fp = fopen($att['path'], 'w')) && $this->get_attachment($msguid, $att['id'], $object['_mailbox'], false, $fp, true)) { | ||||
fclose($fp); | fclose($fp); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 164 Lines • Show Last 20 Lines |