2 commits - lib/kolab_client_task.php lib/kolab_form.php lib/kolab_recipient_policy.php

Aleksander Machniak machniak at kolabsys.com
Mon Apr 2 14:39:29 CEST 2012


 lib/kolab_client_task.php      |    2 +
 lib/kolab_form.php             |    2 -
 lib/kolab_recipient_policy.php |   56 +++++++++++++++++++++++++++++++++--------
 3 files changed, 49 insertions(+), 11 deletions(-)

New commits:
commit 3ce534c4d6666c12a8bd62e806e9dcac6e529d29
Author: Aleksander Machniak <machniak at kolabsys.com>
Date:   Mon Apr 2 14:35:59 2012 +0200

    Make sure we always return valid email addresses

diff --git a/lib/kolab_recipient_policy.php b/lib/kolab_recipient_policy.php
index c947da2..492df0b 100644
--- a/lib/kolab_recipient_policy.php
+++ b/lib/kolab_recipient_policy.php
@@ -28,10 +28,10 @@ class kolab_recipient_policy {
     static function format() {
         $_args = func_get_args();
 
-        $args = Array();
+        $args = array();
 
         for ($i = 0; $i < func_num_args(); $i++) {
-            #$args[$i] = preg_replace('/\./', '\.', $_args[$i]);
+            //$args[$i] = preg_replace('/\./', '\.', $_args[$i]);
             $args[$i] = $_args[$i];
         }
 
@@ -60,7 +60,7 @@ class kolab_recipient_policy {
 
     static function normalize_userdata($userdata)
     {
-        $keymap = Array(
+        $keymap = array(
                 'sn' => 'surname',
             );
 
@@ -90,8 +90,13 @@ class kolab_recipient_policy {
     {
         // Expect only a cn at domain.tld, really
         $groupdata = self::normalize_groupdata($groupdata);
+        $email     = '';
 
-        return $groupdata['cn'] . '@' . $_SESSION['user']->get_domain();
+        if (!empty($groupdata['cn'])) {
+            $email = $groupdata['cn'] . '@' . $_SESSION['user']->get_domain();
+        }
+
+        return self::parse_email($email);
     }
 
     static function primary_mail($userdata)
@@ -156,15 +161,14 @@ class kolab_recipient_policy {
             }
         }
 
-        return $primary_mail;
-
+        return self::parse_email($primary_mail);
     }
 
     static function secondary_mail($userdata)
     {
-        $secondary_mail_addresses = Array();
+        $secondary_mail_addresses = array();
 
-        $functions = Array(
+        $functions = array(
                 '\'%\((\w+)\)s\'\.capitalize\(\)' => 'strtoupper(substr("%(${1})s", 0, 1)) . strtolower(substr("%(${1})s", 1))',
                 '\'%\((\w+)\)s\'\.lower\(\)'      => 'strtolower("%(${1})s")',
                 '\'%\((\w+)\)s\'\.upper\(\)'      => 'strtoupper("%(${1})s")',
@@ -229,13 +233,45 @@ class kolab_recipient_policy {
 
                 eval("\$result = sprintf('" . $format . "', '" . implode("', '", array_values($result)) . "');");
 
-                $secondary_mail_addresses[] = $result;
-
+                if ($result = self::parse_email($result)) {
+                    $secondary_mail_addresses[] = $result;
+                }
             }
 
         }
 
         return $secondary_mail_addresses;
+    }
+
+    /**
+     * Make sure email address is valid, if not return empty string
+     */
+    static private function parse_email($email)
+    {
+        $email = strtolower($email);
 
+        $email_parts = explode('@', $email);
+        $email_parts = array_filter($email_parts);
+
+        // do some simple checks here
+        if (count($email_parts) < 2) {
+            return '';
+        }
+
+        // trim dots, it's most likely case
+        $email_parts[0] = trim($email_parts[0], '.');
+
+        // from PEAR::Validate
+        $regexp = '&^(?:
+            ("\s*(?:[^"\f\n\r\t\v\b\s]+\s*)+")|                             #1 quoted name
+            ([-\w!\#\$%\&\'*+~/^`|{}=]+(?:\.[-\w!\#\$%\&\'*+~/^`|{}=]+)*))  #2 OR dot-atom (RFC5322)
+            $&xi';
+
+        if (!preg_match($regexp, $email_parts[0])) {
+            return '';
+        }
+
+        return $email_parts[0] . '@' . $email_parts[1];
     }
+
 }


commit 094425a4c06b0196e0fe6b852d1788b57f1c7f2c
Author: Aleksander Machniak <machniak at kolabsys.com>
Date:   Mon Apr 2 13:44:39 2012 +0200

    Use optional flag to mark required fields in UI

diff --git a/lib/kolab_client_task.php b/lib/kolab_client_task.php
index c6e3b79..1e3acaa 100644
--- a/lib/kolab_client_task.php
+++ b/lib/kolab_client_task.php
@@ -675,6 +675,8 @@ class kolab_client_task
             }
         }
 
+        $result['required'] = empty($field['optional']);
+
         return $result;
     }
 
diff --git a/lib/kolab_form.php b/lib/kolab_form.php
index b387b65..de39bc3 100644
--- a/lib/kolab_form.php
+++ b/lib/kolab_form.php
@@ -227,7 +227,7 @@ class kolab_form
 
         $attrib = array('cells' => $cells);
 
-        if ($element['required']) {
+        if (!empty($element['required']) && empty($element['readonly']) && empty($element['disabled'])) {
             $attrib['class'] = 'required';
         }
 





More information about the commits mailing list