diff options
| -rw-r--r-- | config.inc.php.dist | 29 | ||||
| -rw-r--r-- | inbox_settings.php | 101 | ||||
| -rw-r--r-- | localization/en_US.inc | 5 |
3 files changed, 102 insertions, 33 deletions
diff --git a/config.inc.php.dist b/config.inc.php.dist index a7c045d..f8e559f 100644 --- a/config.inc.php.dist +++ b/config.inc.php.dist @@ -35,7 +35,7 @@ $config['inbox_settings_encryption_enabled_query'] = 'SELECT encrypt FROM users // %d - the domain part of the username // (in case the username is an email address) // %se - whether the inbox should be encrypted (boolean) -$config['inbox_settings_update_encryption_query'] = 'UPDATE users SET encrypt = ? WHERE username = %u'; +$config['inbox_settings_update_encryption_query'] = 'UPDATE users SET encrypt = %se WHERE username = %u'; // The SQL query used to select a user's forwarding addresses. // Supported replacement variables: @@ -61,7 +61,32 @@ $config['inbox_settings_forwarding_addresses_query'] = 'SELECT addr, fwd_addr, a // %ad - the domain part of the forwarding address // %sf - whether forwarding is set for this address (boolean) // %sa - the new forwarding address (string) -$config['inbox_settings_update_forwarder_query'] = 'UPDATE forwarders SET fwd_addr = %sf, active = %sa WHERE addr = %fa'; +$config['inbox_settings_update_forwarder_query'] = 'UPDATE forwarders SET fwd_addr = %sf, active = %sa WHERE addr = %aa'; + +// The SQL query used to select a user's storage addresses. +// Supported replacement variables: +// %h - user's IMAP hostname +// %u - the username (from the session info) +// %l - the local part of the username +// (in case the username is an email address) +// %d - the domain part of the username +// (in case the username is an email address) +$config['inbox_settings_stored_addresses_query'] = 'SELECT username, store FROM users WHERE username = %u'; + +// The SQL query used to update a user's forwarding setting for an address. +// Supported replacement variables: +// %h - user's IMAP hostname +// %u - the username (from the session info) +// %l - the local part of the username +// (in case the username is an email address) +// %d - the domain part of the username +// (in case the username is an email address) +// %aa - the full email address in question +// (returned as `addr` from the above query) +// %al - the local part of the email address +// %ad - the domain part of the email address +// %ss - whether storage is enabled this address (boolean) +$config['inbox_settings_update_stored_address_query'] = 'UPDATE users SET store = %ss WHERE username = %aa'; // The SQL query used to select a user's PGP keys. // Supported replacement variables: diff --git a/inbox_settings.php b/inbox_settings.php index 9a800a2..2cb0c7a 100644 --- a/inbox_settings.php +++ b/inbox_settings.php @@ -52,33 +52,53 @@ class inbox_settings extends rcube_plugin { if (!is_array($this->run_query('update_encryption', ['%se' => $encrypt_inbox]))) return; - if (empty($_POST['addr']) || !is_array($_POST['addr'])) - return; - $success = true; - 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); + if (!empty($_POST['fwd_iaddr']) && is_array($_POST['fwd_iaddr'])) { + foreach ($_POST['fwd_iaddr'] as $idx => $addr) { + if (!empty($_POST['fwd_oaddr'][$idx]) + && !rcube_utils::check_email($_POST['fwd_oaddr'][$idx])) + continue; + + $fwd_addr = $_POST['fwd_oaddr'][$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); + } + + $success &= is_array($this->run_query('update_forwarder', [ + '%aa' => $addr, + '%al' => $local_part, + '%ad' => $domain_part, + '%sf' => $do_forward, + '%sa' => $fwd_addr + ])); } + } - $success &= is_array($this->run_query('update_forwarder', [ - '%aa' => $addr, - '%al' => $local_part, - '%ad' => $domain_part, - '%sf' => $do_forward, - '%sa' => $fwd_addr - ])); + if (!empty($_POST['store_addr']) && is_array($_POST['store_addr'])) { + foreach ($_POST['store_addr'] as $idx => $addr) { + $do_store = isset($_POST['do_store'][$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); + } + + $success &= is_array($this->run_query('update_stored_address', [ + '%aa' => $addr, + '%al' => $local_part, + '%ad' => $domain_part, + '%ss' => $do_store + ])); + } } if ($success) @@ -117,13 +137,13 @@ class inbox_settings extends rcube_plugin { foreach ($forwarders as $idx => $row) { $forwarding_form->add('title col-sm-4', html::label( - ['class' => 'col-form-label', 'for' => 'fwd_addr_' . $idx], + ['class' => 'col-form-label', 'for' => 'fwd_oaddr_' . $idx], rcube::Q($row[0])) - . self::get_hiddenfield('addr[' . $idx . ']', $row[0])); + . self::get_hiddenfield('fwd_iaddr[' . $idx . ']', $row[0])); $forwarding_form->add('col-sm-4', self::get_textfield( - 'fwd_addr_' . $idx, - 'fwd_addr[' . $idx . ']', + 'fwd_oaddr_' . $idx, + 'fwd_oaddr[' . $idx . ']', $row[1], ['placeholder' => '[email protected]'])); $forwarding_form->add('col-sm-2 offset-1', @@ -134,14 +154,35 @@ class inbox_settings extends rcube_plugin { ['title' => $this->gettext('fwd_addr')])); } + $storage_addrs = $this->run_query('stored_addresses'); + if (!is_array($storage_addrs)) + $stored_addrs = []; + + $storage_form = new html_table(['cols' => 2, 'class' => 'propform']); + foreach ($stored_addrs as $idx => $row) { + $storage_form->add('title col-sm-8', + html::label( + ['class' => 'col-form-label', 'for' => 'do_store_' . $idx], + rcube::Q($row[0])) + . self::get_hiddenfield('store_addr[' . $idx . ']', $row[0])); + $storage_form->add('col-sm-2 offset-1', + self::get_checkbox( + 'do_store_' . $idx, + 'do_store[' . $idx . ']', + $row[1], + ['title' => $this->gettext('store_addr')])); + } + $form = html::div(['class' => 'formcontent'], html::tag('fieldset', null, html::tag('legend', null, rcube::Q($this->gettext('encryption'))) - . $encryption_form->show(null) - ) + . $encryption_form->show(null)) . html::tag('fieldset', null, html::tag('legend', null, rcube::Q($this->gettext('forwarding'))) - . $forwarding_form->show(null))); + . $forwarding_form->show(null)) + . html::tag('fieldset', null, + html::tag('legend', null, rcube::Q($this->gettext('storage'))) + . $storage_form->show(null))); $save_button = (new html_button([ 'type' => 'submit', 'name' => 'save', diff --git a/localization/en_US.inc b/localization/en_US.inc index 7b7fb05..059d5c2 100644 --- a/localization/en_US.inc +++ b/localization/en_US.inc @@ -5,8 +5,11 @@ $labels['encryption'] = 'Encryption'; $labels['encrypt_inbox'] = 'Encrypt incoming mail to my inbox'; $labels['forwarding'] = 'Forwarding'; $labels['fwd_addr'] = 'Forward mail to this address'; -$labels['inbox_keys'] = 'Encryption Keys'; +$labels['storage'] = 'Storage'; +$labels['store_addr'] = 'Store mail send to this address'; $labels['settings_saved'] = 'Inbox settings saved'; + +$labels['inbox_keys'] = 'Encryption Keys'; $labels['no_query'] = 'One or more database queries are not yet configured'; $labels['no_db'] = 'Failed to connect to the database'; $labels['sql_error'] = 'Encountered an error while performing the operation; please check your SQL syntax and database DSN'; |
