Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bcea012af0 | ||
|
|
a437a107ba | ||
|
|
8b2798e412 | ||
|
|
c28305509f | ||
|
|
8a8bca1ae5 | ||
|
|
28d7841af5 | ||
|
|
707abf2a81 | ||
|
|
c90efaa00b | ||
|
|
e4aeef2e07 | ||
|
|
e19b33a842 | ||
|
|
d540de77ff | ||
|
|
913065548b | ||
|
|
683b02027b | ||
|
|
7111e9e759 |
10
README.md
10
README.md
@@ -9,3 +9,13 @@ This plugin allows users to switch between different accounts (including remote)
|
|||||||
* In settigs interface create new identity.
|
* In settigs interface create new identity.
|
||||||
* For all identities except default you will see new section of settings - IMAP. Enter data required to connect to remote server. Don't forget to check Enabled check box.
|
* For all identities except default you will see new section of settings - IMAP. Enter data required to connect to remote server. Don't forget to check Enabled check box.
|
||||||
* After you have created at least one identity with active IMAP settings you will see combobox in the top right corner instead of plain text field with account name. It will allows you to switch to another account.
|
* After you have created at least one identity with active IMAP settings you will see combobox in the top right corner instead of plain text field with account name. It will allows you to switch to another account.
|
||||||
|
|
||||||
|
### Version compatibility ###
|
||||||
|
* Branch 1.X - for Roundcube v1.1
|
||||||
|
* Branch 2.X - for Roundcube v1.2
|
||||||
|
* Branch 3.X - for Roundcube v1.3
|
||||||
|
|
||||||
|
Please specify verion like "~2.0" in your composer.json file for ident_switch requirement. In this case you will stay inside compatible branch until you manually update ypur Roundcube installation.
|
||||||
|
|
||||||
|
### Switching SMTP ###
|
||||||
|
Plugin also switched SMTP credentials but only for server specified in general config. You should use %u and %p substitutions for user and password to make it work. This substitutions are replaced by username and password for selected IMAP account.
|
||||||
|
|||||||
@@ -11,8 +11,7 @@ CREATE TABLE IF NOT EXISTS ident_switch
|
|||||||
int(10) UNSIGNED
|
int(10) UNSIGNED
|
||||||
NOT NULL,
|
NOT NULL,
|
||||||
username
|
username
|
||||||
varchar(64)
|
varchar(64),
|
||||||
NOT NULL,
|
|
||||||
password
|
password
|
||||||
varchar(64),
|
varchar(64),
|
||||||
host
|
host
|
||||||
|
|||||||
6
SQL/mysql/2018071600.sql
Normal file
6
SQL/mysql/2018071600.sql
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
ALTER TABLE
|
||||||
|
ident_switch
|
||||||
|
MODIFY
|
||||||
|
username
|
||||||
|
varchar(64)
|
||||||
|
NULL;
|
||||||
@@ -13,8 +13,7 @@ CREATE TABLE ident_switch
|
|||||||
REFERENCES identities(identity_id) ON DELETE CASCADE ON UPDATE CASCADE
|
REFERENCES identities(identity_id) ON DELETE CASCADE ON UPDATE CASCADE
|
||||||
UNIQUE,
|
UNIQUE,
|
||||||
username
|
username
|
||||||
varchar(64)
|
varchar(64),
|
||||||
NOT NULL,
|
|
||||||
password
|
password
|
||||||
varchar(64),
|
varchar(64),
|
||||||
host
|
host
|
||||||
|
|||||||
5
SQL/postgres/2018081600.sql
Normal file
5
SQL/postgres/2018081600.sql
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
ALTER TABLE
|
||||||
|
ident_switch
|
||||||
|
ALTER COLUMN
|
||||||
|
username
|
||||||
|
DROP NOT NULL;
|
||||||
@@ -30,7 +30,7 @@
|
|||||||
},
|
},
|
||||||
"extra": {
|
"extra": {
|
||||||
"roundcube": {
|
"roundcube": {
|
||||||
"min-version": "1.1",
|
"min-version": "1.3",
|
||||||
"sql-dir": "SQL"
|
"sql-dir": "SQL"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
10
ident_switch-form.js
Normal file
10
ident_switch-form.js
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
/*
|
||||||
|
* This is part of identity_imap plugin
|
||||||
|
*/
|
||||||
|
|
||||||
|
$(function() {
|
||||||
|
$("INPUT[name='_ident_switch.form.enabled']").change();
|
||||||
|
$("SELECT[name='_ident_switch.form.secure']").change();
|
||||||
|
plugin_switchIdent_processPreconfig();
|
||||||
|
});
|
||||||
|
|
||||||
1
ident_switch-form.min.js
vendored
Normal file
1
ident_switch-form.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
$(function(){$("INPUT[name='_ident_switch.form.enabled']").change();$("SELECT[name='_ident_switch.form.secure']").change();plugin_switchIdent_processPreconfig();});
|
||||||
@@ -3,22 +3,50 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
var $truName = $('.topright .username');
|
$sw = $('#plugin-ident_switch-account');
|
||||||
if ($truName.size() > 0) {
|
isOk = false;
|
||||||
$sw = $('#plugin-ident_switch-account');
|
|
||||||
if ($sw.size() > 0) {
|
switch (rcmail.env['skin']) {
|
||||||
$sw.prependTo('.topright');
|
case 'larry':
|
||||||
$truName.hide();
|
isOk = plugin_switchIdent_addCbLarry($sw);
|
||||||
$('#plugin-ident_switch-account').show();
|
break;
|
||||||
}
|
case 'classic':
|
||||||
|
isOk = plugin_switchIdent_addCbClassic($sw);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isOk)
|
||||||
|
$sw.show();
|
||||||
|
|
||||||
$("INPUT[name='_ident_switch.form.enabled']").change();
|
$("INPUT[name='_ident_switch.form.enabled']").change();
|
||||||
$("SELECT[name='_ident_switch.form.secure']").change();
|
$("SELECT[name='_ident_switch.form.secure']").change();
|
||||||
|
|
||||||
plugin_switchIdent_processPreconfig();
|
plugin_switchIdent_processPreconfig();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function plugin_switchIdent_addCbLarry($sw) {
|
||||||
|
var $truName = $('.topright .username');
|
||||||
|
if ($truName.length > 0) {
|
||||||
|
if ($sw.length > 0) {
|
||||||
|
$sw.prependTo('.topright');
|
||||||
|
$truName.hide();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function plugin_switchIdent_addCbClassic($sw) {
|
||||||
|
var $taskBar = $('#taskbar');
|
||||||
|
if ($taskBar.length > 0) {
|
||||||
|
$taskBar.prepend($sw);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
function plugin_switchIdent_processPreconfig() {
|
function plugin_switchIdent_processPreconfig() {
|
||||||
var disFld = $("INPUT[name='_ident_switch.form.readonly']");
|
var disFld = $("INPUT[name='_ident_switch.form.readonly']");
|
||||||
disFld.parentsUntil("TABLE", "TR").hide();
|
disFld.parentsUntil("TABLE", "TR").hide();
|
||||||
15
ident_switch-switch.min.js
vendored
Normal file
15
ident_switch-switch.min.js
vendored
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
$(function(){$sw=$('#plugin-ident_switch-account');isOk=false;switch(rcmail.env['skin']){case'larry':isOk=plugin_switchIdent_addCbLarry($sw);break;case'classic':isOk=plugin_switchIdent_addCbClassic($sw);break;}
|
||||||
|
if(isOk)
|
||||||
|
$sw.show();$("INPUT[name='_ident_switch.form.enabled']").change();$("SELECT[name='_ident_switch.form.secure']").change();plugin_switchIdent_processPreconfig();});function plugin_switchIdent_addCbLarry($sw){var $truName=$('.topright .username');if($truName.length>0){if($sw.length>0){$sw.prependTo('.topright');$truName.hide();return true;}}
|
||||||
|
return false;}
|
||||||
|
function plugin_switchIdent_addCbClassic($sw){var $taskBar=$('#taskbar');if($taskBar.length>0){$taskBar.prepend($sw);return true;}
|
||||||
|
return false;}
|
||||||
|
function plugin_switchIdent_processPreconfig(){var disFld=$("INPUT[name='_ident_switch.form.readonly']");disFld.parentsUntil("TABLE","TR").hide();var disVal=disFld.val();if(disVal>0){$("INPUT[name='_ident_switch.form.host']").prop("disabled",true);$("SELECT[name='_ident_switch.form.secure']").prop("disabled",true);$("INPUT[name='_ident_switch.form.port']").prop("disabled",true);}
|
||||||
|
if(2==disVal){$("INPUT[name='_ident_switch.form.username']").prop("disabled",true);}}
|
||||||
|
function plugin_switchIdent_enabled_onChange(e){var $enFld=$("INPUT[name='_ident_switch.form.enabled']");$("INPUT[name!='_ident_switch.form.enabled'], SELECT",$enFld.parents("FIELDSET")).prop("disabled",!$enFld.is(":checked"));plugin_switchIdent_processPreconfig();}
|
||||||
|
function plugin_switchIdent_secure_onChange(e){var $secSel=$("SELECT[name='_ident_switch.form.secure']");var $portFld=$("INPUT[name='_ident_switch.form.port']");if('SSL'===$secSel.val().toUpperCase())
|
||||||
|
$portFld.attr("placeholder",993);else
|
||||||
|
$portFld.attr("placeholder",143);}
|
||||||
|
function plugin_switchIdent_switch(val){rcmail.http_post('plugin.ident_switch.switch',{'_ident-id':val,'_mbox':rcmail.env.mailbox});}
|
||||||
|
function plugin_switchIdent_fixIdent(iid){if(parseInt(iid)>0)
|
||||||
|
$("#_from").val(iid);}
|
||||||
10
ident_switch.min.js
vendored
10
ident_switch.min.js
vendored
@@ -1,10 +0,0 @@
|
|||||||
$(function(){var $truName=$('.topright .username');if($truName.size()>0){$sw=$('#plugin-ident_switch-account');if($sw.size()>0){$sw.prependTo('.topright');$truName.hide();$('#plugin-ident_switch-account').show();}}
|
|
||||||
$("INPUT[name='_ident_switch.form.enabled']").change();$("SELECT[name='_ident_switch.form.secure']").change();plugin_switchIdent_processPreconfig();});function plugin_switchIdent_processPreconfig(){var disFld=$("INPUT[name='_ident_switch.form.readonly']");disFld.parentsUntil("TABLE","TR").hide();var disVal=disFld.val();if(disVal>0){$("INPUT[name='_ident_switch.form.host']").prop("disabled",true);$("SELECT[name='_ident_switch.form.secure']").prop("disabled",true);$("INPUT[name='_ident_switch.form.port']").prop("disabled",true);}
|
|
||||||
if(2==disVal){$("INPUT[name='_ident_switch.form.username']").prop("disabled",true);}}
|
|
||||||
function plugin_switchIdent_enabled_onChange(e){var $enFld=$("INPUT[name='_ident_switch.form.enabled']");$("INPUT[name!='_ident_switch.form.enabled'], SELECT",$enFld.parents("FIELDSET")).prop("disabled",!$enFld.is(":checked"));plugin_switchIdent_processPreconfig();}
|
|
||||||
function plugin_switchIdent_secure_onChange(e){var $secSel=$("SELECT[name='_ident_switch.form.secure']");var $portFld=$("INPUT[name='_ident_switch.form.port']");if('SSL'===$secSel.val().toUpperCase())
|
|
||||||
$portFld.attr("placeholder",993);else
|
|
||||||
$portFld.attr("placeholder",143);}
|
|
||||||
function plugin_switchIdent_switch(val){rcmail.http_post('plugin.ident_switch.switch',{'_ident-id':val,'_mbox':rcmail.env.mailbox});}
|
|
||||||
function plugin_switchIdent_fixIdent(iid){if(parseInt(iid)>0)
|
|
||||||
$("#_from").val(iid);}
|
|
||||||
460
ident_switch.php
460
ident_switch.php
@@ -12,14 +12,13 @@ class ident_switch extends rcube_plugin
|
|||||||
{
|
{
|
||||||
public $task='?(?!login|logout).*';
|
public $task='?(?!login|logout).*';
|
||||||
|
|
||||||
private $table = 'ident_switch';
|
const TABLE = 'ident_switch';
|
||||||
private $my_postfix = '_iswitch';
|
const MY_POSTFIX = '_iswitch';
|
||||||
private $my_log = 'ident_switch';
|
|
||||||
|
|
||||||
// Flags user in database
|
// Flags user in database
|
||||||
private $db_enabled = 1;
|
const DB_ENABLED = 1;
|
||||||
private $db_secure_ssl = 2;
|
const DB_SECURE_SSL = 2;
|
||||||
private $db_secure_tls = 4;
|
const DB_SECURE_TLS = 4;
|
||||||
|
|
||||||
function init()
|
function init()
|
||||||
{
|
{
|
||||||
@@ -28,6 +27,8 @@ class ident_switch extends rcube_plugin
|
|||||||
$this->add_hook('smtp_connect', array($this, 'on_smtp_connect'));
|
$this->add_hook('smtp_connect', array($this, 'on_smtp_connect'));
|
||||||
$this->add_hook('identity_form', array($this, 'on_identity_form'));
|
$this->add_hook('identity_form', array($this, 'on_identity_form'));
|
||||||
$this->add_hook('identity_update', array($this, 'on_identity_update'));
|
$this->add_hook('identity_update', array($this, 'on_identity_update'));
|
||||||
|
$this->add_hook('identity_create', array($this, 'on_identity_create'));
|
||||||
|
$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('identity_delete', array($this, 'on_identity_delete'));
|
||||||
$this->add_hook('template_object_composeheaders', array($this, 'on_template_object_composeheaders'));
|
$this->add_hook('template_object_composeheaders', array($this, 'on_template_object_composeheaders'));
|
||||||
|
|
||||||
@@ -57,25 +58,40 @@ class ident_switch extends rcube_plugin
|
|||||||
{
|
{
|
||||||
$rc = rcmail::get_instance();
|
$rc = rcmail::get_instance();
|
||||||
|
|
||||||
// Currently selected identity
|
switch ($rc->task)
|
||||||
$iid = $_SESSION['iid' . $this->my_postfix];
|
{
|
||||||
|
case 'mail':
|
||||||
|
$this->render_switch($rc, $args);
|
||||||
|
case 'settings':
|
||||||
|
$this->include_script('ident_switch-form.js');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
$iid_int = 0;
|
|
||||||
if (is_int($iid))
|
return $args;
|
||||||
$iid_int = $iid;
|
}
|
||||||
elseif ($iid === '-1')
|
|
||||||
$iid_int = -1;
|
private function render_switch($rc, $args)
|
||||||
elseif (ctype_digit($iid))
|
{
|
||||||
$iid_int = intval($iid);
|
// Currently selected identity
|
||||||
|
$iid_s = $_SESSION['iid' . self::MY_POSTFIX];
|
||||||
|
|
||||||
|
$iid = 0;
|
||||||
|
if (is_int($iid_s))
|
||||||
|
$iid = $iid_s;
|
||||||
|
elseif ($iid_s === '-1')
|
||||||
|
$iid = -1;
|
||||||
|
elseif (ctype_digit($iid_s))
|
||||||
|
$iid = intval($iid_s);
|
||||||
|
|
||||||
// Get list of alternative accounts
|
// Get list of alternative accounts
|
||||||
$sOpt = '';
|
$sOpt = '';
|
||||||
$sql = 'SELECT id, iid, label, username FROM ' . $rc->db->table_name($this->table) . ' WHERE user_id = ? AND flags & ? > 0';
|
$sql = 'SELECT id, iid, label, username FROM ' . $rc->db->table_name(self::TABLE) . ' WHERE user_id = ? AND flags & ? > 0';
|
||||||
$qRec = $rc->db->query($sql, $rc->user->data['user_id'], $this->db_enabled);
|
$qRec = $rc->db->query($sql, $rc->user->data['user_id'], self::DB_ENABLED);
|
||||||
while ($r = $rc->db->fetch_assoc($qRec))
|
while ($r = $rc->db->fetch_assoc($qRec))
|
||||||
{
|
{
|
||||||
$opts = array('value' => $r['id']);
|
$opts = array('value' => $r['id']);
|
||||||
if ($iid_int == $r['iid'])
|
if ($iid == $r['iid'])
|
||||||
$opts['selected'] = 'selected';
|
$opts['selected'] = 'selected';
|
||||||
|
|
||||||
// Make label
|
// Make label
|
||||||
@@ -109,7 +125,7 @@ class ident_switch extends rcube_plugin
|
|||||||
{
|
{
|
||||||
// Add main account
|
// Add main account
|
||||||
$opts = array('value' => -1);
|
$opts = array('value' => -1);
|
||||||
if (!$iid || $iid_int == -1)
|
if ($iid <= 0)
|
||||||
$opts['selected'] = 'selected';
|
$opts['selected'] = 'selected';
|
||||||
|
|
||||||
$sOpt = html::tag(
|
$sOpt = html::tag(
|
||||||
@@ -118,7 +134,7 @@ class ident_switch extends rcube_plugin
|
|||||||
$_SESSION['global_alias'] ? $_SESSION['global_alias'] : $rc->user->data['username']
|
$_SESSION['global_alias'] ? $_SESSION['global_alias'] : $rc->user->data['username']
|
||||||
) . $sOpt;
|
) . $sOpt;
|
||||||
|
|
||||||
$this->include_script('ident_switch.js');
|
$this->include_script('ident_switch-switch.js');
|
||||||
$sw = html::tag(
|
$sw = html::tag(
|
||||||
'select',
|
'select',
|
||||||
array(
|
array(
|
||||||
@@ -130,22 +146,33 @@ class ident_switch extends rcube_plugin
|
|||||||
);
|
);
|
||||||
$rc->output->add_footer($sw);
|
$rc->output->add_footer($sw);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $args;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function on_smtp_connect($args)
|
function on_smtp_connect($args)
|
||||||
{
|
{
|
||||||
|
$iid = $_SESSION['iid' . self::MY_POSTFIX];
|
||||||
|
if (!is_integer($iid) || $iid == -1)
|
||||||
|
return $args;
|
||||||
|
|
||||||
$rc = rcmail::get_instance();
|
$rc = rcmail::get_instance();
|
||||||
|
|
||||||
// TODO: Rewrite with full settings!
|
$sql = 'SELECT host, flags, port, username, password, iid FROM ' . $rc->db->table_name(self::TABLE) . ' WHERE iid = ? AND user_id = ?';
|
||||||
|
$q = $rc->db->query($sql, $iid ,$rc->user->ID);
|
||||||
if (strcasecmp($rc->user->data['username'], $_SESSION['username']) !== 0)
|
$r = $rc->db->fetch_assoc($q);
|
||||||
|
if (is_array($r))
|
||||||
{
|
{
|
||||||
if ($args['smtp_user'] == '%u')
|
if (!$r['username'])
|
||||||
$args['smtp_user'] = $rc->user->data['username'];
|
{ // Load email from identity
|
||||||
if ($args['smtp_pass'] == '%p')
|
$sql = 'SELECT email FROM ' . $rc->db->table_name('identities') . ' WHERE identity_id = ?';
|
||||||
$args['smtp_pass'] = $rc->decrypt($_SESSION['password' . $this->my_postfix]);
|
$q = $rc->db->query($sql, $r['iid']);
|
||||||
|
$rIid = $rc->db->fetch_assoc($q);
|
||||||
|
|
||||||
|
$r['username'] = $rIid['email'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exactly the same in core SMTP handler
|
||||||
|
$args['smtp_user'] = str_replace('%u', $r['username'], $args['smtp_user']);
|
||||||
|
$args['smtp_pass'] = str_replace('%p', $rc->decrypt($r['password']), $args['smtp_pass']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $args;
|
return $args;
|
||||||
@@ -157,34 +184,14 @@ class ident_switch extends rcube_plugin
|
|||||||
|
|
||||||
// Do not show options for default identity
|
// Do not show options for default identity
|
||||||
if (strcasecmp($args['record']['email'], $rc->user->data['username']) === 0)
|
if (strcasecmp($args['record']['email'], $rc->user->data['username']) === 0)
|
||||||
return $args;
|
return $args;
|
||||||
|
|
||||||
$this->add_texts('localization');
|
$this->add_texts('localization');
|
||||||
|
|
||||||
// Create our field set
|
|
||||||
$args['form']['ident_switch'] = array(
|
|
||||||
'name' => $this->gettext('form.caption'),
|
|
||||||
'content' => array(
|
|
||||||
'ident_switch.form.enabled' => array('type' => 'checkbox', 'onchange' => 'plugin_switchIdent_enabled_onChange();'),
|
|
||||||
'ident_switch.form.label' => array('type' => 'text', 'size' => 32, 'placeholder' => $args['record']['email']),
|
|
||||||
'ident_switch.form.host' => array('type' => 'text', 'size' => 64, 'placeholder' => 'localhost'),
|
|
||||||
'ident_switch.form.secure' => array(
|
|
||||||
'type' => 'select',
|
|
||||||
'options' => array('ssl' => 'SSL', 'tls' => 'TLS'),
|
|
||||||
'onchange' => 'plugin_switchIdent_secure_onChange();'
|
|
||||||
),
|
|
||||||
'ident_switch.form.port' => array('type' => 'text', 'size' => 5),
|
|
||||||
'ident_switch.form.username' => array('type' => 'text', 'size' => 64, 'placeholder' => $args['record']['email']),
|
|
||||||
'ident_switch.form.password' => array('type' => 'password', 'size' => 64),
|
|
||||||
'ident_switch.form.delimiter' => array('type' => 'text', 'size' => 1, 'placeholder' => '.'),
|
|
||||||
'ident_switch.form.readonly' => array('type' => 'hidden'),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Load data if exists
|
// Load data if exists
|
||||||
if (isset($args['record']['identity_id']))
|
if (isset($args['record']['identity_id']))
|
||||||
{
|
{
|
||||||
$sql = 'SELECT * FROM ' . $rc->db->table_name($this->table) . ' WHERE iid = ? AND user_id = ?';
|
$sql = 'SELECT * FROM ' . $rc->db->table_name(self::TABLE) . ' WHERE iid = ? AND user_id = ?';
|
||||||
$q = $rc->db->query($sql, $args['record']['identity_id'], $rc->user->ID);
|
$q = $rc->db->query($sql, $args['record']['identity_id'], $rc->user->ID);
|
||||||
$r = $rc->db->fetch_assoc($q);
|
$r = $rc->db->fetch_assoc($q);
|
||||||
if ($r)
|
if ($r)
|
||||||
@@ -193,11 +200,11 @@ class ident_switch extends rcube_plugin
|
|||||||
$args['record']['ident_switch.form.' . $k] = $v;
|
$args['record']['ident_switch.form.' . $k] = $v;
|
||||||
|
|
||||||
// Parse flags
|
// Parse flags
|
||||||
if ($r['flags'] & $this->db_enabled)
|
if ($r['flags'] & self::DB_ENABLED)
|
||||||
$args['record']['ident_switch.form.enabled'] = true;
|
$args['record']['ident_switch.form.enabled'] = true;
|
||||||
if ($r['flags'] & $this->db_secure_tls) // TLS has priority
|
if ($r['flags'] & self::DB_SECURE_TLS) // TLS has priority
|
||||||
$args['record']['ident_switch.form.secure'] = 'tls';
|
$args['record']['ident_switch.form.secure'] = 'tls';
|
||||||
elseif ($r['flags'] & $this->db_secure_ssl)
|
elseif ($r['flags'] & self::DB_SECURE_SSL)
|
||||||
$args['record']['ident_switch.form.secure'] = 'ssl';
|
$args['record']['ident_switch.form.secure'] = 'ssl';
|
||||||
|
|
||||||
// Set readonly if needed
|
// Set readonly if needed
|
||||||
@@ -213,6 +220,52 @@ class ident_switch extends rcube_plugin
|
|||||||
$this->apply_preconfig($args['record']);
|
$this->apply_preconfig($args['record']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create our field set
|
||||||
|
// Do that manually decause standard processing shows hidden fields (WTF?)
|
||||||
|
$fieldset = array(
|
||||||
|
'ident_switch.form.enabled' => array('type' => 'checkbox', 'onchange' => 'plugin_switchIdent_enabled_onChange();'),
|
||||||
|
'ident_switch.form.label' => array('type' => 'text', 'size' => 32, 'placeholder' => $args['record']['email']),
|
||||||
|
'ident_switch.form.host' => array('type' => 'text', 'size' => 64, 'placeholder' => 'localhost'),
|
||||||
|
'ident_switch.form.secure' => array(
|
||||||
|
'type' => 'select',
|
||||||
|
'options' => array('ssl' => 'SSL', 'tls' => 'TLS'),
|
||||||
|
'onchange' => 'plugin_switchIdent_secure_onChange();'
|
||||||
|
),
|
||||||
|
'ident_switch.form.port' => array('type' => 'text', 'size' => 5),
|
||||||
|
'ident_switch.form.username' => array('type' => 'text', 'size' => 64, 'placeholder' => $args['record']['email']),
|
||||||
|
'ident_switch.form.password' => array('type' => 'password', 'size' => 64),
|
||||||
|
'ident_switch.form.delimiter' => array('type' => 'text', 'size' => 1, 'placeholder' => '.'),
|
||||||
|
'ident_switch.form.readonly' => array('type' => 'hidden'),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Process fields
|
||||||
|
$addAfter = '';
|
||||||
|
$table = new html_table(array('cols' => 2));
|
||||||
|
foreach ($fieldset as $col => $colprop)
|
||||||
|
{
|
||||||
|
$data = $args['record'][$col];
|
||||||
|
if ($colprop['type'] == 'hidden')
|
||||||
|
{
|
||||||
|
$addAfter .= rcube_output::get_edit_field($col, $data, $colprop, $colprop['type']);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$colprop['id'] = 'rcmfd_' . $col;
|
||||||
|
|
||||||
|
$label = $colprop['label'] ?: $this->gettext(str_replace('-', '', $col));
|
||||||
|
$value = $colprop['value'] ?: rcube_output::get_edit_field($col, $data, $colprop, $colprop['type']);
|
||||||
|
|
||||||
|
$table->add('title', html::label($colprop['id'], rcube::Q($label)));
|
||||||
|
$table->add(null, $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set data for output
|
||||||
|
$args['form']['ident_switch'] = array(
|
||||||
|
'name' => $this->gettext('form.caption'),
|
||||||
|
'content' => $table->show(array('class' => 'propform')) . $addAfter // TODO: copy styles from other tables
|
||||||
|
);
|
||||||
|
|
||||||
return $args;
|
return $args;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,104 +278,70 @@ class ident_switch extends rcube_plugin
|
|||||||
return $args;
|
return $args;
|
||||||
|
|
||||||
// Process boolean fields
|
// Process boolean fields
|
||||||
$flags = 0;
|
if (!rcube_utils::get_input_value('_ident_switch_form_enabled', rcube_utils::INPUT_POST))
|
||||||
if (rcube_utils::get_input_value('_ident_switch_form_enabled', rcube_utils::INPUT_POST))
|
|
||||||
$flags |= $this->db_enabled;
|
|
||||||
|
|
||||||
if (!($flags & $this->db_enabled))
|
|
||||||
{
|
{
|
||||||
$this->sw_imap_off($args['iid']);
|
self::sw_imap_off($args['iid']);
|
||||||
return $args;
|
return $args;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check field values
|
$data = self::check_field_values();
|
||||||
$errMsg = '';
|
if ($data['err'])
|
||||||
|
|
||||||
$fLabel = self::ntrim(rcube_utils::get_input_value('_ident_switch_form_label', rcube_utils::INPUT_POST));
|
|
||||||
if (strlen($fLabel) > 32)
|
|
||||||
$errMsg = 'label.long';
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$fHost = self::ntrim(rcube_utils::get_input_value('_ident_switch_form_host', rcube_utils::INPUT_POST));
|
|
||||||
if (strlen($fHost) > 64)
|
|
||||||
$errMsg = 'host.long';
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$fPort = self::ntrim(rcube_utils::get_input_value('_ident_switch_form_port', rcube_utils::INPUT_POST));
|
|
||||||
if ($fPort && !ctype_digit($fPort))
|
|
||||||
$errMsg = 'port.num';
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ($fPort && ($fPort <= 0 || $fPort > 65535))
|
|
||||||
$errMsg = 'port.range';
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$fUser = self::ntrim(rcube_utils::get_input_value('_ident_switch_form_username', rcube_utils::INPUT_POST));
|
|
||||||
if (strlen($fUser) > 64)
|
|
||||||
$errMsg = 'user.long';
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$fDelim = self::ntrim(rcube_utils::get_input_value('_ident_switch_form_delimiter', rcube_utils::INPUT_POST));
|
|
||||||
if (strlen($fDelim) > 1)
|
|
||||||
$errMsg = 'delim.long';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($errMsg)
|
|
||||||
{
|
{
|
||||||
$this->add_texts('localization');
|
$this->add_texts('localization');
|
||||||
$rc->output->show_message('ident_switch.err.' . $errMsg, 'error');
|
|
||||||
$args['abort'] = true;
|
$args['abort'] = true;
|
||||||
|
$args['message'] = 'ident_switch.err.' . $data['err'];
|
||||||
return $args;
|
return $args;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse secure settings
|
$data['id'] = $args['id'];
|
||||||
$ssl = rcube_utils::get_input_value('_ident_switch_form_secure', rcube_utils::INPUT_POST);
|
self::save_field_values($rc, $data);
|
||||||
if (strcasecmp($ssl, 'tls') === 0)
|
|
||||||
$flags |= $this->db_secure_tls;
|
|
||||||
elseif (strcasecmp($ssl, 'ssl') === 0)
|
|
||||||
$flags |= $this->db_secure_ssl;
|
|
||||||
|
|
||||||
$sql = 'SELECT id, password FROM ' . $rc->db->table_name($this->table) . ' WHERE iid = ? AND user_id = ?';
|
return $args;
|
||||||
$q = $rc->db->query($sql, $args['id'], $rc->user->ID);
|
}
|
||||||
$r = $rc->db->fetch_assoc($q);
|
|
||||||
if ($r)
|
|
||||||
{ // Record already exists, will update it
|
|
||||||
$sql = 'UPDATE ' .
|
|
||||||
$rc->db->table_name($this->table) .
|
|
||||||
' SET flags = ?, label = ?, host = ?, port = ?, username = ?, password = ?, delimiter = ?, user_id = ?, iid = ?' .
|
|
||||||
' WHERE id = ?';
|
|
||||||
}
|
|
||||||
else if ($flags & $this->db_enabled)
|
|
||||||
{ // No record exists, create new one
|
|
||||||
$sql = 'INSERT INTO ' .
|
|
||||||
$rc->db->table_name($this->table) .
|
|
||||||
'(flags, label, host, port, username, password, delimiter, user_id, iid) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($sql)
|
function on_identity_create($args)
|
||||||
|
{
|
||||||
|
$rc = rcmail::get_instance();
|
||||||
|
|
||||||
|
// Do not do anything for default identity
|
||||||
|
if (strcasecmp($args['record']['email'], $rc->user->data['username']) === 0)
|
||||||
|
return $args;
|
||||||
|
|
||||||
|
// Process boolean fields
|
||||||
|
if (!rcube_utils::get_input_value('_ident_switch_form_enabled', rcube_utils::INPUT_POST))
|
||||||
|
return $args;
|
||||||
|
|
||||||
|
$data = self::check_field_values();
|
||||||
|
if ($data['err'])
|
||||||
{
|
{
|
||||||
// Do we need to update pwd?
|
$this->add_texts('localization');
|
||||||
$fPass = rcube_utils::get_input_value('_ident_switch_form_password', rcube_utils::INPUT_POST);
|
$args['abort'] = true;
|
||||||
if ($fPass != $r['password'])
|
$args['message'] = 'ident_switch.err.' . $data['err'];
|
||||||
$fPass = $rc->encrypt($fPass);
|
}
|
||||||
|
|
||||||
$rc->db->query(
|
// Save data for _after (cannot pass with $args)
|
||||||
$sql,
|
$_SESSION['createData' . self::MY_POSTFIX] = $data;
|
||||||
$flags,
|
|
||||||
$fLabel,
|
return $args;
|
||||||
$fHost,
|
}
|
||||||
$fPort,
|
|
||||||
$fUser,
|
function on_identity_create_after($args)
|
||||||
$fPass,
|
{
|
||||||
$fDelim,
|
$rc = rcmail::get_instance();
|
||||||
$rc->user->ID,
|
|
||||||
$args['id'],
|
// Do not do anything for default identity
|
||||||
$r['id']
|
if (strcasecmp($args['record']['email'], $rc->user->data['username']) === 0)
|
||||||
);
|
return $args;
|
||||||
|
|
||||||
|
$data = $_SESSION['createData' . self::MY_POSTFIX];
|
||||||
|
|
||||||
|
unset($_SESSION['createData' . self::MY_POSTFIX]);
|
||||||
|
if (!$data || count($data) == 0)
|
||||||
|
self::write_log('Object with ident_switch values not found in session for ID = ' . $args['id'] . '.');
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$data['id'] = $args['id'];
|
||||||
|
self::save_field_values($rc, $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $args;
|
return $args;
|
||||||
@@ -332,11 +351,11 @@ class ident_switch extends rcube_plugin
|
|||||||
{
|
{
|
||||||
$rc = rcmail::get_instance();
|
$rc = rcmail::get_instance();
|
||||||
|
|
||||||
$sql = 'DELETE FROM ' . $rc->db->table_name($this->table) . ' WHERE iid = ? AND user_id = ?';
|
$sql = 'DELETE FROM ' . $rc->db->table_name(self::TABLE) . ' WHERE iid = ? AND user_id = ?';
|
||||||
$q = $rc->db->query($sql, $args['id'], $rc->user->ID);
|
$q = $rc->db->query($sql, $args['id'], $rc->user->ID);
|
||||||
|
|
||||||
if ($rc->db->affected_rows($q))
|
if ($rc->db->affected_rows($q))
|
||||||
$rc->write_log($this->my_log, 'Deleted associated information for identity with ID = ' . $args['id'] . '.');
|
self::write_log('Deleted associated information for identity with ID = ' . $args['id'] . '.');
|
||||||
|
|
||||||
return $args;
|
return $args;
|
||||||
}
|
}
|
||||||
@@ -348,29 +367,126 @@ class ident_switch extends rcube_plugin
|
|||||||
$rc = rcmail::get_instance();
|
$rc = rcmail::get_instance();
|
||||||
if (strcasecmp($_SESSION['username'], $rc->user->data['username']) !== 0)
|
if (strcasecmp($_SESSION['username'], $rc->user->data['username']) !== 0)
|
||||||
{
|
{
|
||||||
if (isset($_SESSION['iid' . $this->my_postfix]))
|
if (isset($_SESSION['iid' . self::MY_POSTFIX]))
|
||||||
$rc->output->add_script('plugin_switchIdent_fixIdent(' . $_SESSION['iid' . $this->my_postfix] . ');', 'docready');
|
$rc->output->add_script('plugin_switchIdent_fixIdent(' . $_SESSION['iid' . self::MY_POSTFIX] . ');', 'docready');
|
||||||
else
|
else
|
||||||
$rc->write_log($this->my_log, 'Special session variable with active identity ID not found.');
|
self::write_log('Special session variable with active identity ID not found.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static function check_field_values()
|
||||||
|
{
|
||||||
|
$retVal = array();
|
||||||
|
|
||||||
|
$retVal['label'] = self::ntrim(rcube_utils::get_input_value('_ident_switch_form_label', rcube_utils::INPUT_POST));
|
||||||
|
if (strlen($retVal['label']) > 32)
|
||||||
|
$retVal['err'] = 'label.long';
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$retVal['host'] = self::ntrim(rcube_utils::get_input_value('_ident_switch_form_host', rcube_utils::INPUT_POST));
|
||||||
|
if (strlen($retVal['host']) > 64)
|
||||||
|
$retVal['err'] = 'host.long';
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$retVal['port'] = self::ntrim(rcube_utils::get_input_value('_ident_switch_form_port', rcube_utils::INPUT_POST));
|
||||||
|
if ($retVal['port'] && !ctype_digit($retVal['port']))
|
||||||
|
$retVal['err'] = 'port.num';
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ($retVal['port'] && ($retVal['port'] <= 0 || $retVal['port'] > 65535))
|
||||||
|
$retVal['err'] = 'port.range';
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$retVal['user'] = self::ntrim(rcube_utils::get_input_value('_ident_switch_form_username', rcube_utils::INPUT_POST));
|
||||||
|
if (strlen($retVal['user']) > 64)
|
||||||
|
$retVal['err'] = 'user.long';
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$retVal['delim'] = self::ntrim(rcube_utils::get_input_value('_ident_switch_form_delimiter', rcube_utils::INPUT_POST));
|
||||||
|
if (strlen($retVal['delim']) > 1)
|
||||||
|
$retVal['err'] = 'delim.long';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get also password
|
||||||
|
$retVal['pass'] = rcube_utils::get_input_value('_ident_switch_form_password', rcube_utils::INPUT_POST);
|
||||||
|
|
||||||
|
// Parse secure settings
|
||||||
|
$retVal['flags'] = self::DB_ENABLED;
|
||||||
|
$ssl = rcube_utils::get_input_value('_ident_switch_form_secure', rcube_utils::INPUT_POST);
|
||||||
|
if (strcasecmp($ssl, 'tls') === 0)
|
||||||
|
$retVal['flags'] |= self::DB_SECURE_TLS;
|
||||||
|
elseif (strcasecmp($ssl, 'ssl') === 0)
|
||||||
|
$retVal['flags'] |= self::DB_SECURE_SSL;
|
||||||
|
|
||||||
|
return $retVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static function save_field_values($rc, $data)
|
||||||
|
{
|
||||||
|
$sql = 'SELECT id, password FROM ' . $rc->db->table_name(self::TABLE) . ' WHERE iid = ? AND user_id = ?';
|
||||||
|
$q = $rc->db->query($sql, $data['id'], $rc->user->ID);
|
||||||
|
$r = $rc->db->fetch_assoc($q);
|
||||||
|
if ($r)
|
||||||
|
{ // Record already exists, will update it
|
||||||
|
$sql = 'UPDATE ' .
|
||||||
|
$rc->db->table_name(self::TABLE) .
|
||||||
|
' SET flags = ?, label = ?, host = ?, port = ?, username = ?, password = ?, delimiter = ?, user_id = ?, iid = ?' .
|
||||||
|
' WHERE id = ?';
|
||||||
|
}
|
||||||
|
else if ($data['flags'] & self::DB_ENABLED)
|
||||||
|
{ // No record exists, create new one
|
||||||
|
$sql = 'INSERT INTO ' .
|
||||||
|
$rc->db->table_name(self::TABLE) .
|
||||||
|
'(flags, label, host, port, username, password, delimiter, user_id, iid) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($sql)
|
||||||
|
{
|
||||||
|
// Do we need to update pwd?
|
||||||
|
if ($data['pass'] != $r['password'])
|
||||||
|
$data['pass'] = $rc->encrypt($data['pass']);
|
||||||
|
|
||||||
|
$rc->db->query(
|
||||||
|
$sql,
|
||||||
|
$data['flags'],
|
||||||
|
$data['label'],
|
||||||
|
$data['host'],
|
||||||
|
$data['port'],
|
||||||
|
$data['user'],
|
||||||
|
$data['pass'],
|
||||||
|
$data['delim'],
|
||||||
|
$rc->user->ID,
|
||||||
|
$data['id'],
|
||||||
|
$r['id']
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
function on_switch()
|
function on_switch()
|
||||||
{
|
{
|
||||||
$rc = rcmail::get_instance();
|
$rc = rcmail::get_instance();
|
||||||
|
|
||||||
$my_postfix_len = strlen($this->my_postfix);
|
$my_postfix_len = strlen(self::MY_POSTFIX);
|
||||||
$identId = rcube_utils::get_input_value('_ident-id', rcube_utils::INPUT_POST);
|
$identId = rcube_utils::get_input_value('_ident-id', rcube_utils::INPUT_POST);
|
||||||
|
|
||||||
if (-1 == $identId)
|
if (-1 == $identId)
|
||||||
{ // Switch to main account
|
{ // Switch to main account
|
||||||
$rc->write_log($this->my_log, 'Switching mailbox back to default.');
|
self::write_log('Switching mailbox back to default.');
|
||||||
|
|
||||||
// Restore everything with STORAGE*my_postfix
|
// Restore everything with STORAGE*my_postfix
|
||||||
foreach ($_SESSION as $k => $v)
|
foreach ($_SESSION as $k => $v)
|
||||||
{
|
{
|
||||||
if (strncasecmp($k, 'storage', 7) === 0 && substr_compare($k, $this->my_postfix, -$my_postfix_len, $my_postfix_len) === 0)
|
if (strncasecmp($k, 'storage', 7) === 0 && substr_compare($k, self::MY_POSTFIX, -$my_postfix_len, $my_postfix_len) === 0)
|
||||||
{
|
{
|
||||||
$realKey = substr($k, 0, -$my_postfix_len);
|
$realKey = substr($k, 0, -$my_postfix_len);
|
||||||
$_SESSION[$realKey] = $_SESSION[$k];
|
$_SESSION[$realKey] = $_SESSION[$k];
|
||||||
@@ -378,12 +494,12 @@ class ident_switch extends rcube_plugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$_SESSION['username'] = $rc->user->data['username'];
|
$_SESSION['username'] = $rc->user->data['username'];
|
||||||
$_SESSION['password'] = $_SESSION['password' . $this->my_postfix];
|
$_SESSION['password'] = $_SESSION['password' . self::MY_POSTFIX];
|
||||||
$_SESSION['iid' . $this->my_postfix] = -1;
|
$_SESSION['iid' . self::MY_POSTFIX] = -1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$sql = 'SELECT host, flags, port, username, password, iid 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(self::TABLE) . ' WHERE id = ? AND user_id = ?';
|
||||||
$q = $rc->db->query($sql, $identId ,$rc->user->ID);
|
$q = $rc->db->query($sql, $identId ,$rc->user->ID);
|
||||||
$r = $rc->db->fetch_assoc($q);
|
$r = $rc->db->fetch_assoc($q);
|
||||||
if (is_array($r))
|
if (is_array($r))
|
||||||
@@ -397,19 +513,16 @@ class ident_switch extends rcube_plugin
|
|||||||
$r['username'] = $rIid['email'];
|
$r['username'] = $rIid['email'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$rc->write_log(
|
self::write_log('Switching mailbox to one for identity with ID = ' . $r['iid'] . ' (username = \'' . $r['username'] . '\').');
|
||||||
$this->my_log,
|
|
||||||
'Switching mailbox to one for identity with ID = ' . $r['iid'] . ' (username = \'' . $r['username'] . '\').'
|
|
||||||
);
|
|
||||||
|
|
||||||
$def_port = 143; // Default port here!
|
$def_port = 143; // Default port here!
|
||||||
$ssl = null;
|
$ssl = null;
|
||||||
if ($r['flags'] & $this->db_secure_tls)
|
if ($r['flags'] & self::DB_SECURE_TLS)
|
||||||
{
|
{
|
||||||
$ssl = 'tls';
|
$ssl = 'tls';
|
||||||
$def_port = 143; // Default TLS port here!
|
$def_port = 143; // Default TLS port here!
|
||||||
}
|
}
|
||||||
elseif ($r['flags'] & $this->db_secure_ssl)
|
elseif ($r['flags'] & self::DB_SECURE_SSL)
|
||||||
{
|
{
|
||||||
$ssl = 'ssl';
|
$ssl = 'ssl';
|
||||||
$def_port = 993; // Default SSL port here!
|
$def_port = 993; // Default SSL port here!
|
||||||
@@ -425,30 +538,30 @@ class ident_switch extends rcube_plugin
|
|||||||
{
|
{
|
||||||
foreach ($_SESSION as $k => $v)
|
foreach ($_SESSION as $k => $v)
|
||||||
{
|
{
|
||||||
if (strncasecmp($k, 'storage', 7) === 0 && substr_compare($k, $this->my_postfix, -$my_postfix_len, $my_postfix_len) !== 0)
|
if (strncasecmp($k, 'storage', 7) === 0 && substr_compare($k, self::MY_POSTFIX, -$my_postfix_len, $my_postfix_len) !== 0)
|
||||||
{
|
{
|
||||||
if (!$_SESSION[$k . $this->my_postfix])
|
if (!$_SESSION[$k . self::MY_POSTFIX])
|
||||||
$_SESSION[$k . $this->my_postfix] = $_SESSION[$k];
|
$_SESSION[$k . self::MY_POSTFIX] = $_SESSION[$k];
|
||||||
$rc->session->remove($k);
|
$rc->session->remove($k);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!$_SESSION['password' . $this->my_postfix])
|
if (!$_SESSION['password' . self::MY_POSTFIX])
|
||||||
$_SESSION['password' . $this->my_postfix] = $_SESSION['password'];
|
$_SESSION['password' . self::MY_POSTFIX] = $_SESSION['password'];
|
||||||
|
|
||||||
$_SESSION['storage_host'] = $r['host'] ? $r['host'] : 'localhost'; // Default host here!
|
$_SESSION['storage_host'] = $r['host'] ? $r['host'] : 'localhost'; // Default host here!
|
||||||
$_SESSION['storage_ssl'] = $ssl;
|
$_SESSION['storage_ssl'] = $ssl;
|
||||||
$_SESSION['storage_port'] = $port;
|
$_SESSION['storage_port'] = $port;
|
||||||
$_SESSION['username'] = $r['username'];
|
$_SESSION['username'] = $r['username'];
|
||||||
$_SESSION['password'] = $r['password'];
|
$_SESSION['password'] = $r['password'];
|
||||||
$_SESSION['iid' . $this->my_postfix] = $r['iid'];
|
$_SESSION['iid' . self::MY_POSTFIX] = $r['iid'];
|
||||||
|
|
||||||
$rc->session->remove('folders');
|
$rc->session->remove('folders');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// TODO: Show message in browser
|
// TODO: Show message in browser
|
||||||
$rc->write_log($this->my_log, 'Requested remote mailbox with ID = ' . $identId . ' not found.');
|
self::write_log('Requested remote mailbox with ID = ' . $identId . ' not found.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -461,21 +574,20 @@ class ident_switch extends rcube_plugin
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function sw_imap_off($iid)
|
private static function sw_imap_off($iid)
|
||||||
{
|
{
|
||||||
$rc = rcmail::get_instance();
|
$rc = rcmail::get_instance();
|
||||||
|
|
||||||
$sql = 'UPDATE ' . $rc->db->table_name($this->table) . ' SET flags = flags & ? WHERE iid = ? AND user_id = ?';
|
$sql = 'UPDATE ' . $rc->db->table_name(self::TABLE) . ' SET flags = flags & ? WHERE iid = ? AND user_id = ?';
|
||||||
$rc->db->query($sql, ~$this->db_enabled, $iid, $rc->user->ID);
|
$rc->db->query($sql, ~self::DB_ENABLED, $iid, $rc->user->ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function get_preconfig($email)
|
private function get_preconfig($email)
|
||||||
{
|
{
|
||||||
$dom = substr(strstr($email, '@'), 1);
|
$dom = substr(strstr($email, '@'), 1);
|
||||||
if (!$dom)
|
if (!$dom)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
//$this->load_config('config.inc.php.dist'); Don't need it yet
|
|
||||||
$this->load_config(); // config.inc.php
|
$this->load_config(); // config.inc.php
|
||||||
|
|
||||||
$cfg = rcmail::get_instance()->config->get('ident_switch.preconfig', array());
|
$cfg = rcmail::get_instance()->config->get('ident_switch.preconfig', array());
|
||||||
@@ -489,16 +601,13 @@ class ident_switch extends rcube_plugin
|
|||||||
return $cfg;
|
return $cfg;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function apply_preconfig(&$record)
|
private function apply_preconfig(&$record)
|
||||||
{
|
{
|
||||||
$email = $record['email'];
|
$email = $record['email'];
|
||||||
$cfg = $this->get_preconfig($email);
|
$cfg = $this->get_preconfig($email);
|
||||||
if (is_array($cfg))
|
if (is_array($cfg))
|
||||||
{
|
{
|
||||||
rcmail::get_instance()->write_log(
|
self::write_log('Applying predefined configuration for \'' . $email . '\'.');
|
||||||
$this->my_log,
|
|
||||||
'Applying predefined configuration for \'' . $email . '\'.'
|
|
||||||
);
|
|
||||||
|
|
||||||
if ($cfg['host'])
|
if ($cfg['host'])
|
||||||
{ // Parse and set host and related
|
{ // Parse and set host and related
|
||||||
@@ -542,7 +651,7 @@ class ident_switch extends rcube_plugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static function ntrim($str)
|
private static function ntrim($str)
|
||||||
{
|
{
|
||||||
if (is_null($str))
|
if (is_null($str))
|
||||||
return $str;
|
return $str;
|
||||||
@@ -553,4 +662,9 @@ class ident_switch extends rcube_plugin
|
|||||||
|
|
||||||
return $s;
|
return $s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static function write_log($txt)
|
||||||
|
{
|
||||||
|
rcmail::get_instance()->write_log('ident_switch', $txt);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user