| @@ -1,187 +1,0 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -namespace AcyMailing\Controllers\MailboxActions; | |
| 4 | - | |
| 5 | -use AcyMailing\Classes\ListClass; | |
| 6 | -use AcyMailing\Classes\MailboxClass; | |
| 7 | -use AcyMailing\Helpers\MailboxHelper; | |
| 8 | -use AcyMailing\Types\DelayType; | |
| 9 | - | |
| 10 | -trait Edition | |
| 11 | -{ | |
| 12 | - public function mailboxAction(): void | |
| 13 | - { | |
| 14 | - $mailboxClass = new MailboxClass(); | |
| 15 | - acym_setVar('layout', 'mailbox_action'); | |
| 16 | - $mailboxId = acym_getVar('int', 'mailboxId', 0); | |
| 17 | - $listsClass = new ListClass(); | |
| 18 | - | |
| 19 | - if (!empty($mailboxId)) { | |
| 20 | - $mailboxAction = $mailboxClass->getOneById($mailboxId); | |
| 21 | - $this->breadcrumb[acym_translation($mailboxAction->name)] = acym_completeLink('bounces&task=mailboxAction&mailboxId='.$mailboxId); | |
| 22 | - } else { | |
| 23 | - $this->breadcrumb[acym_translation('ACYM_NEW')] = acym_completeLink('bounces&task=mailboxAction'); | |
| 24 | - $mailboxAction = new \stdClass(); | |
| 25 | - $mailboxAction->name = ''; | |
| 26 | - $mailboxAction->active = 0; | |
| 27 | - $mailboxAction->frequency = 900; | |
| 28 | - $mailboxAction->description = ''; | |
| 29 | - | |
| 30 | - $mailboxAction->server = ''; | |
| 31 | - $mailboxAction->username = ''; | |
| 32 | - $mailboxAction->password = ''; | |
| 33 | - $mailboxAction->connection_method = 'imap'; | |
| 34 | - $mailboxAction->secure_method = 'ssl'; | |
| 35 | - $mailboxAction->port = ''; | |
| 36 | - $mailboxAction->self_signed = 1; | |
| 37 | - | |
| 38 | - $mailboxAction->delete_wrong_emails = 0; | |
| 39 | - $mailboxAction->conditions = [ | |
| 40 | - 'sender' => '', | |
| 41 | - 'specific' => '', | |
| 42 | - 'groups' => '', | |
| 43 | - 'lists' => '', | |
| 44 | - 'subject' => '', | |
| 45 | - 'subject_text' => '', | |
| 46 | - 'subject_regex' => '', | |
| 47 | - 'subject_remove' => 1, | |
| 48 | - ]; | |
| 49 | - | |
| 50 | - $mailboxAction->actions = []; | |
| 51 | - $mailboxAction->senderfrom = 0; | |
| 52 | - $mailboxAction->senderto = 0; | |
| 53 | - } | |
| 54 | - | |
| 55 | - if (empty($mailboxAction->conditions['groups'])) { | |
| 56 | - $mailboxAction->conditions['groups'] = []; | |
| 57 | - } | |
| 58 | - | |
| 59 | - if (empty($mailboxAction->conditions['lists'])) { | |
| 60 | - $mailboxAction->conditions['lists'] = []; | |
| 61 | - } | |
| 62 | - | |
| 63 | - acym_trigger('onAcymMailboxActionDefine', [&$actions]); | |
| 64 | - | |
| 65 | - $actionOptions = ['' => acym_translation('ACYM_CHOOSE_ACTION')]; | |
| 66 | - $actionParameters = ''; | |
| 67 | - | |
| 68 | - foreach ($actions as $key => $oneAction) { | |
| 69 | - $actionOptions[$key] = $oneAction->name; | |
| 70 | - $actionParameters .= '<div class="acym__mailbox__edition__action__one__parameters '.$key.' margin-top-1">'.$oneAction->option.'</div>'; | |
| 71 | - } | |
| 72 | - | |
| 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 | - $data = [ | |
| 85 | - 'mailboxId' => $mailboxId, | |
| 86 | - 'mailboxActions' => $mailboxAction, | |
| 87 | - 'delayType' => new DelayType(), | |
| 88 | - 'groups' => acym_getGroups(), | |
| 89 | - 'lists' => $listsClass->getAllWithIdName(), | |
| 90 | - 'initialAction' => $initialAction, | |
| 91 | - ]; | |
| 92 | - | |
| 93 | - parent::display($data); | |
| 94 | - } | |
| 95 | - | |
| 96 | - public function applyMailboxAction(): void | |
| 97 | - { | |
| 98 | - $this->storeMailboxAction(); | |
| 99 | - $this->mailboxAction(); | |
| 100 | - } | |
| 101 | - | |
| 102 | - public function saveMailboxAction(): void | |
| 103 | - { | |
| 104 | - $this->storeMailboxAction(); | |
| 105 | - $this->listing(); | |
| 106 | - } | |
| 107 | - | |
| 108 | - public function storeMailboxAction(): void | |
| 109 | - { | |
| 110 | - $mailbox = acym_getVar('array', 'mailbox', []); | |
| 111 | - $mailboxClass = new MailboxClass(); | |
| 112 | - $mailboxObject = new \stdClass(); | |
| 113 | - | |
| 114 | - foreach ($mailbox as $column => $value) { | |
| 115 | - acym_secureDBColumn($column); | |
| 116 | - if (is_array($value) || is_object($value)) { | |
| 117 | - $mailboxObject->$column = json_encode($value); | |
| 118 | - } else { | |
| 119 | - $mailboxObject->$column = $value; | |
| 120 | - } | |
| 121 | - } | |
| 122 | - | |
| 123 | - $actions = acym_getVar('array', 'acym_action', []); | |
| 124 | - $mailboxObject->actions = []; | |
| 125 | - foreach ($actions as $oneAction) { | |
| 126 | - if (empty($oneAction['action'])) { | |
| 127 | - continue; | |
| 128 | - } | |
| 129 | - | |
| 130 | - $mailboxObject->actions[] = [$oneAction['action'] => $oneAction[$oneAction['action']]]; | |
| 131 | - } | |
| 132 | - $mailboxObject->actions = json_encode($mailboxObject->actions); | |
| 133 | - | |
| 134 | - if (!empty($mailboxObject->password) && trim($mailboxObject->password, '*') === '') { | |
| 135 | - unset($mailboxObject->password); | |
| 136 | - } | |
| 137 | - | |
| 138 | - $mailboxId = $mailboxClass->save($mailboxObject); | |
| 139 | - | |
| 140 | - if (empty($mailboxId)) { | |
| 141 | - acym_enqueueMessage(acym_translation('ACYM_ERROR_SAVING'), 'error'); | |
| 142 | - } else { | |
| 143 | - acym_enqueueMessage(acym_translation('ACYM_SUCCESSFULLY_SAVED')); | |
| 144 | - acym_setVar('mailboxId', $mailboxId); | |
| 145 | - } | |
| 146 | - } | |
| 147 | - | |
| 148 | - public function testMailboxAction(): void | |
| 149 | - { | |
| 150 | - $mailbox = acym_getVar('array', 'mailbox', []); | |
| 151 | - | |
| 152 | - if (empty($mailbox)) { | |
| 153 | - acym_sendAjaxResponse(acym_translation('ACYM_NO_CONFIGURATION'), [], false); | |
| 154 | - } | |
| 155 | - | |
| 156 | - $mailbox = (object)$mailbox; | |
| 157 | - | |
| 158 | - if (!empty($mailbox->id)) { | |
| 159 | - if ($mailbox->id !== 'configuration') { | |
| 160 | - if (empty(trim($mailbox->password, '*'))) { | |
| 161 | - $mailboxClass = new MailboxClass(); | |
| 162 | - $mailboxFromDatabase = $mailboxClass->getOneById($mailbox->id); | |
| 163 | - $mailbox->password = $mailboxFromDatabase->password; | |
| 164 | - } | |
| 165 | - } elseif (empty(trim($mailbox->password, '*'))) { | |
| 166 | - $mailbox->password = $this->config->get('bounce_password'); | |
| 167 | - $mailbox->bounce_access_token = str_replace('Bearer ', '', $this->config->get('bounce_access_token', '')); | |
| 168 | - if (empty($mailbox->connection_method)) { | |
| 169 | - $mailbox->connection_method = $this->config->get('connection_method', 'imap'); | |
| 170 | - } | |
| 171 | - } | |
| 172 | - } | |
| 173 | - | |
| 174 | - $mailboxHelper = new MailboxHelper(); | |
| 175 | - try { | |
| 176 | - $isConnectionValid = $mailboxHelper->isConnectionValid($mailbox); | |
| 177 | - } catch (\Exception $e) { | |
| 178 | - $this->mailboxReport[] = $e->getMessage(); | |
| 179 | - } | |
| 180 | - | |
| 181 | - if (empty($isConnectionValid)) { | |
| 182 | - acym_sendAjaxResponse(acym_translation('ACYM_CONNECTION_FAILED'), ['report' => $this->mailboxReport], false); | |
| 183 | - } else { | |
| 184 | - acym_sendAjaxResponse(acym_translation('ACYM_CONNECTION_SUCCESSFUL')); | |
| 185 | - } | |
| 186 | - } | |
| 187 | -} | |