From ff3facb2614aa3e6641b125710b526f92ba421df Mon Sep 17 00:00:00 2001 From: Carson Fleming Date: Mon, 25 Nov 2024 00:31:59 -0800 Subject: working prototype, still need key management and maybe some json for smoother experience --- inbox_settings.php | 76 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 60 insertions(+), 16 deletions(-) (limited to 'inbox_settings.php') diff --git a/inbox_settings.php b/inbox_settings.php index a9797a1..25e3cd0 100644 --- a/inbox_settings.php +++ b/inbox_settings.php @@ -33,9 +33,46 @@ class inbox_settings extends rcube_plugin { return $params; } + private function save_settings() { + if (empty($_POST['save'])) + return; + + $encrypt_inbox = isset($_POST['encrypt_inbox']) ? '1' : '0'; + $this->run_query('update_encryption', ['%se' => $encrypt_inbox]); + + if (empty($_POST['addr']) || !is_array($_POST['addr'])) + return; + + foreach ($_POST['addr'] as $idx => $addr) { + if (!empty($_POST['fwd_addr'][$idx]) + && !rcube_utils::check_email($_POST['fwd_addr'][$idx])) + continue; + + $fwd_addr = $_POST['fwd_addr'][$idx]; + $fwd_addr = empty($fwd_addr) ? '' : $fwd_addr; + $do_forward = isset($_POST['do_fwd'][$idx]) ? '1' : '0'; + + $local_part = $addr; + $domain_part = ''; + if ($at_separator = strrpos($addr, '@')) { + $local_part = substr($addr, 0, $at_separator); + $domain_part = substr($addr, $at_separator + 1); + } + + $this->run_query('update_forwarder', [ + '%aa' => $addr, + '%al' => $local_part, + '%ad' => $domain_part, + '%sf' => $do_forward, + '%sa' => $fwd_addr + ]); + } + } + function render_settings_ui() { - $this->rcmail->output->set_pagetitle($this->gettext('inbox_settings')); $this->register_handler('plugin.body', array($this, 'render_settings_form')); + $this->rcmail->output->set_pagetitle($this->gettext('inbox_settings')); + $this->save_settings(); $this->rcmail->output->send('plugin'); } @@ -48,9 +85,9 @@ class inbox_settings extends rcube_plugin { $encryption_form = new html_table(['cols' => 2, 'class' => 'propform']); $encryption_form->add_row(['class' => 'form-group row']); $encryption_form->add('title col-sm-8', html::label([ - 'class' => 'col-form-label', - 'for' => 'rcmfd_encrypt_inbox' - ], rcube::Q($this->gettext('encrypt_inbox')))); + 'class' => 'col-form-label', + 'for' => 'rcmfd_encrypt_inbox' + ], rcube::Q($this->gettext('encrypt_inbox')))); $encryption_form->add('col-sm-2 offset-1', self::get_checkbox( 'rcmfd_encrypt_inbox', 'encrypt_inbox', $encrypt_inbox)); @@ -60,15 +97,15 @@ class inbox_settings extends rcube_plugin { $forwarding_form->add_row(['class' => 'form-group row']); $forwarding_form->add('title col-sm-4', html::label(['class' => 'col-form-label'], rcube::Q($row[0])) - . self::get_hiddenfield('addr[]', $row[0]) + . self::get_hiddenfield('addr[' . $idx . ']', $row[0]) ); $forwarding_form->add('col-sm-4', self::get_textfield( - 'fwd_addr[]', $row[1], ['placeholder' => 'anyone@gmail.com'])); + 'fwd_addr[' . $idx . ']', $row[1], ['placeholder' => 'anyone@gmail.com'])); $forwarding_form->add('col-sm-2 offset-1', self::get_checkbox( - 'do_forward_' . $idx, - 'do_forward[]', + 'do_fwd_' . $idx, + 'do_fwd[' . $idx . ']', $row[2], ['title' => $this->gettext('fwd_addr')])); } @@ -81,17 +118,17 @@ class inbox_settings extends rcube_plugin { . html::tag('fieldset', null, html::tag('legend', null, rcube::Q($this->gettext('forwarding'))) . $forwarding_form->show(null))); - $save_button = new html_button([ - 'class' => 'btn btn-primary submit', - 'onclick' => 'return rcmail.command(\'plugin.inbox_settings_save\', \'\', this, event)' - ]); - $form_buttons = html::div(['class' => 'formbuttons'], - $save_button->show($this->rcmail->gettext('save'))); + $save_button = (new html_inputfield([ + 'type' => 'submit', + 'name' => 'save', + 'class' => 'button mainaction submit' + ]))->show($this->rcmail->gettext('save')); + $form_buttons = html::div(['class' => 'formbuttons'], $save_button); $page_content = html::div(['class' => 'formcontainer'], $page_title . $this->rcmail->output->form_tag([ 'action' => $this->rcmail->url( - ['action' => $this->rcmail->action, 'a' => 'save']), + ['action' => 'plugin.inbox_settings']), 'method' => 'post' ], $form . $form_buttons)); return $page_content; @@ -122,6 +159,8 @@ class inbox_settings extends rcube_plugin { private function run_query($qid, $substitutions = []) { if (!($sql = $this->rcmail->config->get('inbox_settings_' . $qid . '_query'))) { + $this->rcmail->output->command( + 'display_message', $this->gettext('no_query'), 'error'); return []; } @@ -133,6 +172,8 @@ class inbox_settings extends rcube_plugin { } if ($db->is_error()) { + $this->rcmail->output->command( + 'display_message', $this->gettext('no_db'), 'error'); return []; } @@ -151,8 +192,11 @@ class inbox_settings extends rcube_plugin { } $result = $db->query($sql); - if ($db->is_error($result)) + if ($db->is_error($result)) { + $this->rcmail->output->command( + 'display_message', $this->gettext('sql_error'), 'error'); return []; + } $ndresult = []; while ($row = $db->fetch_array($result)) -- cgit v1.2.3