From 3e41e578885e0817623e3ac3a2e74c64415d6996 Mon Sep 17 00:00:00 2001 From: Boris Gulay Date: Mon, 16 May 2016 22:18:20 +0300 Subject: [PATCH] Now correct identity is selected when creating new message in remote account. --- ident_switch.js | 5 +++++ ident_switch.php | 18 +++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/ident_switch.js b/ident_switch.js index 949e0b9..553969f 100644 --- a/ident_switch.js +++ b/ident_switch.js @@ -13,3 +13,8 @@ function plugin_switchIdent_switch(val) { console.log("qwe1"); rcmail.http_post('plugin.ident_switch.switch', { '_ident-id': val }); } + +function plugin_switchIdent_fixIdent(iid) { + if (parseInt(iid) > 0) + $("#_from").val(iid); +} diff --git a/ident_switch.php b/ident_switch.php index f514c7b..b86e6f5 100644 --- a/ident_switch.php +++ b/ident_switch.php @@ -27,6 +27,7 @@ class ident_switch extends rcube_plugin $this->add_hook('identity_form', array($this, 'on_identity_form')); $this->add_hook('identity_update', array($this, 'on_identity_update')); $this->add_hook('identity_delete', array($this, 'on_identity_delete')); + $this->add_hook('template_object_composeheaders', array($this, 'on_template_object_composeheaders')); $this->register_action('plugin.ident_switch.switch', array($this, 'on_switch')); } @@ -223,6 +224,19 @@ class ident_switch extends rcube_plugin return $args; } + function on_template_object_composeheaders($args) + { + if ($args['id'] == '_from') + { + $rc = rcmail::get_instance(); + if (strcasecmp($_SESSION['username'], $rc->user->data['username']) !== 0) + { + if (isset($_SESSION['iid' . $this->my_postfix])) + $rc->output->add_script('plugin_switchIdent_fixIdent(' . $_SESSION['iid' . $this->my_postfix] . ');', 'docready'); + } + } + } + function on_switch() { $rc = rcmail::get_instance(); @@ -247,10 +261,11 @@ class ident_switch extends rcube_plugin } $_SESSION['username'] = $rc->user->data['username']; $_SESSION['password'] = $_SESSION['password' . $this->my_postfix]; + $_SESSION['iid' . $this->my_postfix] = -1; } else { - $sql = 'SELECT host, flags, port, username, password FROM ' . $rc->db->table_name($this->table) . ' WHERE id = ? AND user_id = ?'; + $sql = 'SELECT host, flags, port, username, password, iid FROM ' . $rc->db->table_name($this->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)) @@ -287,6 +302,7 @@ class ident_switch extends rcube_plugin $_SESSION['storage_port'] = $port; $_SESSION['username'] = $r['username']; $_SESSION['password'] = $r['password']; + $_SESSION['iid' . $this->my_postfix] = $r['iid']; $rc->session->remove('folders'); }