-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrupal8-smtp-config-timeout.patch
97 lines (94 loc) · 3.52 KB
/
drupal8-smtp-config-timeout.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
diff --git a/config/install/smtp.settings.yml b/config/install/smtp.settings.yml
index 7b9865e..bf8d3a0 100644
--- a/config/install/smtp.settings.yml
+++ b/config/install/smtp.settings.yml
@@ -3,6 +3,7 @@ smtp_host: ''
smtp_hostbackup: ''
smtp_port: '25'
smtp_protocol: 'standard'
+smtp_timeout: 30
smtp_username: ''
smtp_password: ''
smtp_from: ''
diff --git a/config/schema/smtp.schema.yml b/config/schema/smtp.schema.yml
index cda9cd0..1128d11 100644
--- a/config/schema/smtp.schema.yml
+++ b/config/schema/smtp.schema.yml
@@ -17,6 +17,9 @@ smtp.settings:
smtp_protocol:
type: string
label: 'Use encrypted protocol'
+ smtp_timeout:
+ type: integer
+ label: 'Amount of seconds for the SMTP command to timeout'
smtp_username:
type: string
label: 'Username'
diff --git a/smtp.install b/smtp.install
index ae9cb2a..e3cc079 100644
--- a/smtp.install
+++ b/smtp.install
@@ -25,6 +25,15 @@ function smtp_uninstall() {
$smtp_config->delete();
}
+/**
+ * Add SMTP timeout configuration and change default to 30.
+ */
+function smtp_update_8001() {
+ \Drupal::configFactory()->getEditable('smtp.settings')
+ ->set('smtp_timeout', 30)
+ ->save(TRUE);
+}
+
/**
* Implements hook_install().
*/
diff --git a/src/Form/SMTPConfigForm.php b/src/Form/SMTPConfigForm.php
index cf58d2c..47335b2 100644
--- a/src/Form/SMTPConfigForm.php
+++ b/src/Form/SMTPConfigForm.php
@@ -133,7 +133,13 @@ class SMTPConfigForm extends ConfigFormBase {
'#description' => $encryption_description,
'#disabled' => $this->isOverridden('smtp_protocol'),
];
-
+ $form['server']['smtp_timeout'] = [
+ '#type' => 'textfield',
+ '#title' => $this->t('Timeout'),
+ '#default_value' => $config->get('smtp_timeout'),
+ '#description' => $this->t('Amount of seconds for the SMTP commands to timeout.'),
+ '#disabled' => $this->isOverridden('smtp_timeout'),
+ ];
$form['auth'] = [
'#type' => 'details',
'#title' => $this->t('SMTP Authentication'),
@@ -300,6 +306,7 @@ class SMTPConfigForm extends ConfigFormBase {
'smtp_hostbackup',
'smtp_port',
'smtp_protocol',
+ 'smtp_timeout',
'smtp_username',
'smtp_from',
'smtp_fromname',
diff --git a/src/Plugin/Mail/SMTPMailSystem.php b/src/Plugin/Mail/SMTPMailSystem.php
index 93f764c..d7f8b37 100644
--- a/src/Plugin/Mail/SMTPMailSystem.php
+++ b/src/Plugin/Mail/SMTPMailSystem.php
@@ -141,6 +141,7 @@ class SMTPMailSystem implements MailInterface, ContainerFactoryPluginInterface {
// Create a new PHPMailer object - autoloaded from registry.
$mailer = new PHPMailer(TRUE);
+ $mailer->Timeout = $this->smtpConfig->get('smtp_timeout');
// Turn on debugging, if requested.
if ($this->smtpConfig->get('smtp_debugging') && \Drupal::currentUser()->hasPermission('administer smtp module')) {
diff --git a/tests/src/Unit/SMTPConfigFormTest.php b/tests/src/Unit/SMTPConfigFormTest.php
index 93fb785..d3ab0ac 100644
--- a/tests/src/Unit/SMTPConfigFormTest.php
+++ b/tests/src/Unit/SMTPConfigFormTest.php
@@ -56,6 +56,7 @@ class SMTPConfigFormTest extends UnitTestCase {
$this->mockConfig->get('smtp_hostbackup')->willReturn('');
$this->mockConfig->get('smtp_port')->willReturn('');
$this->mockConfig->get('smtp_protocol')->willReturn('');
+ $this->mockConfig->get('smtp_timeout')->willReturn('');
$this->mockConfig->get('smtp_username')->willReturn('');
$this->mockConfig->get('smtp_password')->willReturn('');
$this->mockConfig->get('smtp_from')->willReturn('');