From 67fc6b8b664f746d6bc477e482771856d9e61948 Mon Sep 17 00:00:00 2001 From: Christian Landvogt Date: Fri, 13 Dec 2019 09:35:08 +0100 Subject: [PATCH 1/6] fix imap delimiter switching --- ident_switch.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ident_switch.php b/ident_switch.php index 8cad50e..2813b02 100644 --- a/ident_switch.php +++ b/ident_switch.php @@ -603,7 +603,7 @@ class ident_switch extends rcube_plugin if ($ssl) $host = "{$ssl}://{$host}"; - $delimiter = $r['delimiter'] ? $r['delimiter'] : '.'; // Default delimiter here + $delimiter = $r['imap_delimiter'] ? $r['imap_delimiter'] : '.'; // Default delimiter here $_SESSION['storage_host'] = $host; $_SESSION['storage_ssl'] = $ssl; From f30f72099b9cb32f52da05e51a9bf3c5dbea04bb Mon Sep 17 00:00:00 2001 From: Christian Landvogt Date: Fri, 13 Dec 2019 10:49:50 +0100 Subject: [PATCH 2/6] load and set special folders from db --- ident_switch.php | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/ident_switch.php b/ident_switch.php index 2813b02..0171987 100644 --- a/ident_switch.php +++ b/ident_switch.php @@ -33,6 +33,15 @@ class ident_switch extends rcube_plugin $this->add_hook('template_object_composeheaders', array($this, 'on_template_object_composeheaders')); $this->register_action('plugin.ident_switch.switch', array($this, 'on_switch')); + + $rc = rcmail::get_instance(); + $saveFromConfig = Array('drafts_mbox', 'sent_mbox', 'trash_mbox', 'junk_mbox'); + foreach ($saveFromConfig as $k) + { + $key = $k . '_default' . self::MY_POSTFIX; + if (!$_SESSION[$key]) + $_SESSION[$key] = $rc->config->get($k); + } } function on_startup($args) @@ -51,6 +60,15 @@ class ident_switch extends rcube_plugin } } + $setConfig = Array('drafts_mbox', 'sent_mbox', 'trash_mbox', 'junk_mbox'); + foreach ($setConfig as $k) + { + $defaultKey = $k . '_default' . self::MY_POSTFIX; + $otherKey = $k . self::MY_POSTFIX; + $val = $_SESSION[$otherKey] ? $_SESSION[$otherKey] : $_SESSION[$defaultKey]; + $rc->config->set($k, $val); + } + return $args; } @@ -531,6 +549,9 @@ class ident_switch extends rcube_plugin $my_postfix_len = strlen(self::MY_POSTFIX); $identId = rcube_utils::get_input_value('_ident-id', rcube_utils::INPUT_POST); + $rc->session->remove('folders'); + $rc->session->remove('unseen_count'); + if (-1 == $identId) { // Switch to main account self::write_log('Switching mailbox back to default.'); @@ -548,10 +569,18 @@ class ident_switch extends rcube_plugin $_SESSION['username'] = $rc->user->data['username']; $_SESSION['password'] = $_SESSION['password' . self::MY_POSTFIX]; $_SESSION['iid' . self::MY_POSTFIX] = -1; + + $delFromConfig = Array('drafts_mbox', 'sent_mbox', 'trash_mbox', 'junk_mbox'); + foreach ($delFromConfig as $k) + { + $otherKey = $k . self::MY_POSTFIX; + if ($_SESSION[$otherKey]) + $rc->session->remove($otherKey); + } } else { - $sql = 'SELECT imap_host, flags, imap_port, imap_delimiter, username, password, iid FROM ' . $rc->db->table_name(self::TABLE) . ' WHERE id = ? AND user_id = ?'; + $sql = 'SELECT imap_host, flags, imap_port, imap_delimiter, drafts_mbox, sent_mbox, junk_mbox, trash_mbox, username, password, iid FROM ' . $rc->db->table_name(self::TABLE) . ' WHERE id = ? AND user_id = ?'; $q = $rc->db->query($sql, $identId ,$rc->user->ID); $r = $rc->db->fetch_assoc($q); if (is_array($r)) @@ -613,7 +642,14 @@ class ident_switch extends rcube_plugin $_SESSION['password'] = $r['password']; $_SESSION['iid' . self::MY_POSTFIX] = $r['iid']; - $rc->session->remove('folders'); + $saveToSessiong = Array('drafts_mbox', 'sent_mbox', 'trash_mbox', 'junk_mbox'); + foreach ($saveToSessiong as $k) + { + if ($r[$k]) { + $otherKey = $k . self::MY_POSTFIX; + $_SESSION[$otherKey] = $r[$k]; + } + } } else { From f1d2e3193a3e1fed77d0bfda5c9e7a587c3d524e Mon Sep 17 00:00:00 2001 From: Christian Landvogt Date: Fri, 13 Dec 2019 12:16:16 +0100 Subject: [PATCH 3/6] save special folders from normal dialog --- ident_switch.php | 112 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 94 insertions(+), 18 deletions(-) diff --git a/ident_switch.php b/ident_switch.php index 0171987..043718c 100644 --- a/ident_switch.php +++ b/ident_switch.php @@ -31,16 +31,17 @@ class ident_switch extends rcube_plugin $this->add_hook('identity_create_after', array($this, 'on_identity_create_after')); $this->add_hook('identity_delete', array($this, 'on_identity_delete')); $this->add_hook('template_object_composeheaders', array($this, 'on_template_object_composeheaders')); + $this->add_hook('preferences_list', array($this, 'on_special_folders_form')); + $this->add_hook('preferences_save', array($this, 'on_special_folders_update')); $this->register_action('plugin.ident_switch.switch', array($this, 'on_switch')); $rc = rcmail::get_instance(); - $saveFromConfig = Array('drafts_mbox', 'sent_mbox', 'trash_mbox', 'junk_mbox'); - foreach ($saveFromConfig as $k) + foreach (rcube_storage::$folder_types as $type) { - $key = $k . '_default' . self::MY_POSTFIX; + $key = $type . '_mbox_default' . self::MY_POSTFIX; if (!$_SESSION[$key]) - $_SESSION[$key] = $rc->config->get($k); + $_SESSION[$key] = $rc->config->get($type . '_mbox'); } } @@ -60,13 +61,12 @@ class ident_switch extends rcube_plugin } } - $setConfig = Array('drafts_mbox', 'sent_mbox', 'trash_mbox', 'junk_mbox'); - foreach ($setConfig as $k) + foreach (rcube_storage::$folder_types as $type) { - $defaultKey = $k . '_default' . self::MY_POSTFIX; - $otherKey = $k . self::MY_POSTFIX; + $defaultKey = $type . '_mbox_default' . self::MY_POSTFIX; + $otherKey = $type . '_mbox' . self::MY_POSTFIX; $val = $_SESSION[$otherKey] ? $_SESSION[$otherKey] : $_SESSION[$defaultKey]; - $rc->config->set($k, $val); + $rc->config->set($type . '_mbox', $val); } return $args; @@ -414,6 +414,84 @@ class ident_switch extends rcube_plugin } } + function on_special_folders_form($args) + { + $rc = rcmail::get_instance(); + + if (($args['section'] == 'folders') && + (strcasecmp($rc->user->data['username'], $_SESSION['username']) !== 0)) + { + $no_override = array_flip((array)$rc->config->get('dont_override')); + $onchange = "if ($(this).val() == 'INBOX') $(this).val('')"; + $args['blocks']['main']['name'] .= ' (remote)'; + $select = $rc->folder_selector(array('noselection' => '---', + 'realnames' => true, + 'maxlength' => 30, + 'folder_filter' => 'mail', + 'folder_rights' => 'w')); + + foreach (rcube_storage::$folder_types as $type) + { + if (isset($no_override[$type . '_mbox'])) + continue; + + $defaultKey = $type . '_mbox_default' . self::MY_POSTFIX; + $otherKey = $type . '_mbox' . self::MY_POSTFIX; + $selected = $_SESSION[$otherKey] ? $_SESSION[$otherKey] : $_SESSION[$defaultKey]; + $attr = array('id' => '_' . $type . '_mbox', 'name' => '_' . $type . '_mbox', 'onchange' => $onchange); + $args['blocks']['main']['options'][$type . '_mbox']['content'] = $select->show($selected, $attr); + } + } + + return $args; + } + + function on_special_folders_update($args) + { + $rc = rcmail::get_instance(); + + if (($args['section'] == 'folders') && + (strcasecmp($rc->user->data['username'], $_SESSION['username']) !== 0)) + { + $sql = 'SELECT id FROM ' . $rc->db->table_name(self::TABLE) . ' WHERE iid = ? AND user_id = ?'; + $q = $rc->db->query($sql, $_SESSION['iid' . self::MY_POSTFIX], $rc->user->ID); + $r = $rc->db->fetch_assoc($q); + if ($r) + { + $sql = 'UPDATE ' . + $rc->db->table_name(self::TABLE) . + ' SET drafts_mbox = ?, sent_mbox = ?, junk_mbox = ?, trash_mbox = ?' . + ' WHERE id = ?'; + + $rc->db->query( + $sql, + $args['prefs']['drafts_mbox'], + $args['prefs']['sent_mbox'], + $args['prefs']['junk_mbox'], + $args['prefs']['trash_mbox'], + $r['id'] + ); + + //abuse $plugin['abort'] to prevent RC main from saving prefs + $args['abort'] = true; + $args['result'] = true; + + foreach (rcube_storage::$folder_types as $type) + { + if ($args['prefs'][$type . '_mbox']) { + $otherKey = $type . '_mbox' . self::MY_POSTFIX; + $_SESSION[$otherKey] = $args['prefs'][$type . '_mbox']; + } + } + return $args; + } + + $args['abort'] = true; + $args['result'] = false; + } + + return $args; + } private static function check_field_values() { @@ -570,10 +648,9 @@ class ident_switch extends rcube_plugin $_SESSION['password'] = $_SESSION['password' . self::MY_POSTFIX]; $_SESSION['iid' . self::MY_POSTFIX] = -1; - $delFromConfig = Array('drafts_mbox', 'sent_mbox', 'trash_mbox', 'junk_mbox'); - foreach ($delFromConfig as $k) + foreach (rcube_storage::$folder_types as $type) { - $otherKey = $k . self::MY_POSTFIX; + $otherKey = $type . '_mbox' . self::MY_POSTFIX; if ($_SESSION[$otherKey]) $rc->session->remove($otherKey); } @@ -609,7 +686,7 @@ class ident_switch extends rcube_plugin } } - $moreToSave = Array('password', 'imap_delimiter'); + $moreToSave = array('password', 'imap_delimiter'); foreach ($moreToSave as $k) { if (!$_SESSION[$k . self::MY_POSTFIX]) @@ -642,12 +719,11 @@ class ident_switch extends rcube_plugin $_SESSION['password'] = $r['password']; $_SESSION['iid' . self::MY_POSTFIX] = $r['iid']; - $saveToSessiong = Array('drafts_mbox', 'sent_mbox', 'trash_mbox', 'junk_mbox'); - foreach ($saveToSessiong as $k) + foreach (rcube_storage::$folder_types as $type) { - if ($r[$k]) { - $otherKey = $k . self::MY_POSTFIX; - $_SESSION[$otherKey] = $r[$k]; + if ($r[$type . '_mbox']) { + $otherKey = $type . '_mbox' . self::MY_POSTFIX; + $_SESSION[$otherKey] = $r[$type . '_mbox']; } } } From 98e0f16836fa3ab9df22a4704ba1fd493e9daefe Mon Sep 17 00:00:00 2001 From: Christian Landvogt Date: Fri, 13 Dec 2019 12:20:06 +0100 Subject: [PATCH 4/6] fix special folder not updated for main identity --- ident_switch.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ident_switch.php b/ident_switch.php index 043718c..aa7521a 100644 --- a/ident_switch.php +++ b/ident_switch.php @@ -488,8 +488,16 @@ class ident_switch extends rcube_plugin $args['abort'] = true; $args['result'] = false; + return $args; } + foreach (rcube_storage::$folder_types as $type) + { + if ($args['prefs'][$type . '_mbox']) { + $key = $type . '_mbox_default' . self::MY_POSTFIX; + $_SESSION[$key] = $args['prefs'][$type . '_mbox']; + } + } return $args; } From 0342dd497545ee07bf6038078f87004100023c58 Mon Sep 17 00:00:00 2001 From: Christian Landvogt Date: Fri, 13 Dec 2019 12:35:01 +0100 Subject: [PATCH 5/6] display identity label at folder selection --- ident_switch.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ident_switch.php b/ident_switch.php index aa7521a..a44f2ff 100644 --- a/ident_switch.php +++ b/ident_switch.php @@ -423,13 +423,17 @@ class ident_switch extends rcube_plugin { $no_override = array_flip((array)$rc->config->get('dont_override')); $onchange = "if ($(this).val() == 'INBOX') $(this).val('')"; - $args['blocks']['main']['name'] .= ' (remote)'; $select = $rc->folder_selector(array('noselection' => '---', 'realnames' => true, 'maxlength' => 30, 'folder_filter' => 'mail', 'folder_rights' => 'w')); + $sql = 'SELECT label FROM ' . $rc->db->table_name(self::TABLE) . ' WHERE iid = ? AND user_id = ?'; + $q = $rc->db->query($sql, $_SESSION['iid' . self::MY_POSTFIX], $rc->user->ID); + $r = $rc->db->fetch_assoc($q); + $args['blocks']['main']['name'] .= ' (' . ($r['label'] ? rcube::Q($rc->gettext('server')) . ': ' . $r['label'] : 'remote') . ')'; + foreach (rcube_storage::$folder_types as $type) { if (isset($no_override[$type . '_mbox'])) From fa0d0c168432153a37cabfdf57648cc0c977828f Mon Sep 17 00:00:00 2001 From: Christian Landvogt Date: Fri, 13 Dec 2019 12:37:42 +0100 Subject: [PATCH 6/6] adjust MySQL database - postgres and sqlite are missing! --- SQL/mysql.initial.sql | 8 ++++++++ SQL/mysql/2019121300.sql | 14 ++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 SQL/mysql/2019121300.sql diff --git a/SQL/mysql.initial.sql b/SQL/mysql.initial.sql index 7130075..4a20665 100644 --- a/SQL/mysql.initial.sql +++ b/SQL/mysql.initial.sql @@ -32,6 +32,14 @@ CREATE TABLE IF NOT EXISTS ident_switch smtp_port int CHECK(smtp_port > 0 AND smtp_port <= 65535), + drafts_mbox + varchar(64), + sent_mbox + varchar(64), + junk_mbox + varchar(64), + trash_mbox + varchar(64), UNIQUE KEY user_id_label (user_id, label), CONSTRAINT fk_user_id FOREIGN KEY (user_id) REFERENCES users(user_id) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT fk_identity_id FOREIGN KEY (iid) REFERENCES identities(identity_id) ON DELETE CASCADE ON UPDATE CASCADE, diff --git a/SQL/mysql/2019121300.sql b/SQL/mysql/2019121300.sql new file mode 100644 index 0000000..94a469d --- /dev/null +++ b/SQL/mysql/2019121300.sql @@ -0,0 +1,14 @@ +ALTER TABLE + ident_switch +ADD COLUMN + drafts_mbox + varchar(64), +ADD COLUMN + sent_mbox + varchar(64), +ADD COLUMN + junk_mbox + varchar(64), +ADD COLUMN + trash_mbox + varchar(64);