PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.1.0
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.1.0
11.1.1 11.1.0 11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 All 62 releases
← All changes | back/Controllers/MailboxActions/Edition.php +36 -28 10.0.1 → 11.1.0 View file →
@@ -8,9 +8,9 @@
8 8 use AcyMailing\Types\DelayType;
9 9
10 10 trait Edition
11 11 {
12 - public function mailboxAction()
12 + public function mailboxAction(): void
13 13 {
14 14 $mailboxClass = new MailboxClass();
15 15 acym_setVar('layout', 'mailbox_action');
16 16 $mailboxId = acym_getVar('int', 'mailboxId', 0);
@@ -62,26 +62,12 @@
62 62
63 63 acym_trigger('onAcymMailboxActionDefine', [&$actions]);
64 64
65 65 $actionOptions = ['' => acym_translation('ACYM_CHOOSE_ACTION')];
66 - $actionParameters = '';
67 -
68 66 foreach ($actions as $key => $oneAction) {
69 67 $actionOptions[$key] = $oneAction->name;
70 - $actionParameters .= '<div class="acym__mailbox__edition__action__one__parameters '.$key.' margin-top-1">'.$oneAction->option.'</div>';
71 68 }
72 69
73 - $initialAction = acym_select(
74 - $actionOptions,
75 - 'acym_action[__num__][action]',
76 - '',
77 - [
78 - 'class' => 'acym__select acym__mailbox__edition__action__one__choice',
79 - 'acym-data-infinite' => '',
80 - ]
81 - );
82 - $initialAction .= $actionParameters;
83 -
84 70 $data = [
85 71 'mailboxId' => $mailboxId,
86 72 'mailboxActions' => $mailboxAction,
87 73 'delayType' => new DelayType(),
@@ -86,28 +72,31 @@
86 72 'mailboxActions' => $mailboxAction,
87 73 'delayType' => new DelayType(),
88 74 'groups' => acym_getGroups(),
89 75 'lists' => $listsClass->getAllWithIdName(),
90 - 'initialAction' => $initialAction,
76 + 'actionDeclarations' => $actions,
77 + 'actionOptions' => $actionOptions,
91 78 ];
92 79
93 80 parent::display($data);
94 81 }
95 82
96 - public function applyMailboxAction()
83 + public function applyMailboxAction(): void
97 84 {
98 85 $this->storeMailboxAction();
99 86 $this->mailboxAction();
100 87 }
101 88
102 - public function saveMailboxAction()
89 + public function saveMailboxAction(): void
103 90 {
104 91 $this->storeMailboxAction();
105 92 $this->listing();
106 93 }
107 94
108 - public function storeMailboxAction()
95 + public function storeMailboxAction(): void
109 96 {
97 + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
98 +
110 99 $mailbox = acym_getVar('array', 'mailbox', []);
111 100 $mailboxClass = new MailboxClass();
112 101 $mailboxObject = new \stdClass();
113 102
@@ -144,10 +133,12 @@
144 133 acym_setVar('mailboxId', $mailboxId);
145 134 }
146 135 }
147 136
148 - public function testMailboxAction()
137 + public function testMailboxAction(): void
149 138 {
139 + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
140 +
150 141 $mailbox = acym_getVar('array', 'mailbox', []);
151 142
152 143 if (empty($mailbox)) {
153 144 acym_sendAjaxResponse(acym_translation('ACYM_NO_CONFIGURATION'), [], false);
@@ -154,21 +145,28 @@
154 145 }
155 146
156 147 $mailbox = (object)$mailbox;
157 148
149 + // If this is not a new mailbox or if it is not from the configuration menu, we need to get the password from the database
158 150 if (!empty($mailbox->id)) {
159 151 if ($mailbox->id !== 'configuration') {
160 - $mailboxClass = new MailboxClass();
161 - $mailboxFromDatabase = $mailboxClass->getOneById($mailbox->id);
162 -
152 + // We check if the password has not changed
163 153 if (empty(trim($mailbox->password, '*'))) {
164 - $mailbox->password = $mailboxFromDatabase->password;
154 + $mailboxClass = new MailboxClass();
155 + $mailboxFromDatabase = $mailboxClass->getOneById($mailbox->id);
156 + if (!empty($mailboxFromDatabase) && $this->isSameMailboxHost($mailbox->server ?? '', $mailboxFromDatabase->server)) {
157 + $mailbox->password = $mailboxFromDatabase->password;
158 + }
165 159 }
166 160 } elseif (empty(trim($mailbox->password, '*'))) {
167 - $mailbox->password = $this->config->get('bounce_password');
168 - $mailbox->bounce_token = str_replace('Bearer ', '', $this->config->get('bounce_token', ''));
169 - $mailbox->connection_method = $this->config->get('connection_method', 'imap');
170 - $mailbox->imap_connection_method = $this->config->get('imap_connection_method', 'classic');
161 + // If it comes from the configuration menu, we need to get the password from the config table (not the mailbox_action table)
162 + if ($this->isSameMailboxHost($mailbox->server ?? '', $this->config->get('bounce_server'))) {
163 + $mailbox->password = $this->config->get('bounce_password');
164 + $mailbox->bounce_access_token = str_replace('Bearer ', '', $this->config->get('bounce_access_token', ''));
165 + if (empty($mailbox->connection_method)) {
166 + $mailbox->connection_method = $this->config->get('connection_method', 'imap');
167 + }
168 + }
171 169 }
172 170 }
173 171
174 172 $mailboxHelper = new MailboxHelper();
@@ -182,6 +180,16 @@
182 180 acym_sendAjaxResponse(acym_translation('ACYM_CONNECTION_FAILED'), ['report' => $this->mailboxReport], false);
183 181 } else {
184 182 acym_sendAjaxResponse(acym_translation('ACYM_CONNECTION_SUCCESSFUL'));
185 183 }
184 + }
185 +
186 + private function isSameMailboxHost($submittedServer, $storedServer): bool
187 + {
188 + $storedServer = trim((string)$storedServer);
189 + if ($storedServer === '') {
190 + return false;
191 + }
192 +
193 + return strcasecmp(trim((string)$submittedServer), $storedServer) === 0;
186 194 }
187 195 }