diff options
author | Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> | 2012-03-30 18:21:55 +0200 |
---|---|---|
committer | Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> | 2012-03-30 18:21:55 +0200 |
commit | 7381230117b0861d635820dc9095f47e28cca390 (patch) | |
tree | 5078062df3da9b3aa1e5577362d03667dfdc7d0e | |
parent | 812ccf7f14b09006dcf6fdf4f6618f2f65c68714 (diff) | |
download | webadmin-7381230117b0861d635820dc9095f47e28cca390.tar.gz |
Generate a proper primary mail attribute value for groups
-rw-r--r-- | lib/api/kolab_api_service_form_value.php | 32 | ||||
-rw-r--r-- | lib/kolab_recipient_policy.php | 28 |
2 files changed, 58 insertions, 2 deletions
diff --git a/lib/api/kolab_api_service_form_value.php b/lib/api/kolab_api_service_form_value.php index b006b84..6e39a9b 100644 --- a/lib/api/kolab_api_service_form_value.php +++ b/lib/api/kolab_api_service_form_value.php @@ -60,6 +60,7 @@ class kolab_api_service_form_value extends kolab_api_service public function generate($getdata, $postdata) { $attribs = $this->object_type_attributes($postdata['object_type'], $postdata['type_id']); + $attributes = (array) $postdata['attributes']; $result = array(); @@ -68,10 +69,16 @@ class kolab_api_service_form_value extends kolab_api_service continue; } - $method_name = 'generate_' . strtolower($attr_name); + $method_name = 'generate_' . strtolower($attr_name) . '_' . strtolower($postdata['object_type']); if (!method_exists($this, $method_name)) { - continue; + console("Method $method_name doesn't exist"); + + $method_name = 'generate_' . strtolower($attr_name); + + if (!method_exists($this, $method_name)) { + continue; + } } $result[$attr_name] = $this->{$method_name}($postdata, $attribs); @@ -269,6 +276,11 @@ class kolab_api_service_form_value extends kolab_api_service return $this->generate_primary_mail($postdata, $attribs); } + private function generate_mail_group($postdata, $attribs = array()) + { + return $this->generate_primary_mail_group($postdata, $attribs); + } + private function generate_mailalternateaddress($postdata, $attribs = array()) { return $this->generate_secondary_mail($postdata, $attribs); @@ -310,6 +322,22 @@ class kolab_api_service_form_value extends kolab_api_service } } + private function generate_primary_mail_group($postdata, $attribs = array()) + { + if (isset($attribs['auto_form_fields']) && isset($attribs['auto_form_fields']['mail'])) { + // Use Data Please + foreach ($attribs['auto_form_fields']['mail']['data'] as $key) { + if (!isset($postdata[$key])) { + throw new Exception("Key not set: " . $key, 12356); + } + } + + $primary_mail = kolab_recipient_policy::primary_mail_group($postdata); + + return $primary_mail; + } + } + private function generate_secondary_mail($postdata, $attribs = array()) { $secondary_mail_address = Array(); diff --git a/lib/kolab_recipient_policy.php b/lib/kolab_recipient_policy.php index 94dc008..c947da2 100644 --- a/lib/kolab_recipient_policy.php +++ b/lib/kolab_recipient_policy.php @@ -38,6 +38,26 @@ class kolab_recipient_policy { return $args; } + static function normalize_groupdata($groupdata) + { + //console("IN", $groupdata); + foreach ($groupdata as $key => $value) { + if (isset($groupdata['preferredlanguage'])) { + setlocale(LC_ALL, $groupdata['preferredlanguage']); + } + + if (!is_array($groupdata[$key])) { + $orig_value = $groupdata[$key]; + + $groupdata[$key] = iconv('UTF-8', 'ASCII//TRANSLIT', $groupdata[$key]); + $groupdata[$key] = preg_replace('/[^a-z0-9-_]/i', '', $groupdata[$key]); + } + } + + //console("OUT", $groupdata); + return $groupdata; + } + static function normalize_userdata($userdata) { $keymap = Array( @@ -66,6 +86,14 @@ class kolab_recipient_policy { return $userdata; } + static function primary_mail_group($groupdata) + { + // Expect only a cn@domain.tld, really + $groupdata = self::normalize_groupdata($groupdata); + + return $groupdata['cn'] . '@' . $_SESSION['user']->get_domain(); + } + static function primary_mail($userdata) { $userdata = self::normalize_userdata($userdata); |