public function createEmailAccount($user, $config, $username, $password) { if (\GO::modules()->isInstalled('email')) { \GO::debug('IMAPAUTH: Creating IMAP account for user'); $account['user_id'] = $user->id; $account['type'] = 'imap'; //$config['proto']; $account['host'] = $config['host']; $account['smtp_host'] = $config['smtp_host']; $account['smtp_port'] = $config['smtp_port']; $account['smtp_encryption'] = $config['smtp_encryption']; if (!empty($config['smtp_use_login_credentials'])) { $account['smtp_username'] = $username; $account['smtp_password'] = $password; } elseif (isset($config['smtp_username'])) { $account['smtp_username'] = $config['smtp_username']; $account['smtp_password'] = $config['smtp_password']; } $account['port'] = $config['port']; $account['use_ssl'] = empty($config['ssl']) ? 0 : 1; $account['mbroot'] = $config['mbroot']; $account['username'] = $username; $account['store_password'] = !isset($config['store_password']) || !empty($config['store_password']) ? 1 : 0; $account['store_smtp_password'] = !empty($account['store_password']) && !empty($config['smtp_use_login_credentials']) ? 1 : 0; $account['password'] = $password; //set session pass. $model = new \GO\Email\Model\Account(); $model->setAttributes($account); $model->save(); if (!$model->save()) { throw new \Exception("Could not save e-mail account: " . implode("\n", $model->getValidationErrors())); } $model->addAlias($user->email, $user->name); } else { \GO::debug('IMAPAUTH: E-mail module not installed. Skipping e-mail account creation.'); } }