From c8696e278cb8507ddcfd5febbad20ac6378d902d Mon Sep 17 00:00:00 2001 From: Thomas B Date: Thu, 8 Mar 2012 21:22:09 +0100 Subject: [PATCH] Implement format wrapper for distribution-list; add more utility functions --- plugins/libkolab/lib/kolab_format.php | 4 +- .../lib/kolab_format_distributionlist.php | 57 ++++++++----------- plugins/libkolab/lib/kolab_storage.php | 21 +++++++ 3 files changed, 48 insertions(+), 34 deletions(-) diff --git a/plugins/libkolab/lib/kolab_format.php b/plugins/libkolab/lib/kolab_format.php index bcad59e7..9fb0d8be 100644 --- a/plugins/libkolab/lib/kolab_format.php +++ b/plugins/libkolab/lib/kolab_format.php @@ -45,11 +45,11 @@ abstract class kolab_format /** * Generate random UID for Kolab objects * - * @return string MD5 hash with a unique value + * @return string UUID with a unique MD5 value */ public static function generate_uid() { - return md5(uniqid(mt_rand(), true)); + return 'urn:uuid:' . md5(uniqid(mt_rand(), true)); } /** diff --git a/plugins/libkolab/lib/kolab_format_distributionlist.php b/plugins/libkolab/lib/kolab_format_distributionlist.php index a1f5891b..d6297815 100644 --- a/plugins/libkolab/lib/kolab_format_distributionlist.php +++ b/plugins/libkolab/lib/kolab_format_distributionlist.php @@ -10,7 +10,7 @@ class kolab_format_distributionlist extends kolab_format function __construct() { - $obj = new DistList; + $this->obj = new DistList; } /** @@ -35,12 +35,28 @@ class kolab_format_distributionlist extends kolab_format public function set(&$object) { - // TODO: do the hard work of setting object values + // set some automatic values if missing + if (empty($object['uid'])) + $object['uid'] = self::generate_uid(); + + // do the hard work of setting object values + $this->obj->setUid($object['uid']); + $this->obj->setName($object['name']); + + $members = new vectormember; + foreach ($object['member'] as $member) { + $m = new Member; + $m->setName($member['name']); + $m->setEmail($member['mailto']); + $m->setUid($member['uid']); + $members->push($m); + } + $this->obj->setMembers($members); } public function is_valid() { - return $this->data || (is_object($this->obj) && true /*$this->obj->isValid()*/); + return $this->data || (is_object($this->obj) && $this->obj->isValid()); } /** @@ -87,40 +103,17 @@ class kolab_format_distributionlist extends kolab_format $members = $this->obj->members(); for ($i=0; $i < $members->size(); $i++) { - $adr = self::decode_member($members->get($i)); - if ($adr[0]['mailto']) + $member = $members->get($i); + if ($mailto = $member->email()) $object['member'][] = array( - 'mailto' => $adr[0]['mailto'], - 'name' => $adr[0]['name'], - 'uid' => '????', + 'mailto' => $mailto, + 'name' => $member->name(), + 'uid' => $member->uid(), ); } + $this->data = $object; return $this->data; } - /** - * Compose a valid Mailto URL according to RFC 822 - * - * @param string E-mail address - * @param string Person name - * @return string Formatted string - */ - public static function format_member($email, $name = '') - { - // let Roundcube internals do the job - return 'mailto:' . format_email_recipient($email, $name); - } - - /** - * Split a mailto: url into a structured member component - * - * @param string RFC 822 mailto: string - * @return array Hash array with member properties - */ - public static function decode_member($str) - { - $adr = rcube_mime::decode_address_list(preg_replace('/^mailto:/', '', $str)); - return $adr[0]; - } } diff --git a/plugins/libkolab/lib/kolab_storage.php b/plugins/libkolab/lib/kolab_storage.php index ec93213f..9d00d336 100644 --- a/plugins/libkolab/lib/kolab_storage.php +++ b/plugins/libkolab/lib/kolab_storage.php @@ -203,4 +203,25 @@ class kolab_storage return $folder; } + /** + * Creates a SELECT field with folders list + * + * @param string $type Folder type + * @param array $attrs SELECT field attributes (e.g. name) + * @param string $current The name of current folder (to skip it) + * + * @return html_select SELECT object + */ + public static function folder_selector($type, $attrs, $current = '') + { + // TODO: implement this + + + // Build SELECT field of parent folder + $select = new html_select($attrs); + $select->add('---', ''); + + + return $select; + } }