From f4d1b4a5b89ea5534df3935456df0c088a2cccea Mon Sep 17 00:00:00 2001 From: yuri Date: Fri, 30 Aug 2019 12:22:01 +0300 Subject: [PATCH] email account: smtp auth mechanism param --- application/Espo/Core/Mail/Sender.php | 7 ++++++- application/Espo/Resources/i18n/en_US/EmailAccount.json | 6 ++++++ application/Espo/Resources/i18n/en_US/InboundEmail.json | 6 ++++++ .../Espo/Resources/layouts/EmailAccount/detail.json | 2 +- .../Espo/Resources/layouts/InboundEmail/detail.json | 3 ++- .../Espo/Resources/metadata/entityDefs/EmailAccount.json | 7 ++++++- .../Espo/Resources/metadata/entityDefs/InboundEmail.json | 7 ++++++- application/Espo/Services/EmailAccount.php | 3 ++- application/Espo/Services/InboundEmail.php | 7 ++++++- client/src/views/email-account/record/detail.js | 7 ++++--- client/src/views/inbound-email/record/detail.js | 6 ++++-- 11 files changed, 49 insertions(+), 12 deletions(-) diff --git a/application/Espo/Core/Mail/Sender.php b/application/Espo/Core/Mail/Sender.php index 56f4e9446f..540b8c862d 100644 --- a/application/Espo/Core/Mail/Sender.php +++ b/application/Espo/Core/Mail/Sender.php @@ -107,7 +107,12 @@ class Sender if ($params['auth']) { if (!empty($params['smtpAuthMechanism'])) { - $options['connectionClass'] = $params['smtpAuthMechanism']; + $smtpAuthMechanism = preg_replace("([\.]{2,})", '', $params['smtpAuthMechanism']); + if (in_array($smtpAuthMechanism, ['login', 'crammd5', 'plain'])) { + $options['connectionClass'] = $smtpAuthMechanism; + } else { + $options['connectionClass'] = 'login'; + } } else { $options['connectionClass'] = 'login'; } diff --git a/application/Espo/Resources/i18n/en_US/EmailAccount.json b/application/Espo/Resources/i18n/en_US/EmailAccount.json index dbd68bd736..264179a9ca 100644 --- a/application/Espo/Resources/i18n/en_US/EmailAccount.json +++ b/application/Espo/Resources/i18n/en_US/EmailAccount.json @@ -20,6 +20,7 @@ "smtpPort": "SMTP Port", "smtpAuth": "SMTP Auth", "smtpSecurity": "SMTP Security", + "smtpAuthMechanism": "SMTP Auth Mechanism", "smtpUsername": "SMTP Username", "smtpPassword": "SMTP Password" }, @@ -31,6 +32,11 @@ "status": { "Active": "Active", "Inactive": "Inactive" + }, + "smtpAuthMechanism": { + "plain": "PLAIN", + "login": "LOGIN", + "crammd5": "CRAM-MD5" } }, "labels": { diff --git a/application/Espo/Resources/i18n/en_US/InboundEmail.json b/application/Espo/Resources/i18n/en_US/InboundEmail.json index a80ec3dfd4..1e14ac7126 100644 --- a/application/Espo/Resources/i18n/en_US/InboundEmail.json +++ b/application/Espo/Resources/i18n/en_US/InboundEmail.json @@ -32,6 +32,7 @@ "smtpPort": "SMTP Port", "smtpAuth": "SMTP Auth", "smtpSecurity": "SMTP Security", + "smtpAuthMechanism": "SMTP Auth Mechanism", "smtpUsername": "SMTP Username", "smtpPassword": "SMTP Password", "fromName": "From Name", @@ -68,6 +69,11 @@ "Direct-Assignment": "Direct-Assignment", "Round-Robin": "Round-Robin", "Least-Busy": "Least-Busy" + }, + "smtpAuthMechanism": { + "plain": "PLAIN", + "login": "LOGIN", + "crammd5": "CRAM-MD5" } }, "labels": { diff --git a/application/Espo/Resources/layouts/EmailAccount/detail.json b/application/Espo/Resources/layouts/EmailAccount/detail.json index 684e9c1bf6..faaef4e10d 100644 --- a/application/Espo/Resources/layouts/EmailAccount/detail.json +++ b/application/Espo/Resources/layouts/EmailAccount/detail.json @@ -45,7 +45,7 @@ [{"name": "useSmtp"}, false], [{"name": "smtpHost"}, {"name": "smtpPort"}], [{"name": "smtpAuth"}, {"name": "smtpSecurity"}], - [{"name": "smtpUsername"}, false], + [{"name": "smtpUsername"}, {"name": "smtpAuthMechanism"}], [{"name": "smtpPassword"}, false], [ {"name": "smtpTestSend", "customLabel": null, "view": "views/email-account/fields/test-send"}, false diff --git a/application/Espo/Resources/layouts/InboundEmail/detail.json b/application/Espo/Resources/layouts/InboundEmail/detail.json index 6680d482b2..9127a0a004 100644 --- a/application/Espo/Resources/layouts/InboundEmail/detail.json +++ b/application/Espo/Resources/layouts/InboundEmail/detail.json @@ -74,8 +74,9 @@ [{"name": "smtpIsShared"}, {"name": "smtpIsForMassEmail"}], [{"name": "smtpHost"}, {"name": "smtpPort"}], [{"name": "smtpAuth"}, {"name": "smtpSecurity"}], - [{"name": "smtpUsername"}, {"name": "fromName"}], + [{"name": "smtpUsername"}, {"name": "smtpAuthMechanism"}], [{"name": "smtpPassword"}, false], + [{"name": "fromName"}, false], [ {"name": "smtpTestSend", "customLabel": null, "view": "views/inbound-email/fields/test-send"}, false ] diff --git a/application/Espo/Resources/metadata/entityDefs/EmailAccount.json b/application/Espo/Resources/metadata/entityDefs/EmailAccount.json index 041e9e3379..b4973c64dd 100644 --- a/application/Espo/Resources/metadata/entityDefs/EmailAccount.json +++ b/application/Espo/Resources/metadata/entityDefs/EmailAccount.json @@ -96,7 +96,7 @@ }, "smtpAuth": { "type": "bool", - "default": false + "default": true }, "smtpSecurity": { "type": "enum", @@ -109,6 +109,11 @@ "smtpPassword": { "type": "password" }, + "smtpAuthMechanism": { + "type": "enum", + "options": ["login", "crammd5", "plain"], + "default": "login" + }, "createdBy": { "type": "link", "readOnly": true diff --git a/application/Espo/Resources/metadata/entityDefs/InboundEmail.json b/application/Espo/Resources/metadata/entityDefs/InboundEmail.json index 9e346c0047..67fc7fb8f2 100644 --- a/application/Espo/Resources/metadata/entityDefs/InboundEmail.json +++ b/application/Espo/Resources/metadata/entityDefs/InboundEmail.json @@ -104,7 +104,7 @@ }, "smtpAuth": { "type": "bool", - "default": false + "default": true }, "smtpSecurity": { "type": "enum", @@ -117,6 +117,11 @@ "smtpPassword": { "type": "password" }, + "smtpAuthMechanism": { + "type": "enum", + "options": ["login", "crammd5", "plain"], + "default": "login" + }, "createCase": { "type": "bool", "tooltip": true diff --git a/application/Espo/Services/EmailAccount.php b/application/Espo/Services/EmailAccount.php index 3ad09e49ef..f9f78928de 100644 --- a/application/Espo/Services/EmailAccount.php +++ b/application/Espo/Services/EmailAccount.php @@ -487,7 +487,7 @@ class EmailAccount extends Record public function getSmtpParamsFromAccount(\Espo\Entities\EmailAccount $emailAccount) { - $smtpParams = array(); + $smtpParams = []; $smtpParams['server'] = $emailAccount->get('smtpHost'); if ($smtpParams['server']) { $smtpParams['port'] = $emailAccount->get('smtpPort'); @@ -496,6 +496,7 @@ class EmailAccount extends Record if ($emailAccount->get('smtpAuth')) { $smtpParams['username'] = $emailAccount->get('smtpUsername'); $smtpParams['password'] = $emailAccount->get('smtpPassword'); + $smtpParams['smtpAuthMechanism'] = $emailAccount->get('smtpAuthMechanism'); } if (array_key_exists('password', $smtpParams)) { $smtpParams['password'] = $this->getCrypt()->decrypt($smtpParams['password']); diff --git a/application/Espo/Services/InboundEmail.php b/application/Espo/Services/InboundEmail.php index a0ee91b994..95b52fb2cf 100644 --- a/application/Espo/Services/InboundEmail.php +++ b/application/Espo/Services/InboundEmail.php @@ -922,7 +922,7 @@ class InboundEmail extends \Espo\Services\Record public function getSmtpParamsFromAccount(\Espo\Entities\InboundEmail $emailAccount) { - $smtpParams = array(); + $smtpParams = []; $smtpParams['server'] = $emailAccount->get('smtpHost'); if ($smtpParams['server']) { $smtpParams['port'] = $emailAccount->get('smtpPort'); @@ -930,6 +930,11 @@ class InboundEmail extends \Espo\Services\Record $smtpParams['security'] = $emailAccount->get('smtpSecurity'); $smtpParams['username'] = $emailAccount->get('smtpUsername'); $smtpParams['password'] = $emailAccount->get('smtpPassword'); + + if ($emailAccount->get('smtpAuth')) { + $smtpParams['smtpAuthMechanism'] = $emailAccount->get('smtpAuthMechanism'); + } + if ($emailAccount->get('fromName')) { $smtpParams['fromName'] = $emailAccount->get('fromName'); } diff --git a/client/src/views/email-account/record/detail.js b/client/src/views/email-account/record/detail.js index 717ff3651b..10b851a2b2 100644 --- a/client/src/views/email-account/record/detail.js +++ b/client/src/views/email-account/record/detail.js @@ -26,7 +26,7 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -Espo.define('views/email-account/record/detail', 'views/record/detail', function (Dep) { +define('views/email-account/record/detail', 'views/record/detail', function (Dep) { return Dep.extend({ @@ -132,6 +132,7 @@ Espo.define('views/email-account/record/detail', 'views/record/detail', function this.hideField('smtpAuth'); this.hideField('smtpUsername'); this.hideField('smtpPassword'); + this.hideField('smtpAuthMechanism'); this.hideField('smtpSecurity'); this.hideField('smtpTestSend'); @@ -145,15 +146,15 @@ Espo.define('views/email-account/record/detail', 'views/record/detail', function if (this.model.get('smtpAuth')) { this.showField('smtpUsername'); this.showField('smtpPassword'); + this.showField('smtpAuthMechanism'); this.setFieldRequired('smtpUsername'); } else { this.hideField('smtpUsername'); this.hideField('smtpPassword'); + this.hideField('smtpAuthMechanism'); this.setFieldNotRequired('smtpUsername'); } }, }); - }); - diff --git a/client/src/views/inbound-email/record/detail.js b/client/src/views/inbound-email/record/detail.js index 99f1211d03..43ac6acc28 100644 --- a/client/src/views/inbound-email/record/detail.js +++ b/client/src/views/inbound-email/record/detail.js @@ -26,7 +26,7 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -Espo.define('views/inbound-email/record/detail', 'views/record/detail', function (Dep) { +define('views/inbound-email/record/detail', 'views/record/detail', function (Dep) { return Dep.extend({ @@ -36,7 +36,6 @@ Espo.define('views/inbound-email/record/detail', 'views/record/detail', function this.initSslFieldListening(); }, - wasFetched: function () { if (!this.model.isNew()) { return !!((this.model.get('fetchData') || {}).lastUID); @@ -74,6 +73,7 @@ Espo.define('views/inbound-email/record/detail', 'views/record/detail', function this.hideField('smtpAuth'); this.hideField('smtpUsername'); this.hideField('smtpPassword'); + this.hideField('smtpAuthMechanism'); this.hideField('smtpSecurity'); this.hideField('smtpTestSend'); this.hideField('fromName'); @@ -102,10 +102,12 @@ Espo.define('views/inbound-email/record/detail', 'views/record/detail', function if (this.model.get('smtpAuth')) { this.showField('smtpUsername'); this.showField('smtpPassword'); + this.showField('smtpAuthMechanism'); this.setFieldRequired('smtpUsername'); } else { this.hideField('smtpUsername'); this.hideField('smtpPassword'); + this.hideField('smtpAuthMechanism'); this.setFieldNotRequired('smtpUsername'); } },