2 commits - config/main.inc.php.dist lib/ext lib/kolab_sync_backend_common.php lib/kolab_sync_backend_device.php lib/kolab_sync_message.php

Aleksander Machniak machniak at kolabsys.com
Mon Feb 3 12:50:04 CET 2014


 config/main.inc.php.dist                              |    4 +
 lib/ext/Syncroton/Backend/ABackend.php                |   12 +++++
 lib/ext/Syncroton/Backend/IBackend.php                |   11 ++++
 lib/ext/Syncroton/Command/Settings.php                |   18 ++++++--
 lib/ext/Syncroton/Wbxml/Dtd/ActiveSync/CodePage18.php |    2 
 lib/kolab_sync_backend_common.php                     |   12 +++++
 lib/kolab_sync_backend_device.php                     |   40 ++++++++++++++++++
 lib/kolab_sync_message.php                            |   16 +++++++
 8 files changed, 109 insertions(+), 6 deletions(-)

New commits:
commit e9593658ac53b7c6fc3364493c3f25d55358d5ad
Author: Aleksander Machniak <alec at alec.pl>
Date:   Mon Feb 3 12:49:22 2014 +0100

    Added option (activesync_fix_from) to enables adding sender name into the From: header
    of send email when a device uses email address only (e.g. iOS devices)
    $config['activesync_fix_from'] = false

diff --git a/config/main.inc.php.dist b/config/main.inc.php.dist
index 2ebe75d..c792377 100644
--- a/config/main.inc.php.dist
+++ b/config/main.inc.php.dist
@@ -79,3 +79,7 @@ $config['activesync_quiet_time'] = 180;
 //    16 - all subscribed folders in shared namespace
 //    32 - all folders in shared namespace
 $config['activesync_init_subscriptions'] = 0;
+
+// Enables adding sender name in the From: header of send email
+// when a device uses email address only (e.g. iOS devices)
+$config['activesync_fix_from'] = false;
diff --git a/lib/kolab_sync_message.php b/lib/kolab_sync_message.php
index 79ac8d9..77892ee 100644
--- a/lib/kolab_sync_message.php
+++ b/lib/kolab_sync_message.php
@@ -169,6 +169,22 @@ class kolab_sync_message
         if (empty($headers['From'])) {
             $headers['From'] = $this->get_identity();
         }
+        // make sure there's sender name in From:
+        else if ($rcube->config->get('activesync_fix_from')
+            && preg_match('/^<?((\S+|("[^"]+"))@\S+)>?$/', trim($headers['From']), $m)
+        ) {
+            $identities = kolab_sync::get_instance()->user->list_identities();
+            $email      = $m[1];
+
+            foreach ((array) $identities as $ident) {
+                if ($ident['email'] == $email) {
+                    if ($ident['name']) {
+                        $headers['From'] = format_email_recipient($email, $ident['name']);
+                    }
+                    break;
+                }
+            }
+        }
 
         if (empty($headers['Message-ID'])) {
             $headers['Message-ID'] = $rcube->gen_message_id();


commit 81e6f3dd922d0af6de4310b7966ef0db1bd8038f
Author: Aleksander Machniak <alec at alec.pl>
Date:   Mon Feb 3 12:42:45 2014 +0100

    Add support for returning UserInformation (display name and aliases) in Settings command response

diff --git a/lib/ext/Syncroton/Backend/ABackend.php b/lib/ext/Syncroton/Backend/ABackend.php
index 00869e4..f472301 100644
--- a/lib/ext/Syncroton/Backend/ABackend.php
+++ b/lib/ext/Syncroton/Backend/ABackend.php
@@ -166,6 +166,18 @@ abstract class Syncroton_Backend_ABackend implements Syncroton_Backend_IBackend
     }
 
     /**
+     * Returns list of user accounts
+     *
+     * @param Syncroton_Model_Device $device The device
+     *
+     * @return array List of Syncroton_Model_Account objects
+     */
+    public function userAccounts($device)
+    {
+        return array();
+    }
+
+    /**
      * convert from camelCase to camel_case
      * @param  string  $string
      * @return string
diff --git a/lib/ext/Syncroton/Backend/IBackend.php b/lib/ext/Syncroton/Backend/IBackend.php
index 00e83af..faaab9d 100644
--- a/lib/ext/Syncroton/Backend/IBackend.php
+++ b/lib/ext/Syncroton/Backend/IBackend.php
@@ -47,5 +47,14 @@ interface Syncroton_Backend_IBackend
      * @param  Syncroton_Model_IDevice $_device
      * @return Syncroton_Model_IDevice
      */
-    public function update($model);    
+    public function update($model);
+
+    /**
+     * Returns list of user accounts
+     *
+     * @param Syncroton_Model_Device $device The device
+     *
+     * @return array List of Syncroton_Model_Account objects
+     */
+    public function userAccounts($device);
 }
diff --git a/lib/ext/Syncroton/Command/Settings.php b/lib/ext/Syncroton/Command/Settings.php
index 11a36a3..6590569 100644
--- a/lib/ext/Syncroton/Command/Settings.php
+++ b/lib/ext/Syncroton/Command/Settings.php
@@ -82,18 +82,28 @@ class Syncroton_Command_Settings extends Syncroton_Command_Wbxml
             $set->appendChild($this->_outputDom->createElementNS('uri:Settings', 'Status', self::STATUS_SUCCESS));
         }
         
-        if($this->_userInformationRequested === true) {
-            $smtpAddresses = array();
-            
+        if ($this->_userInformationRequested === true) {
             $userInformation = $settings->appendChild($this->_outputDom->createElementNS('uri:Settings', 'UserInformation'));
             $userInformation->appendChild($this->_outputDom->createElementNS('uri:Settings', 'Status', self::STATUS_SUCCESS));
+
             $get = $userInformation->appendChild($this->_outputDom->createElementNS('uri:Settings', 'Get'));
-            if(!empty($smtpAddresses)) {
+/*
+            $smtpAddresses = array();
+            if (!empty($smtpAddresses)) {
                 $emailAddresses = $get->appendChild($this->_outputDom->createElementNS('uri:Settings', 'EmailAddresses'));
                 foreach($smtpAddresses as $smtpAddress) {
                     $emailAddresses->appendChild($this->_outputDom->createElementNS('uri:Settings', 'SMTPAddress', $smtpAddress));
                 }
             }
+*/
+            $userAccounts = $this->_deviceBackend->userAccounts($this->_device);
+            if (!empty($userAccounts)) {
+                $accounts = $get->appendChild($this->_outputDom->createElementNS('uri:Settings', 'Accounts'));
+                foreach ((array) $userAccounts as $account) {
+                    $element = $accounts->appendChild($this->_outputDom->createElementNS('uri:Settings', 'Account'));
+                    $account->appendXML($element, $this->_device);
+                }
+            }
         }
 
         return $this->_outputDom;
diff --git a/lib/ext/Syncroton/Wbxml/Dtd/ActiveSync/CodePage18.php b/lib/ext/Syncroton/Wbxml/Dtd/ActiveSync/CodePage18.php
index 01358bf..2b1d6d4 100644
--- a/lib/ext/Syncroton/Wbxml/Dtd/ActiveSync/CodePage18.php
+++ b/lib/ext/Syncroton/Wbxml/Dtd/ActiveSync/CodePage18.php
@@ -49,7 +49,7 @@ class Syncroton_Wbxml_Dtd_ActiveSync_CodePage18 extends Syncroton_Wbxml_Dtd_Acti
         'PhoneNumber'               => 0x1c,
         'UserInformation'           => 0x1d,
         'EmailAddresses'            => 0x1e,
-        'SmtpAddress'               => 0x1f,
+        'SMTPAddress'               => 0x1f,
         'UserAgent'                 => 0x20,
         'EnableOutboundSMS'         => 0x21,
         'MobileOperator'            => 0x22,
diff --git a/lib/kolab_sync_backend_common.php b/lib/kolab_sync_backend_common.php
index 1c4f988..49bb62f 100644
--- a/lib/kolab_sync_backend_common.php
+++ b/lib/kolab_sync_backend_common.php
@@ -180,6 +180,18 @@ class kolab_sync_backend_common implements Syncroton_Backend_IBackend
     }
 
     /**
+     * Returns list of user accounts
+     *
+     * @param Syncroton_Model_Device $device The current device
+     *
+     * @return array List of Syncroton_Model_Account objects
+     */
+    public function userAccounts($device)
+    {
+        // this method is overwritten by kolab_sync_backend class
+    }
+
+    /**
      * Convert array into model object
      */
     protected function get_object($data)
diff --git a/lib/kolab_sync_backend_device.php b/lib/kolab_sync_backend_device.php
index 9f0b909..bc9770c 100644
--- a/lib/kolab_sync_backend_device.php
+++ b/lib/kolab_sync_backend_device.php
@@ -122,4 +122,44 @@ class kolab_sync_backend_device extends kolab_sync_backend_common implements Syn
 
         return $device;
     }
+
+    /**
+     * Returns list of user accounts
+     *
+     * @param Syncroton_Model_Device $device The device
+     *
+     * @return array List of Syncroton_Model_Account objects
+     */
+    public function userAccounts($device)
+    {
+        $engine      = kolab_sync::get_instance();
+        $identities  = $engine->user->list_identities();
+        $email       = $engine->get_user_email();
+        $addresses   = array();
+
+        // read email addresses and display name (default ident comes first)
+        foreach ((array)$identities as $ident) {
+            if ($ident['name'] && !isset($displayname)) {
+                $displayname = $ident['name'];
+            }
+
+            $addresses[] = $ident['email'];
+        }
+
+        if (empty($displayname) && empty($email) && empty($addresses)) {
+            return array();
+        }
+
+        $account = new Syncroton_Model_Account;
+
+        if ($email) {
+            $addresses = array_diff($addresses, array($email));
+        }
+
+        $account->userDisplayName = $displayname;
+        $account->primaryAddress  = $email;
+        $account->addresses       = array_unique($addresses);
+
+        return array($account);
+    }
 }




More information about the commits mailing list