implement standard imap/smtp backend
authorLars Kneschke <l.kneschke@metaways.de>
Fri, 6 Mar 2015 08:08:01 +0000 (09:08 +0100)
committerPhilipp Schüle <p.schuele@metaways.de>
Sat, 7 Mar 2015 11:14:21 +0000 (12:14 +0100)
Change-Id: I442f02d42a53de1d544f5e51b4b63f104982566c
Reviewed-on: http://gerrit.tine20.com/customers/1716
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tine20/Tinebase/EmailUser.php
tine20/Tinebase/EmailUser/Imap/Standard.php [new file with mode: 0644]
tine20/Tinebase/EmailUser/Smtp/Postfix.php
tine20/Tinebase/EmailUser/Smtp/Standard.php [new file with mode: 0644]

index 206777d..469c557 100644 (file)
@@ -92,6 +92,40 @@ class Tinebase_EmailUser
     const CYRUS    = 'Cyrus';
     
     /**
+     * imap standard backend const
+     * 
+     * @staticvar string
+     */
+    const IMAP_STANDARD      = 'Standard';
+    
+    /**
+     * smtp standard backend const
+     * 
+     * @staticvar string
+     */
+    const SMTP_STANDARD      = 'Standard';
+    
+    /**
+     * supported backends
+     * 
+     * @var array
+     */
+    protected static $_supportedBackends = array(
+        self::CYRUS            => 'Tinebase_EmailUser_Imap_Cyrus',
+        self::DBMAIL           => 'Tinebase_EmailUser_Imap_Dbmail',
+        self::DOVECOT_IMAP     => 'Tinebase_EmailUser_Imap_Dovecot',
+        self::DOVECOT_COMBINED => 'Tinebase_EmailUser_Imap_DovecotCombined',
+        self::IMAP_STANDARD    => 'Tinebase_EmailUser_Imap_Standard',
+        self::LDAP_IMAP        => 'Tinebase_EmailUser_Imap_LdapDbmailSchema',
+        self::LDAP_SMTP        => 'Tinebase_EmailUser_Smtp_LdapDbmailSchema',
+        self::LDAP_SMTP_MAIL   => 'Tinebase_EmailUser_Smtp_LdapMailSchema',
+        self::LDAP_SMTP_QMAIL  => 'Tinebase_EmailUser_Smtp_LdapQmailSchema',
+        self::POSTFIX          => 'Tinebase_EmailUser_Smtp_Postfix',
+        self::POSTFIX_COMBINED => 'Tinebase_EmailUser_Smtp_PostfixCombined',
+        self::SMTP_STANDARD    => 'Tinebase_EmailUser_Smtp_Standard',
+    );
+    
+    /**
      * backend object instances
      * 
      * @var array
@@ -125,94 +159,39 @@ class Tinebase_EmailUser
     /**
      * the singleton pattern
      *
-     * @param string $_configType
+     * @param string $configType
      * @return Tinebase_User_Plugin_Abstract
      */
-    public static function getInstance($_configType = Tinebase_Config::IMAP) 
+    public static function getInstance($configType = Tinebase_Config::IMAP) 
     {
-        $backendType = self::getConfiguredBackend($_configType);
-        #if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ .' Email user backend: ' . $backendType);
+        $type = self::getConfiguredBackend($configType);
+        if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ .' Email user backend: ' . $type);
         
-        return self::factory($backendType);
+        if (!isset(self::$_backends[$type])) {
+            self::$_backends[$type] = self::factory($type);
+        }
+        
+        return self::$_backends[$type];
     }
     
     /**
-     * return an instance of the current backend
+     * return an instance of the defined backend
      *
-     * @param   string $_type name of the backend
+     * @param   string $type name of the backend
      * @return  Tinebase_User_Plugin_Abstract
      * @throws  Tinebase_Exception_InvalidArgument
      */
-    public static function factory($_type = NULL
+    public static function factory($type
     {
-        switch($_type) {
-            case self::LDAP_IMAP:
-                if (!isset(self::$_backends[$_type])) {
-                    self::$_backends[$_type] = new Tinebase_EmailUser_Imap_LdapDbmailSchema();
-                }
-                break;
-                
-            case self::DBMAIL:
-                if (!isset(self::$_backends[$_type])) {
-                    self::$_backends[$_type] = new Tinebase_EmailUser_Imap_Dbmail();
-                }
-                break;
-                
-            case self::CYRUS:
-                if (!isset(self::$_backends[$_type])) {
-                    self::$_backends[$_type] = new Tinebase_EmailUser_Imap_Cyrus();
-                }
-                break;
-                
-            case self::POSTFIX:
-                if (!isset(self::$_backends[$_type])) {
-                    self::$_backends[$_type] = new Tinebase_EmailUser_Smtp_Postfix();
-                }
-                break;
-                
-            case self::POSTFIX_COMBINED:
-                if (!isset(self::$_backends[$_type])) {
-                    self::$_backends[$_type] = new Tinebase_EmailUser_Smtp_PostfixCombined();
-                }
-                break;
-                
-            case self::LDAP_SMTP:
-                if (!isset(self::$_backends[$_type])) {
-                    self::$_backends[$_type] = new Tinebase_EmailUser_Smtp_LdapDbmailSchema();
-                }
-                break;
-                
-            case self::LDAP_SMTP_MAIL:
-                if (!isset(self::$_backends[$_type])) {
-                    self::$_backends[$_type] = new Tinebase_EmailUser_Smtp_LdapMailSchema();
-                }
-                break;
-                
-            case self::LDAP_SMTP_QMAIL:
-                if (!isset(self::$_backends[$_type])) {
-                    self::$_backends[$_type] = new Tinebase_EmailUser_Smtp_LdapQmailSchema();
-                }
-                break;
-                
-            case self::DOVECOT_IMAP:
-                if (!isset(self::$_backends[$_type])) {
-                    self::$_backends[$_type] = new Tinebase_EmailUser_Imap_Dovecot();
-                }
-                break;
-                
-            case self::DOVECOT_COMBINED:
-                if (!isset(self::$_backends[$_type])) {
-                    self::$_backends[$_type] = new Tinebase_EmailUser_Imap_DovecotCombined();
-                }
-                break;
-                
-            default:
-                throw new Tinebase_Exception_InvalidArgument("Backend type $_type not implemented.");
+        if (!isset(self::$_supportedBackends[$type])) {
+            throw new Tinebase_Exception_InvalidArgument("Backend type $type not implemented.");
         }
         
-        $result = self::$_backends[$_type];
+        $className = self::$_supportedBackends[$type];
         
-        return $result;
+        $backend = new $className();
+        
+        return $backend;
     }
     
     /**
@@ -233,10 +212,7 @@ class Tinebase_EmailUser
         
         $backend = ucfirst(strtolower($config['backend']));
         
-        if (!in_array($backend, array(
-            self::DBMAIL, self::LDAP_IMAP, self::CYRUS, self::DOVECOT_IMAP, self::DOVECOT_COMBINED,
-            self::POSTFIX, self::POSTFIX_COMBINED, self::LDAP_SMTP, self::LDAP_SMTP_MAIL, self::LDAP_SMTP_QMAIL
-        ))) {
+        if (!isset(self::$_supportedBackends[$backend])) {
             throw new Tinebase_Exception_NotFound("Config for type $configType / $backend not found.");
         }
         
@@ -282,7 +258,7 @@ class Tinebase_EmailUser
     {
         $config = self::getConfig($_configType);
         
-        $result = (isset($config['backend']) && ! empty($config['backend']) && $config['backend'] != 'standard' && isset($config['active']) && $config['active'] == true);
+        $result = (!empty($config['backend']) && isset($config['active']) && $config['active'] == true);
         
         return $result;
     }
diff --git a/tine20/Tinebase/EmailUser/Imap/Standard.php b/tine20/Tinebase/EmailUser/Imap/Standard.php
new file mode 100644 (file)
index 0000000..e26503d
--- /dev/null
@@ -0,0 +1,94 @@
+<?php
+/**
+ * Tine 2.0
+ * 
+ * @package     Tinebase
+ * @subpackage  EmailUser
+ * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
+ * @copyright   Copyright (c) 2015-2015 Metaways Infosystems GmbH (http://www.metaways.de)
+ * @author      Lars Kneschke
+ */
+
+/**
+ * plugin to handle sql email accounts
+ * 
+ * @package    Tinebase
+ * @subpackage EmailUser
+ */
+class Tinebase_EmailUser_Imap_Standard extends Tinebase_User_Plugin_Abstract
+{
+    /**
+     * email user config
+     * 
+     * @var array 
+     */
+    protected $_config = array();
+    
+    /**
+     * config key (Tinebase_Config::IMAP || Tinebase_Config::SMTP)
+     * 
+     * @var string
+     */
+    protected $_configKey = Tinebase_Config::IMAP;
+    
+    /**
+     * subconfig for user email backend (for example: dovecot)
+     * 
+     * @var string
+     */
+    protected $_subconfigKey =  NULL;
+    
+    /**
+     * the constructor
+     * 
+     * @param array $_options
+     */
+    public function __construct(array $_options = array())
+    {
+        if ($this->_configKey === NULL) {
+            throw new Tinebase_Exception_UnexpectedValue('$this->_configKey can not be emoty');
+        }
+        
+        // get email user backend config options (host, dbname, username, password, port)
+        $emailConfig = Tinebase_Config::getInstance()->get($this->_configKey, new Tinebase_Config_Struct())->toArray();
+        
+        // merge _config and email backend config
+        if ($this->_subconfigKey) {
+            $this->_config = array_merge($emailConfig[$this->_subconfigKey], $this->_config);
+        }
+        
+        if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($this->_config, TRUE));
+    }
+    
+    /**
+     * adds email properties for a new user
+     * 
+     * @param  Tinebase_Model_FullUser  $_addedUser
+     * @param  Tinebase_Model_FullUser  $_newUserProperties
+     */
+    protected function _addUser(Tinebase_Model_FullUser $_addedUser, Tinebase_Model_FullUser $_newUserProperties)
+    {
+        // do nothing
+    }
+    
+    /**
+     * updates email properties for an existing user
+     * 
+     * @param  Tinebase_Model_FullUser  $_updatedUser
+     * @param  Tinebase_Model_FullUser  $_newUserProperties
+     */
+    protected function _updateUser(Tinebase_Model_FullUser $_updatedUser, Tinebase_Model_FullUser $_newUserProperties)
+    {
+        // do nothing
+    }
+    
+    /**
+     * check if user exists already in plugin user table
+     * 
+     * @param Tinebase_Model_FullUser $_user
+     */
+    protected function _userExists(Tinebase_Model_FullUser $_user)
+    {
+        return false;
+    }
+}
index 05fdc47..be19a36 100644 (file)
@@ -109,7 +109,7 @@ class Tinebase_EmailUser_Smtp_Postfix extends Tinebase_EmailUser_Sql
         'alloweddomains'    => array(),
         'adapter'           => Tinebase_Core::PDO_MYSQL
     );
-
+    
     /**
      * user properties mapping
      *
@@ -344,7 +344,7 @@ class Tinebase_EmailUser_Smtp_Postfix extends Tinebase_EmailUser_Sql
     {
         return ((isset($_smtpSettings[$this->_propertyMapping['emailForwards']]) || array_key_exists($this->_propertyMapping['emailForwards'], $_smtpSettings)) && is_array($_smtpSettings[$this->_propertyMapping['emailForwards']]));
     }
-
+    
     /**
      * add forward destinations
      * 
diff --git a/tine20/Tinebase/EmailUser/Smtp/Standard.php b/tine20/Tinebase/EmailUser/Smtp/Standard.php
new file mode 100644 (file)
index 0000000..d680041
--- /dev/null
@@ -0,0 +1,94 @@
+<?php
+/**
+ * Tine 2.0
+ * 
+ * @package     Tinebase
+ * @subpackage  EmailUser
+ * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
+ * @copyright   Copyright (c) 2015-2015 Metaways Infosystems GmbH (http://www.metaways.de)
+ * @author      Lars Kneschke
+ */
+
+/**
+ * plugin to handle sql email accounts
+ * 
+ * @package    Tinebase
+ * @subpackage EmailUser
+ */
+class Tinebase_EmailUser_Smtp_Standard extends Tinebase_User_Plugin_Abstract
+{
+    /**
+     * email user config
+     * 
+     * @var array 
+     */
+    protected $_config = array();
+    
+    /**
+     * config key (Tinebase_Config::IMAP || Tinebase_Config::SMTP)
+     * 
+     * @var string
+     */
+    protected $_configKey = Tinebase_Config::SMTP;
+    
+    /**
+     * subconfig for user email backend (for example: dovecot)
+     * 
+     * @var string
+     */
+    protected $_subconfigKey =  NULL;
+    
+    /**
+     * the constructor
+     * 
+     * @param array $_options
+     */
+    public function __construct(array $_options = array())
+    {
+        if ($this->_configKey === NULL) {
+            throw new Tinebase_Exception_UnexpectedValue('$this->_configKey can not be emoty');
+        }
+        
+        // get email user backend config options (host, dbname, username, password, port)
+        $emailConfig = Tinebase_Config::getInstance()->get($this->_configKey, new Tinebase_Config_Struct())->toArray();
+        
+        // merge _config and email backend config
+        if ($this->_subconfigKey) {
+            $this->_config = array_merge($emailConfig[$this->_subconfigKey], $this->_config);
+        }
+        
+        if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($this->_config, TRUE));
+    }
+    
+    /**
+     * adds email properties for a new user
+     * 
+     * @param  Tinebase_Model_FullUser  $_addedUser
+     * @param  Tinebase_Model_FullUser  $_newUserProperties
+     */
+    protected function _addUser(Tinebase_Model_FullUser $_addedUser, Tinebase_Model_FullUser $_newUserProperties)
+    {
+        // do nothing
+    }
+    
+    /**
+     * updates email properties for an existing user
+     * 
+     * @param  Tinebase_Model_FullUser  $_updatedUser
+     * @param  Tinebase_Model_FullUser  $_newUserProperties
+     */
+    protected function _updateUser(Tinebase_Model_FullUser $_updatedUser, Tinebase_Model_FullUser $_newUserProperties)
+    {
+        // do nothing
+    }
+    
+    /**
+     * check if user exists already in plugin user table
+     * 
+     * @param Tinebase_Model_FullUser $_user
+     */
+    protected function _userExists(Tinebase_Model_FullUser $_user)
+    {
+        return false;
+    }
+}