From 6f76f7289de8ab21fc451edf6512a1a9dca4a080 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Wed, 26 Mar 2014 15:57:12 +0200 Subject: [PATCH] refactor smtp preferences --- application/Espo/Entities/Preferences.php | 16 ++++++++++++++-- application/Espo/Services/Email.php | 18 +++++------------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/application/Espo/Entities/Preferences.php b/application/Espo/Entities/Preferences.php index 566ab8ee3d..cd79b5165f 100644 --- a/application/Espo/Entities/Preferences.php +++ b/application/Espo/Entities/Preferences.php @@ -25,9 +25,21 @@ namespace Espo\Entities; class Preferences extends \Espo\Core\ORM\Entity { - public function getSmtpSettings() + public function getSmtpParams() { - // TODO + $smtpParams = array(); + $smtpParams['server'] = $this->get('smtpServer'); + if ($smtpParams['server']) { + $smtpParams['port'] = $this->get('smtpPort'); + $smtpParams['server'] = $this->get('smtpServer'); + $smtpParams['auth'] = $this->get('smtpAuth'); + $smtpParams['security'] = $this->get('smtpSecurity'); + $smtpParams['username'] = $this->get('smtpUsername'); + $smtpParams['password'] = $this->get('smtpPassword'); + return $smtpParams; + } else { + return false; + } } } diff --git a/application/Espo/Services/Email.php b/application/Espo/Services/Email.php index 4a68f7de7c..8cb127a5b1 100644 --- a/application/Espo/Services/Email.php +++ b/application/Espo/Services/Email.php @@ -43,7 +43,7 @@ class Email extends Record protected function getPreferences() { return $this->injections['preferences']; - } + } public function createEntity($data) { @@ -52,18 +52,10 @@ class Email extends Record if ($entity && $entity->get('status') == 'Sending') { $emailSender = $this->getMailSender(); - if (strtolower($this->getUser()->get('emailAddress')) == strtolower($entity->get('from'))) { - $smtpParams = array(); - $smtpParams['server'] = $this->getPreferences()->get('smtpServer'); - if (!empty($smtpParams['server'])) { - $smtpParams['fromName'] = $this->getUser()->get('name'); - $smtpParams['port'] = $this->getPreferences()->get('smtpPort'); - $smtpParams['server'] = $this->getPreferences()->get('smtpServer'); - $smtpParams['auth'] = $this->getPreferences()->get('smtpAuth'); - $smtpParams['security'] = $this->getPreferences()->get('smtpSecurity'); - $smtpParams['username'] = $this->getPreferences()->get('smtpUsername'); - $smtpParams['password'] = $this->getPreferences()->get('smtpPassword'); - + if (strtolower($this->getUser()->get('emailAddress')) == strtolower($entity->get('from'))) { + $smtpParams = $this->getPreferences()->getSmtpParams(); + if ($smtpParams) { + $smtpParams['fromName'] = $this->getUser()->get('name'); $emailSender->useSmtp($smtpParams); } } else {