Only search undeleted messages when resolving uids.
Store office-location as Address block in Affiliation and profession into title attribute. Merge initials into nickname.
This commit is contained in:
parent
bafdb3bd63
commit
8af6b9eec3
2 changed files with 50 additions and 27 deletions
|
@ -43,6 +43,7 @@ class kolab_format_contact extends kolab_format
|
||||||
public $addresstypes = array(
|
public $addresstypes = array(
|
||||||
'home' => Address::Home,
|
'home' => Address::Home,
|
||||||
'work' => Address::Work,
|
'work' => Address::Work,
|
||||||
|
'office' => 0,
|
||||||
);
|
);
|
||||||
|
|
||||||
private $gendermap = array(
|
private $gendermap = array(
|
||||||
|
@ -70,13 +71,11 @@ class kolab_format_contact extends kolab_format
|
||||||
'organization' => 'organization',
|
'organization' => 'organization',
|
||||||
'department' => 'department',
|
'department' => 'department',
|
||||||
'job-title' => 'jobtitle',
|
'job-title' => 'jobtitle',
|
||||||
'initials' => 'initials',
|
|
||||||
'birthday' => 'birthday',
|
'birthday' => 'birthday',
|
||||||
'anniversary' => 'anniversary',
|
'anniversary' => 'anniversary',
|
||||||
'phone' => 'phone',
|
'phone' => 'phone',
|
||||||
'im-address' => 'im',
|
'im-address' => 'im',
|
||||||
'web-page' => 'website',
|
'web-page' => 'website',
|
||||||
'office-location' => 'officelocation',
|
|
||||||
'profession' => 'profession',
|
'profession' => 'profession',
|
||||||
'manager-name' => 'manager',
|
'manager-name' => 'manager',
|
||||||
'assistant' => 'assistant',
|
'assistant' => 'assistant',
|
||||||
|
@ -162,17 +161,18 @@ class kolab_format_contact extends kolab_format
|
||||||
|
|
||||||
if (isset($object['nickname']))
|
if (isset($object['nickname']))
|
||||||
$this->obj->setNickNames(self::array2vector($object['nickname']));
|
$this->obj->setNickNames(self::array2vector($object['nickname']));
|
||||||
|
if (isset($object['profession']))
|
||||||
|
$this->obj->setTitles(self::array2vector($object['profession']));
|
||||||
|
|
||||||
// organisation related properties (affiliation)
|
// organisation related properties (affiliation)
|
||||||
$org = new Affiliation;
|
$org = new Affiliation;
|
||||||
|
$offices = new vectoraddress;
|
||||||
if ($object['organization'])
|
if ($object['organization'])
|
||||||
$org->setOrganisation($object['organization']);
|
$org->setOrganisation($object['organization']);
|
||||||
if ($object['department'])
|
if ($object['department'])
|
||||||
$org->setOrganisationalUnits(self::array2vector($object['department']));
|
$org->setOrganisationalUnits(self::array2vector($object['department']));
|
||||||
if ($object['jobtitle'])
|
if ($object['jobtitle'])
|
||||||
$org->setRoles(self::array2vector($object['jobtitle']));
|
$org->setRoles(self::array2vector($object['jobtitle']));
|
||||||
// if ($object['officelocation'])
|
|
||||||
// $org->setOffices(self::array2vector($object['officelocation']));
|
|
||||||
|
|
||||||
$rels = new vectorrelated;
|
$rels = new vectorrelated;
|
||||||
if ($object['manager']) {
|
if ($object['manager']) {
|
||||||
|
@ -185,10 +185,6 @@ class kolab_format_contact extends kolab_format
|
||||||
}
|
}
|
||||||
$org->setRelateds($rels);
|
$org->setRelateds($rels);
|
||||||
|
|
||||||
$orgs = new vectoraffiliation;
|
|
||||||
$orgs->push($org);
|
|
||||||
$this->obj->setAffiliations($orgs);
|
|
||||||
|
|
||||||
// email, im, url
|
// email, im, url
|
||||||
$this->obj->setEmailAddresses(self::array2vector($object['email']));
|
$this->obj->setEmailAddresses(self::array2vector($object['email']));
|
||||||
$this->obj->setIMaddresses(self::array2vector($object['im']));
|
$this->obj->setIMaddresses(self::array2vector($object['im']));
|
||||||
|
@ -214,9 +210,18 @@ class kolab_format_contact extends kolab_format
|
||||||
if ($address['country'])
|
if ($address['country'])
|
||||||
$adr->setCountry($address['country']);
|
$adr->setCountry($address['country']);
|
||||||
|
|
||||||
|
if ($address['type'] == 'office')
|
||||||
|
$offices->push($adr);
|
||||||
|
else
|
||||||
$adrs->push($adr);
|
$adrs->push($adr);
|
||||||
}
|
}
|
||||||
$this->obj->setAddresses($adrs);
|
$this->obj->setAddresses($adrs);
|
||||||
|
$org->setAddresses($offices);
|
||||||
|
|
||||||
|
// add org affiliation after addresses are set
|
||||||
|
$orgs = new vectoraffiliation;
|
||||||
|
$orgs->push($org);
|
||||||
|
$this->obj->setAffiliations($orgs);
|
||||||
|
|
||||||
// telephones
|
// telephones
|
||||||
$tels = new vectortelephone;
|
$tels = new vectortelephone;
|
||||||
|
@ -259,7 +264,7 @@ class kolab_format_contact extends kolab_format
|
||||||
}
|
}
|
||||||
$this->obj->setRelateds($rels);
|
$this->obj->setRelateds($rels);
|
||||||
|
|
||||||
// TODO: handle profession, language, pgppublickey, etc.
|
// TODO: handle language, pgppublickey, etc.
|
||||||
|
|
||||||
|
|
||||||
// cache this data
|
// cache this data
|
||||||
|
@ -299,6 +304,7 @@ class kolab_format_contact extends kolab_format
|
||||||
$object['prefix'] = join(' ', self::vector2array($nc->prefixes()));
|
$object['prefix'] = join(' ', self::vector2array($nc->prefixes()));
|
||||||
$object['suffix'] = join(' ', self::vector2array($nc->suffixes()));
|
$object['suffix'] = join(' ', self::vector2array($nc->suffixes()));
|
||||||
$object['nickname'] = join(' ', self::vector2array($this->obj->nickNames()));
|
$object['nickname'] = join(' ', self::vector2array($this->obj->nickNames()));
|
||||||
|
$object['profession'] = join(' ', self::vector2array($this->obj->titles()));
|
||||||
|
|
||||||
// organisation related properties (affiliation)
|
// organisation related properties (affiliation)
|
||||||
$orgs = $this->obj->affiliations();
|
$orgs = $this->obj->affiliations();
|
||||||
|
@ -306,7 +312,6 @@ class kolab_format_contact extends kolab_format
|
||||||
$org = $orgs->get(0);
|
$org = $orgs->get(0);
|
||||||
$object['organization'] = $org->organisation();
|
$object['organization'] = $org->organisation();
|
||||||
$object['jobtitle'] = join(' ', self::vector2array($org->roles()));
|
$object['jobtitle'] = join(' ', self::vector2array($org->roles()));
|
||||||
// $object['officelocation'] = join(' ', self::vector2array($org->offices()));
|
|
||||||
$object['department'] = join(' ', self::vector2array($org->organisationalUnits()));
|
$object['department'] = join(' ', self::vector2array($org->organisationalUnits()));
|
||||||
$this->read_relateds($org->relateds(), $object);
|
$this->read_relateds($org->relateds(), $object);
|
||||||
}
|
}
|
||||||
|
@ -316,19 +321,9 @@ class kolab_format_contact extends kolab_format
|
||||||
$object['website'] = self::vector2array($this->obj->urls());
|
$object['website'] = self::vector2array($this->obj->urls());
|
||||||
|
|
||||||
// addresses
|
// addresses
|
||||||
$adrtypes = array_flip($this->addresstypes);
|
$this->read_addresses($this->obj->addresses(), $object);
|
||||||
$addresses = $this->obj->addresses();
|
if ($org && ($offices = $org->addresses()))
|
||||||
for ($i=0; $i < $addresses->size(); $i++) {
|
$this->read_addresses($offices, $object, 'office');
|
||||||
$adr = $addresses->get($i);
|
|
||||||
$object['address'][] = array(
|
|
||||||
'type' => $adrtypes[$adr->types()] ? $adrtypes[$adr->types()] : '', /*$adr->label(),*/
|
|
||||||
'street' => $adr->street(),
|
|
||||||
'code' => $adr->code(),
|
|
||||||
'locality' => $adr->locality(),
|
|
||||||
'region' => $adr->region(),
|
|
||||||
'country' => $adr->country()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// telehones
|
// telehones
|
||||||
$tels = $this->obj->telephones();
|
$tels = $this->obj->telephones();
|
||||||
|
@ -401,10 +396,38 @@ class kolab_format_contact extends kolab_format
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// office location goes into an address block
|
||||||
|
if ($record['office-location'])
|
||||||
|
$object['address'][] = array('type' => 'office', 'locality' => $record['office-location']);
|
||||||
|
|
||||||
|
// merge initials into nickname
|
||||||
|
if ($record['initials'])
|
||||||
|
$object['nickname'] = trim($object['nickname'] . ', ' . $record['initials'], ', ');
|
||||||
|
|
||||||
// remove empty fields
|
// remove empty fields
|
||||||
$this->data = array_filter($object);
|
$this->data = array_filter($object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to copy contents of an Address vector to the contact data object
|
||||||
|
*/
|
||||||
|
private function read_addresses($addresses, &$object, $type = null)
|
||||||
|
{
|
||||||
|
$adrtypes = array_flip($this->addresstypes);
|
||||||
|
|
||||||
|
for ($i=0; $i < $addresses->size(); $i++) {
|
||||||
|
$adr = $addresses->get($i);
|
||||||
|
$object['address'][] = array(
|
||||||
|
'type' => $type ? $type : ($adrtypes[$adr->types()] ? $adrtypes[$adr->types()] : ''), /*$adr->label()),*/
|
||||||
|
'street' => $adr->street(),
|
||||||
|
'code' => $adr->code(),
|
||||||
|
'locality' => $adr->locality(),
|
||||||
|
'region' => $adr->region(),
|
||||||
|
'country' => $adr->country()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method to map contents of a Related vector to the contact data object
|
* Helper method to map contents of a Related vector to the contact data object
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -406,7 +406,7 @@ class kolab_storage_folder
|
||||||
*/
|
*/
|
||||||
public function undelete($uid)
|
public function undelete($uid)
|
||||||
{
|
{
|
||||||
if ($msguid = $this->uid2msguid($uid)) {
|
if ($msguid = $this->uid2msguid($uid, true)) {
|
||||||
if ($this->imap->set_flag($msguid, 'UNDELETED', $this->name)) {
|
if ($this->imap->set_flag($msguid, 'UNDELETED', $this->name)) {
|
||||||
return $msguid;
|
return $msguid;
|
||||||
}
|
}
|
||||||
|
@ -419,11 +419,11 @@ class kolab_storage_folder
|
||||||
/**
|
/**
|
||||||
* Resolve an object UID into an IMAP message UID
|
* Resolve an object UID into an IMAP message UID
|
||||||
*/
|
*/
|
||||||
private function uid2msguid($uid)
|
private function uid2msguid($uid, $deleted = false)
|
||||||
{
|
{
|
||||||
if (!isset($this->uid2msg[$uid])) {
|
if (!isset($this->uid2msg[$uid])) {
|
||||||
// use IMAP SEARCH to get the right message
|
// use IMAP SEARCH to get the right message
|
||||||
$index = $this->imap->search_once($this->name, 'HEADER SUBJECT ' . $uid);
|
$index = $this->imap->search_once($this->name, ($deleted ? '' : 'UNDELETED ') . 'HEADER SUBJECT ' . $uid);
|
||||||
$results = $index->get();
|
$results = $index->get();
|
||||||
$this->uid2msg[$uid] = $results[0];
|
$this->uid2msg[$uid] = $results[0];
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue