16 Commits
3.3 ... 4.0

Author SHA1 Message Date
Boris Gulay
c2380e630b Better image for settings 2019-01-12 15:55:13 +03:00
Boris Gulay
a062f5ebb5 Readme rewritten.
It's now sexy, contains images and explains settings!
2019-01-12 15:51:30 +03:00
Boris Gulay
f164ccfd05 SQLite script updates for new SMTP feature. 2019-01-10 23:55:33 +03:00
Boris Gulay
34fd9ca6f6 Update German translation. 2019-01-10 00:25:13 +03:00
Boris Gulay
6ba63dfe50 Updated MySQL scripts to work with new SMTP feature.
Closes #34
Closes #26
2019-01-08 15:26:04 +03:00
Boris Gulay
e79ec4e45b English translation updated 2018-12-29 15:07:21 +03:00
Boris Gulay
f1bd9679da Added SMTP server TLS connection. 2018-12-22 17:31:58 +03:00
Boris Gulay
68164414c2 Fix saving label. 2018-12-22 16:55:30 +03:00
Boris Gulay
d8ea3d5539 Fix setting flags on form load. 2018-12-22 16:50:46 +03:00
Boris Gulay
a4dc73c6a7 Fix password saving. 2018-12-22 16:36:55 +03:00
Boris Gulay
f796334126 Add ability to specify SMTP server directly.
Closes #32.
Closes #30.
2018-12-22 13:31:25 +03:00
Boris Gulay
d65ad79709 Added support for new Elastic skin in v1.4. Thanx to Estudio Nexos.
Closes #33
2018-12-06 20:07:52 +03:00
Boris Gulay
43a9ed178e Made git another way 2018-12-06 19:55:02 +03:00
Boris Gulay
cc68ab1521 JS optimizations. 2018-11-10 18:32:44 +03:00
Boris Gulay
ea21509f2a Added initial script for SQLite. Thanx to Gergely Papp. Closes #29. 2018-10-12 17:32:58 +03:00
Boris Gulay
24a9584d6f Fixed typo in field name. Closes #25 (thanx Dariusz Bijoś) 2018-08-27 22:24:48 +03:00
17 changed files with 497 additions and 273 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
*.swp
.idea

View File

@@ -1,21 +1,37 @@
# ident_switch
ident_switch plugin for Roundcube
This plugin allows users to switch between different accounts (including remote) in single Roundcube session.
This plugin allows users to switch between different accounts (including remote) in single Roundcube session like this:
![Screenshot example](https://i.imgur.com/rRIqtA8.jpg)
*Inspired by identities_imap plugin that is no longer supported.*
### Where to start ###
* 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.
* 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.
* In settings interface create new identity.
* For all identities except default you will see new section of settings - "Plugin ident_switch" (see screenshot below). 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 plugin 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.
### Settings ###
![Plugin settings](https://i.imgur.com/rFaHUbR.jpg)
* **Enabled** - enables plugin (i.e. account switcing) for this identity.
* **Label** - text that will be displayed in drop down list for this identity. If left blank email will be used.
* **IMAP**
* **Server host name** - host name for imap server. If left blank 'localhost' will be used.
* **Port** - port on server to connect to. If left blank 143 will be used.
* **Secure connection** - enabled secure connection (TLS) *for both IMAP and SMTP*.
* **Username** - login used *for IMAP and SMTP servers*.
* **Password** - password used *for IMAP and SMTP servers*. It's stored encrypted in database.
* **SMTP**
* **Server host name** - host name for imap server. If left blank 'localhost' will be used.
* **Port** - port on server to connect to. If left blank 587 will be used.
### Version compatibility ###
* Branch 1.X - for Roundcube v1.1
* Branch 2.X - for Roundcube v1.2
* Branch 3.X - for Roundcube v1.3
* Versions 1.X (not supported any more) - for Roundcube v1.1
* Versions 2.X (not supported any more) - for Roundcube v1.2
* Versions 3.X (not supported any more) - for Roundcube v1.3
* Versions 4.x - for Roundcube v1.3 and upcoming 1.4.
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.
Please specify version 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 your Roundcube installation.

View File

@@ -14,19 +14,22 @@ CREATE TABLE IF NOT EXISTS ident_switch
varchar(64),
password
varchar(64),
host
imap_host
varchar(64),
port
imap_port
int
CHECK(port > 0 AND port <= 65535),
delimiter
char(1),
label
varchar(32),
flags
int
NOT NULL
DEFAULT 0,
smtp_host
varchar(64),
smtp_port
int
CHECK(port > 0 AND port <= 65535),
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,

29
SQL/mysql/2018121800.sql Normal file
View File

@@ -0,0 +1,29 @@
ALTER TABLE
ident_switch
CHANGE
host
imap_host varchar(64);
ALTER TABLE
ident_switch
CHANGE
port
imap_port int;
ALTER TABLE
ident_switch
ADD COLUMN
smtp_host
varchar(64);
ALTER TABLE
ident_switch
ADD COLUMN
smtp_port
int
CHECK(smtp_port > 0 AND smtp_port <= 65535);
ALTER TABLE
ident_switch
DROP COLUMN
delimiter;

View File

@@ -16,19 +16,22 @@ CREATE TABLE ident_switch
varchar(64),
password
varchar(64),
host
imap_host
varchar(64),
port
imap_port
integer
CHECK(port > 0 AND port <= 65535),
delimiter
char(1),
label
varchar(32),
flags
integer
NOT NULL
DEFAULT(0),
smtp_host
varchar(64),
smtp_port
integer
CHECK(port > 0 AND port <= 65535),
UNIQUE (user_id, label)
);

View File

@@ -0,0 +1,31 @@
ALTER TABLE
ident_switch
RENAME COLUMN
host
TO
imap_host;
ALTER TABLE
ident_switch
RENAME COLUMN
port
TO
imap_port;
ALTER TABLE
ident_switch
ADD COLUMN
smtp_host
varchar(64);
ALTER TABLE
ident_switch
ADD COLUMN
smtp_port
integer
CHECK(smtp_port > 0 AND smtp_port <= 65535);
ALTER TABLE
ident_switch
DROP COLUMN
delimiter;

38
SQL/sqlite.initial.sql Normal file
View File

@@ -0,0 +1,38 @@
CREATE TABLE ident_switch
(
id
serial
PRIMARY KEY,
user_id
integer
NOT NULL
REFERENCES users(user_id) ON DELETE CASCADE ON UPDATE CASCADE,
iid
integer
NOT NULL
REFERENCES identities(identity_id) ON DELETE CASCADE ON UPDATE CASCADE
UNIQUE,
username
varchar(64),
password
varchar(64),
imap_host
varchar(64),
imap_port
integer
CHECK(imap_port > 0 AND imap_port <= 65535),
label
varchar(32),
flags
integer
NOT NULL
DEFAULT(0),
smtp_host
varchar(64),
smtp_port
integer
CHECK(smtp_port > 0 AND smtp_port <= 65535),
UNIQUE (user_id, label)
);
CREATE INDEX IX_ident_switch_user_id ON ident_switch(user_id);
CREATE INDEX IX_ident_switch_iid on ident_switch(iid);

25
SQL/sqlite/2018121800.sql Normal file
View File

@@ -0,0 +1,25 @@
ALTER TABLE
ident_switch
RENAME COLUMN
host
TO
imap_host;
ALTER TABLE
ident_switch
RENAME COLUMN
port
TO
imap_port;
ALTER TABLE
ident_switch
ADD COLUMN
smtp_host
varchar(64);
ALTER TABLE
ident_switch
ADD COLUMN
smtp_port
int;

View File

@@ -19,8 +19,9 @@
}
],
"require": {
"php": ">=5.3.0",
"roundcube/plugin-installer": ">=0.1.3"
"php": ">=5.3.0",
"roundcube/plugin-installer": ">=0.1.3",
"ext-ctype": "*"
},
"conflict": {
"elm/identity_smtp": "*"

View File

@@ -3,8 +3,33 @@
*/
$(function() {
$("INPUT[name='_ident_switch.form.enabled']").change();
$("SELECT[name='_ident_switch.form.secure']").change();
$("INPUT[name='_ident_switch.form.common.enabled']").change();
plugin_switchIdent_processPreconfig();
});
function plugin_switchIdent_processPreconfig() {
var disFld = $("INPUT[name='_ident_switch.form.common.readonly']");
disFld.parentsUntil("TABLE", "TR").hide();
var disVal = disFld.val();
if (disVal > 0) {
$("INPUT[name='_ident_switch.form.imap.host']").prop("disabled", true);
$("SELECT[name='_ident_switch.form.imap.tls']").prop("disabled", true);
$("INPUT[name='_ident_switch.form.imap.port']").prop("disabled", true);
$("INPUT[name='_ident_switch.form.smtp.host']").prop("disabled", true);
$("SELECT[name='_ident_switch.form.smtp.tls']").prop("disabled", true);
$("INPUT[name='_ident_switch.form.smtp.port']").prop("disabled", true);
}
if (2 == disVal) {
$("INPUT[name='_ident_switch.form.imap.username']").prop("disabled", true);
$("INPUT[name='_ident_switch.form.smtp.username']").prop("disabled", true);
}
}
function plugin_switchIdent_enabled_onChange(e) {
var $enFld = $("INPUT[name='_ident_switch.form.common.enabled'], INPUT[name='_ident_switch.form.imap.host'], INPUT[name='_ident_switch.form.smtp.host']");
$("INPUT[name!='_ident_switch.form.common.enabled']", $enFld.parents("FIELDSET")).prop("disabled", !$enFld.is(":checked"));
plugin_switchIdent_processPreconfig();
}

View File

@@ -1 +1 @@
$(function(){$("INPUT[name='_ident_switch.form.enabled']").change();$("SELECT[name='_ident_switch.form.secure']").change();plugin_switchIdent_processPreconfig();});
$(function(){$("INPUT[name='_ident_switch.form.common.enabled']").change();plugin_switchIdent_processPreconfig()});function plugin_switchIdent_processPreconfig(){var a=$("INPUT[name='_ident_switch.form.common.readonly']");a.parentsUntil("TABLE","TR").hide();var b=a.val();if(b>0){$("INPUT[name='_ident_switch.form.imap.host']").prop("disabled",true);$("SELECT[name='_ident_switch.form.imap.tls']").prop("disabled",true);$("INPUT[name='_ident_switch.form.imap.port']").prop("disabled",true);$("INPUT[name='_ident_switch.form.smtp.host']").prop("disabled",true);$("SELECT[name='_ident_switch.form.smtp.tls']").prop("disabled",true);$("INPUT[name='_ident_switch.form.smtp.port']").prop("disabled",true)}if(2==b){$("INPUT[name='_ident_switch.form.imap.username']").prop("disabled",true);$("INPUT[name='_ident_switch.form.smtp.username']").prop("disabled",true)}}function plugin_switchIdent_enabled_onChange(a){var b=$("INPUT[name='_ident_switch.form.common.enabled'], INPUT[name='_ident_switch.form.imap.host'], INPUT[name='_ident_switch.form.smtp.host']");$("INPUT[name!='_ident_switch.form.common.enabled']",b.parents("FIELDSET")).prop("disabled",!b.is(":checked"));plugin_switchIdent_processPreconfig()};

View File

@@ -13,14 +13,13 @@ $(function() {
case 'classic':
isOk = plugin_switchIdent_addCbClassic($sw);
break;
case 'elastic':
isOk = plugin_switchIdent_addCbElastic($sw);
break;
}
if (isOk)
$sw.show();
$("INPUT[name='_ident_switch.form.enabled']").change();
$("SELECT[name='_ident_switch.form.secure']").change();
plugin_switchIdent_processPreconfig();
$sw.show();
});
function plugin_switchIdent_addCbLarry($sw) {
@@ -47,39 +46,22 @@ function plugin_switchIdent_addCbClassic($sw) {
return false;
}
function plugin_switchIdent_processPreconfig() {
var disFld = $("INPUT[name='_ident_switch.form.readonly']");
disFld.parentsUntil("TABLE", "TR").hide();
function plugin_switchIdent_addCbElastic($sw) {
var $taskBar = $('.header-title.username');
$sw.css("background-color", "transparent").css("border","none");
$sw.css("background-position-x","left 0.75rem").css("padding","0 0 0 2rem");
$sw.css("font-weight","bold").css("box-shadow","none");
if ($taskBar.length > 0) {
$taskBar.prepend($sw);
return true;
}
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);
return false;
}
function plugin_switchIdent_switch(val) {
rcmail.env.unread_counts = {};
console.log(rcmail.env.unread_counts);
rcmail.http_post('plugin.ident_switch.switch', { '_ident-id': val, '_mbox': rcmail.env.mailbox });
}

View File

@@ -1,15 +1 @@
$(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);}
$(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;case"elastic":isOk=plugin_switchIdent_addCbElastic($sw);break}if(isOk){$sw.show()}});function plugin_switchIdent_addCbLarry(b){var a=$(".topright .username");if(a.length>0){if(b.length>0){b.prependTo(".topright");a.hide();return true}}return false}function plugin_switchIdent_addCbClassic(b){var a=$("#taskbar");if(a.length>0){a.prepend(b);return true}return false}function plugin_switchIdent_addCbElastic(b){var a=$(".header-title.username");b.css("background-color","transparent").css("border","none");b.css("background-position-x","left 0.75rem").css("padding","0 0 0 2rem");b.css("font-weight","bold").css("box-shadow","none");if(a.length>0){a.prepend(b);return true}return false}function plugin_switchIdent_switch(a){rcmail.env.unread_counts={};console.log(rcmail.env.unread_counts);rcmail.http_post("plugin.ident_switch.switch",{"_ident-id":a,_mbox:rcmail.env.mailbox})}function plugin_switchIdent_fixIdent(a){if(parseInt(a)>0){$("#_from").val(a)}};

View File

@@ -16,9 +16,9 @@ class ident_switch extends rcube_plugin
const MY_POSTFIX = '_iswitch';
// Flags user in database
const DB_ENABLED = 1;
const DB_SECURE_SSL = 2;
const DB_SECURE_TLS = 4;
const DB_ENABLED = 1;
//const DB_SECURE_SSL = 2; // Not supported any more
const DB_SECURE_IMAP_TLS = 4;
function init()
{
@@ -62,6 +62,7 @@ class ident_switch extends rcube_plugin
{
case 'mail':
$this->render_switch($rc, $args);
break;
case 'settings':
$this->include_script('ident_switch-form.js');
break;
@@ -156,7 +157,7 @@ class ident_switch extends rcube_plugin
$rc = rcmail::get_instance();
$sql = 'SELECT host, flags, port, username, password, iid FROM ' . $rc->db->table_name(self::TABLE) . ' WHERE iid = ? AND user_id = ?';
$sql = 'SELECT smtp_host, flags, smtp_port, username, password FROM ' . $rc->db->table_name(self::TABLE) . ' WHERE iid = ? AND user_id = ?';
$q = $rc->db->query($sql, $iid ,$rc->user->ID);
$r = $rc->db->fetch_assoc($q);
if (is_array($r))
@@ -164,106 +165,125 @@ class ident_switch extends rcube_plugin
if (!$r['username'])
{ // Load email from identity
$sql = 'SELECT email FROM ' . $rc->db->table_name('identities') . ' WHERE identity_id = ?';
$q = $rc->db->query($sql, $r['iid']);
$q = $rc->db->query($sql, $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']);
$args['smtp_user'] = $r['username'];
$args['smtp_pass'] = $rc->decrypt($r['password']);
$args['smtp_server'] = $r['smtp_host'] ? $r['smtp_host'] : 'localhost'; // Default SMTP host here
$args['smtp_port'] = $r['smtp_port'] ? $r['smtp_port'] : 587; // Default SMTP port here
if ($r['flags'] & self::DB_SECURE_IMAP_TLS)
{
if (strpos($args['smtp_server'], ':') !== false)
self::write_log('SMTP server already contains protocol, ignoring TLS flag.');
else
$args['smtp_server'] = 'tls://' . $args['smtp_server'];
}
self::write_log(print_r($args, true));
}
return $args;
}
private static function get_common_form(&$record)
{
$prefix = 'ident_switch.form.common.';
return array(
$prefix . 'enabled' => array('type' => 'checkbox', 'onchange' => 'plugin_switchIdent_enabled_onChange();'),
$prefix . 'label' => array('type' => 'text', 'size' => 32, 'placeholder' => $record['email']),
$prefix . 'readonly' => array('type' => 'hidden'),
);
}
private static function get_imap_form(&$record)
{
$prefix = 'ident_switch.form.imap.';
return array(
$prefix . 'host' => array('type' => 'text', 'size' => 64, 'placeholder' => 'localhost'),
$prefix . 'port' => array('type' => 'text', 'size' => 5, 'placeholder' => 143),
$prefix . 'tls' => array('type' => 'checkbox'),
$prefix . 'username' => array('type' => 'text', 'size' => 64, 'placeholder' => $record['email']),
$prefix . 'password' => array('type' => 'password', 'size' => 64),
);
}
private static function get_smtp_form(&$record)
{
$prefix = 'ident_switch.form.smtp.';
return array(
$prefix . 'host' => array('type' => 'text', 'size' => 64, 'placeholder' => 'localhost'),
$prefix . 'port' => array('type' => 'text', 'size' => 5, 'placeholder' => 587),
);
}
function on_identity_form($args)
{
$rc = rcmail::get_instance();
// Do not show options for default identity
if (strcasecmp($args['record']['email'], $rc->user->data['username']) === 0)
return $args;
return $args;
$this->add_texts('localization');
// Load data if exists
$row = null;
if (isset($args['record']['identity_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);
$r = $rc->db->fetch_assoc($q);
if ($r)
{
foreach ($r as $k => $v)
$args['record']['ident_switch.form.' . $k] = $v;
// Parse flags
if ($r['flags'] & self::DB_ENABLED)
$args['record']['ident_switch.form.enabled'] = true;
if ($r['flags'] & self::DB_SECURE_TLS) // TLS has priority
$args['record']['ident_switch.form.secure'] = 'tls';
elseif ($r['flags'] & self::DB_SECURE_SSL)
$args['record']['ident_switch.form.secure'] = 'ssl';
// Set readonly if needed
$cfg = $this->get_preconfig($args['record']['email']);
if (is_array($cfg) && $cfg['readonly'])
{
$args['record']['ident_switch.form.readonly'] = 1;
if (in_array(strtoupper($cfg['user']), array('EMAIL', 'MBOX')))
$args['record']['ident_switch.form.readonly'] = 2;
}
}
else
$this->apply_preconfig($args['record']);
$row = $rc->db->fetch_assoc($q);
}
// 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'),
);
$record = &$args['record'];
// Process fields
$addAfter = '';
$table = new html_table(array('cols' => 2));
foreach ($fieldset as $col => $colprop)
// Load data if exists
if ($row)
{
$data = $args['record'][$col];
if ($colprop['type'] == 'hidden')
{
$addAfter .= rcube_output::get_edit_field($col, $data, $colprop, $colprop['type']);
}
else
{
$colprop['id'] = 'rcmfd_' . $col;
$dbToForm = array(
'label' => 'common.label',
'imap_host' => 'imap.host',
'imap_port' => 'imap.port',
'username' => 'imap.username',
'password' => 'imap.password',
'smtp_host' => 'smtp.host',
'smtp_port' => 'smtp.port'
$label = $colprop['label'] ?: $this->gettext(str_replace('-', '', $col));
$value = $colprop['value'] ?: rcube_output::get_edit_field($col, $data, $colprop, $colprop['type']);
);
foreach ($row as $k => $v)
$record['ident_switch.form.' . $dbToForm[$k]] = $v;
$table->add('title', html::label($colprop['id'], rcube::Q($label)));
$table->add(null, $value);
// Parse flags
$record['ident_switch.form.common.enabled'] = !!($row['flags'] & self::DB_ENABLED);
$record['ident_switch.form.imap.tls'] = !!($row['flags'] & self::DB_SECURE_IMAP_TLS);
// Set readonly if needed
$cfg = $this->get_preconfig($record['email']);
if (is_array($cfg) && $cfg['readonly'])
{
$record['ident_switch.form.common.readonly'] = 1;
if (in_array(strtoupper($cfg['user']), array('EMAIL', 'MBOX')))
$record['ident_switch.form.common.readonly'] = 2;
}
}
else
$this->apply_preconfig($record);
// 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
$args['form']['ident_switch.common'] = array(
'name' => $this->gettext('form.common.caption'),
'content' => ident_switch::get_common_form($record)
);
$args['form']['ident_switch.imap'] = array(
'name' => $this->gettext('form.imap.caption'),
'content' => ident_switch::get_imap_form($record)
);
$args['form']['ident_switch.smtp'] = array(
'name' => $this->gettext('form.smtp.caption'),
'content' => ident_switch::get_smtp_form($record)
);
return $args;
@@ -277,10 +297,9 @@ class ident_switch extends rcube_plugin
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))
if (!self::get_field_value('common', 'enabled', false))
{
self::sw_imap_off($args['iid']);
self::sw_imap_off($args['id']);
return $args;
}
@@ -307,8 +326,7 @@ class ident_switch extends rcube_plugin
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))
if (!self::get_field_value('common', 'enabled', false))
return $args;
$data = self::check_field_values();
@@ -375,37 +393,49 @@ class ident_switch extends rcube_plugin
}
}
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));
$retVal['label'] = self::get_field_value('common', 'label');
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['imap.host'] = self::get_field_value('imap', 'host');
if (strlen($retVal['imap.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['imap.port'] = self::get_field_value('imap', 'port');
if ($retVal['imap.port'] && !ctype_digit($retVal['imap.port']))
$retVal['err'] = 'port.num';
else
{
if ($retVal['port'] && ($retVal['port'] <= 0 || $retVal['port'] > 65535))
if ($retVal['imap.port'] && ($retVal['imap.port'] <= 0 || $retVal['imap.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['imap.user'] = self::get_field_value('imap', 'username');
if (strlen($retVal['imap.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';
$retVal['smtp.host'] = self::get_field_value('smtp', 'host');
if (strlen($retVal['smtp.host']) > 64)
$retVal['err'] = 'host.long';
else
{
$retVal['smtp.port'] = self::get_field_value('smtp', 'port');
if ($retVal['smtp.port'] && !ctype_digit($retVal['smtp.port']))
$retVal['err'] = 'port.num';
else
{
if ($retVal['smtp.port'] && ($retVal['smtp.port'] <= 0 || $retVal['smtp.port'] > 65535))
$retVal['err'] = 'port.range';
}
}
}
}
}
@@ -413,19 +443,29 @@ class ident_switch extends rcube_plugin
}
// Get also password
$retVal['pass'] = rcube_utils::get_input_value('_ident_switch_form_password', rcube_utils::INPUT_POST);
$retVal['imap.pass'] = self::get_field_value('imap', 'password', false);
// 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;
$tls = self::get_field_value('imap', 'tls', false);
if ($tls)
$retVal['flags'] |= self::DB_SECURE_IMAP_TLS;
return $retVal;
}
private static function get_field_value($section, $field, $trim = true)
{
$retVal = rcube_utils::get_input_value(
'_ident_switch_form_' . $section . '_' . $field,
rcube_utils::INPUT_POST
);
if (!$trim)
return $retVal;
return self::ntrim($retVal);
}
private static function save_field_values($rc, $data)
{
@@ -436,31 +476,32 @@ class ident_switch extends rcube_plugin
{ // 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 = ?' .
' SET flags = ?, label = ?, imap_host = ?, imap_port = ?, username = ?, password = ?, smtp_host = ?, smtp_port = ?, 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 (?, ?, ?, ?, ?, ?, ?, ?, ?)';
'(flags, label, imap_host, imap_port, username, password, smtp_host, smtp_port, user_id, iid) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
}
if ($sql)
{
// Do we need to update pwd?
if ($data['pass'] != $r['password'])
$data['pass'] = $rc->encrypt($data['pass']);
if ($data['imap.pass'] != $r['password'])
$data['imap.pass'] = $rc->encrypt($data['imap.pass']);
$rc->db->query(
$sql,
$data['flags'],
$data['label'],
$data['host'],
$data['port'],
$data['user'],
$data['pass'],
$data['delim'],
$data['imap.host'],
$data['imap.port'],
$data['imap.user'],
$data['imap.pass'],
$data['smtp.host'],
$data['smtp.port'],
$rc->user->ID,
$data['id'],
$r['id']
@@ -499,7 +540,7 @@ class ident_switch extends rcube_plugin
}
else
{
$sql = 'SELECT host, flags, port, username, password, iid FROM ' . $rc->db->table_name(self::TABLE) . ' WHERE id = ? AND user_id = ?';
$sql = 'SELECT imap_host, flags, imap_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);
$r = $rc->db->fetch_assoc($q);
if (is_array($r))
@@ -515,22 +556,14 @@ class ident_switch extends rcube_plugin
self::write_log('Switching mailbox to one for identity with ID = ' . $r['iid'] . ' (username = \'' . $r['username'] . '\').');
$def_port = 143; // Default port here!
$def_port = 143; // Default IMAP port here!
$ssl = null;
if ($r['flags'] & self::DB_SECURE_TLS)
if ($r['flags'] & self::DB_SECURE_IMAP_TLS)
{
$ssl = 'tls';
$def_port = 143; // Default TLS port here!
$def_port = 143; // Default IMAP TLS port here!
}
elseif ($r['flags'] & self::DB_SECURE_SSL)
{
$ssl = 'ssl';
$def_port = 993; // Default SSL port here!
}
$port = $r['port'];
if (!$port)
$port = $def_port;
$port = $r['imap_port'] ? $r['imap_port'] : $def_port;
// If we are in default account now
// save everything with STORAGE
@@ -549,7 +582,7 @@ class ident_switch extends rcube_plugin
if (!$_SESSION['password' . self::MY_POSTFIX])
$_SESSION['password' . self::MY_POSTFIX] = $_SESSION['password'];
$_SESSION['storage_host'] = $r['host'] ? $r['host'] : 'localhost'; // Default host here!
$_SESSION['storage_host'] = $r['imap_host'] ? $r['imap_host'] : 'localhost'; // Default IMAP host here!
$_SESSION['storage_ssl'] = $ssl;
$_SESSION['storage_port'] = $port;
$_SESSION['username'] = $r['username'];
@@ -613,15 +646,13 @@ class ident_switch extends rcube_plugin
{ // Parse and set host and related
$urlArr = parse_url($cfg['host']);
$record['ident_switch.form.host'] = $urlArr['host'] ? rcube::Q($urlArr['host'], 'url') : '';
$record['ident_switch.form.port'] = $urlArr['port'] ? intval($urlArr['port']) : '';
$record['ident_switch.form.imap.host'] = $urlArr['host'] ? rcube::Q($urlArr['host'], 'url') : '';
$record['ident_switch.form.imap.port'] = $urlArr['port'] ? intval($urlArr['port']) : '';
if (strcasecmp('tls', $urlArr['scheme']) === 0)
$record['ident_switch.form.secure'] = 'tls';
elseif (strcasecmp('ssl', $urlArr['scheme']) === 0)
$record['ident_switch.form.secure'] = 'ssl';
$record['ident_switch.form.imap.tls'] = true;
else
$record['ident_switch.form.secure'] = '';
$record['ident_switch.form.imap.rls'] = false;
}
$loginSet = false;
@@ -630,11 +661,11 @@ class ident_switch extends rcube_plugin
switch (strtoupper($cfg['user']))
{
case 'EMAIL':
$record['ident_switch.form.username'] = $email;
$record['ident_switch.form.imap.username'] = $email;
$loginSet = true;
break;
case 'MBOX':
$record['ident_switch.form.username'] = strstr($email, '@', true);
$record['ident_switch.form.imap.username'] = strstr($email, '@', true);
$loginSet = true;
break;
}
@@ -642,13 +673,15 @@ class ident_switch extends rcube_plugin
if ($cfg['readonly'])
{
$record['ident_switch.form.readonly'] = 1;
$record['ident_switch.form.common.readonly'] = 1;
if ($loginSet)
$record['ident_switch.form.readonly'] = 2;
$record['ident_switch.form.common.readonly'] = 2;
}
return $cfg['readonly'];
}
return false;
}
private static function ntrim($str)

View File

@@ -4,47 +4,64 @@
*/
$labels = array();
// IMAP
$labels['form.caption'] = 'IMAP';
// Plugin ident_switch
$labels['form.common.caption'] = 'Plugin ident_switch';
// Enabled
$labels['form.enabled'] = 'Aktiviert';
$labels['form.common.enabled'] = 'Aktiviert';
// Label
$labels['form.label'] = 'Bezeichnung';
$labels['form.common.label'] = 'Bezeichnung';
// Value in \'Label\' field is too long (32 chars max).
$labels['err.label.long'] = 'Der Wert in Feld \'Bezeichnung\' ist zu lang (max. 32 Zeichen).';
// IMAP
$labels['form.imap.caption'] = 'IMAP';
// Server host name
$labels['form.host']='Servername';
$labels['form.imap.host'] = 'Servername';
// Secure connection (SSL/TLS)
$labels['form.secure']='Verbindungssicherheit';
// Secure connection (TLS)
$labels['form.imap.tls'] = 'Sichere Verbindung (TLS)';
// Port
$labels['form.port']='Port';
$labels['form.imap.port'] = 'Port';
// Username
$labels['form.username'] = 'Benutzername';
$labels['form.imap.username'] = 'Benutzername';
// Password
$labels['form.password'] = 'Passwort';
$labels['form.imap.password'] = 'Passwort';
// Folder hierarchy delimiter
$labels['form.delimiter'] = 'Hierachietrennzeichen für Verzeichnisse';
// Value in \'Username\' field is too long (64 chars max).
$labels['err.user.long'] = 'Der Wert in Feld \'Benutzername\' ist zu lang (max. 64 Zeichen).';
// Value in \'Label\' field of IMAP section is too long (32 chars max).
$labels['err.label.long'] = 'Der Wert in Feld \'Bezeichnung\' im Abschnitt IMAP ist zu lang (max. 32 Zeichen).';
// Value in \'Server host name\' field of IMAP section is too long (64 chars max).
$labels['err.host.long'] = 'Der Wert in Feld \'Servername\' im Abschnitt IMAP ist zu lang (max. 64 Zeichen).';
// SMTP
$labels['form.smtp.caption'] = 'SMTP';
// Value in \'Username\' field of IMAP section is too long (64 chars max).
$labels['err.user.long'] = 'Der Wert in Feld \'Benutzername\' im Abschnitt IMAP ist zu lang (max. 64 Zeichen).';
// Server host name
$labels['form.smtp.host'] = 'Servername';
// Value in \'Folder hierarchy delimiter\' field of IMAP section is too long (1 char max).
$labels['err.delim.long'] = 'Der Wert in Feld \'Hierachietrennzeichen für Verzeichnisse\' im Abschnitt IMAP ist zu lang (max. 1 Zeichen).';
// Secure connection (TLS)
$labels['form.smtp.tls'] = 'Sichere Verbindung (TLS)';
// Value in \'Port\' field of IMAP section must be a number.
$labels['err.port.num'] = 'Der Wert in Feld \'Port\' im Abschnitt IMAP muss eine Zahl sein.';
// Port
$labels['form.smtp.port'] = 'Port';
// Value in \'Port\' field of IMAP section must be between 1 and 65535.
$labels['err.port.range'] = 'Der Wert in Feld \'Port\' im Abschnitt IMAP muss 1 und 65535 liegen.';
// Authorization required
$labels['form.smtp.auth'] = 'Genehmigung benötigt';
// Errors
// Value in \'Server host name\' field is too long (64 chars max).
$labels['err.host.long'] = 'Der Wert in Feld \'Servername\' ist zu lang (max. 64 Zeichen).';
// Value in \'Port\' field must be a number.
$labels['err.port.num'] = 'Der Wert in Feld \'Port\' muss eine Zahl sein.';
// Value in \'Port\' field must be between 1 and 65535.
$labels['err.port.range'] = 'Der Wert in Feld \'Port\' muss 1 und 65535 liegen.';

View File

@@ -4,47 +4,64 @@
*/
$labels = array();
// IMAP
$labels['form.caption'] = 'IMAP';
// Plugin ident_switch
$labels['form.common.caption'] = 'Plugin ident_switch';
// Enabled
$labels['form.enabled'] = 'Enabled';
$labels['form.common.enabled'] = 'Enabled';
// Label
$labels['form.label'] = 'Label';
$labels['form.common.label'] = 'Label';
// Value in \'Label\' field is too long (32 chars max).
$labels['err.label.long'] = 'Value in \'Label\' field is too long (32 chars max).';
// IMAP
$labels['form.imap.caption'] = 'IMAP';
// Server host name
$labels['form.host']='Server host name';
$labels['form.imap.host'] = 'Server host name';
// Secure connection (SSL/TLS)
$labels['form.secure']='Connection security';
// Secure connection (TLS)
$labels['form.imap.tls'] = 'Secure connection (TLS)';
// Port
$labels['form.port']='Port';
$labels['form.imap.port'] = 'Port';
// Username
$labels['form.username'] = 'Username';
$labels['form.imap.username'] = 'Username';
// Password
$labels['form.password'] = 'Password';
$labels['form.imap.password'] = 'Password';
// Folder hierarchy delimiter
$labels['form.delimiter'] = 'Folder hierarchy delimiter';
// Value in \'Username\' field is too long (64 chars max).
$labels['err.user.long'] = 'Value in \'Username\' field is too long (64 chars max).';
// Value in \'Label\' field of IMAP section is too long (32 chars max).
$labels['err.label.long'] = 'Value in \'Label\' field of IMAP section is too long (32 chars max).';
// Value in \'Server host name\' field of IMAP section is too long (64 chars max).
$labels['err.host.long'] = 'Value in \'Server host name\' field of IMAP section is too long (64 chars max).';
// SMTP
$labels['form.smtp.caption'] = 'SMTP';
// Value in \'Username\' field of IMAP section is too long (64 chars max).
$labels['err.user.long'] = 'Value in \'Username\' field of IMAP section is too long (64 chars max).';
// Server host name
$labels['form.smtp.host'] = 'Server host name';
// Value in \'Folder hierarchy delimiter\' field of IMAP section is too long (1 char max).
$labels['err.delim.long'] = 'Value in \'Folder hierarchy delimiter\' field of IMAP section is too long (1 char max).';
// Secure connection (TLS)
$labels['form.smtp.tls'] = 'Secure connection (TLS)';
// Value in \'Port\' field of IMAP section must be a number.
$labels['err.port.num'] = 'Value in \'Port\' field of IMAP section must be a number.';
// Port
$labels['form.smtp.port'] = 'Port';
// Value in \'Port\' field of IMAP section must be between 1 and 65535.
$labels['err.port.range'] = 'Value in \'Port\' field of IMAP section must be between 1 and 65535.';
// Authorization required
$labels['form.smtp.auth'] = 'Authorization required';
// Errors
// Value in \'Server host name\' field is too long (64 chars max).
$labels['err.host.long'] = 'Value in \'Server host name\' field is too long (64 chars max).';
// Value in \'Port\' field must be a number.
$labels['err.port.num'] = 'Value in \'Port\' field must be a number.';
// Value in \'Port\' field must be between 1 and 65535.
$labels['err.port.range'] = 'Value in \'Port\' field must be between 1 and 65535.';

View File

@@ -4,47 +4,64 @@
*/
$labels = array();
// IMAP
$labels['form.caption'] = 'IMAP';
// Plugin ident_switch
$labels['form.common.caption'] = 'Плагин ident_switch';
// Enabled
$labels['form.enabled'] = 'Включено';
$labels['form.common.enabled'] = 'Включено';
// Label
$labels['form.label'] = 'Название';
$labels['form.common.label'] = 'Название';
// Value in \'Label\' field is too long (32 chars max).
$labels['err.label.long'] = '\'Название\' должно быть не длинее 32 символов.';
// IMAP
$labels['form.imap.caption'] = 'IMAP';
// Server host name
$labels['form.host'] = 'Адрес сервера';
$labels['form.imap.host'] = 'Адрес сервера';
// Secure connection (SSL/TLS)
$labels['form.secure'] = 'Защита подключения';
// Secure connection (TLS)
$labels['form.imap.tls'] = 'Безопасное подключение (TLS)';
// Port
$labels['form.port'] = 'Порт';
$labels['form.imap.port'] = 'Порт';
// Username
$labels['form.username'] = 'Имя пользователя';
$labels['form.imap.username'] = 'Имя пользователя';
// Password
$labels['form.password'] = 'Пароль';
$labels['form.imap.password'] = 'Пароль';
// Folder hierarchy delimiter
$labels['form.delimiter'] = 'Разделитель в иерархии папок';
// Value in \'Username\' field is too long (64 chars max).
$labels['err.user.long'] = '\'Имя пользователя\' должно быть не длинее 64 символов.';
// Value in \'Label\' field of IMAP section is too long (32 chars max).
$labels['err.label.long'] = '\'Название\' в разделе IMAP должно быть не длинее 32 символов.';
// Value in \'Server host name\' field of IMAP section is too long (64 chars max).
$labels['err.host.long'] = '\'Адрес сервера\' в разделе IMAP должен быть не длинее 64 символов.';
// SMTP
$labels['form.smtp.caption'] = 'SMTP';
// Value in \'Username\' field of IMAP section is too long (64 chars max).
$labels['err.user.long'] = '\'Имя пользователя\' в секции IMAP должно быть не длинее 64 символов.';
// Server host name
$labels['form.smtp.host'] = 'Адрес сервера';
// Value in \'Folder hierarchy delimiter\' field of IMAP section is too long (1 char max).
$labels['err.delim.long'] = '\'Разделитель в иерархии папок\' в секции IMAP должен быть не длинее 1 символа.';
// Secure connection (TLS)
$labels['form.smtp.tls'] = 'Безопасное подключение (TLS)';
// Value in \'Port\' field of IMAP section must be a number.
$labels['err.port.num'] = '\'Порт\' в секции IMAP должен быть числом.';
// Port
$labels['form.smtp.port'] = 'Порт';
// Value in \'Port\' field of IMAP section must be between 1 and 65535.
$labels['err.port.range'] = '\'Порт\' в секции IMAP должен быть в диапазоне от 1 до 65535.';
// Authorization required
$labels['form.smtp.auth'] = 'Требуется авторизация';
// Errors
// Value in \'Server host name\' field is too long (64 chars max).
$labels['err.host.long'] = '\'Адрес сервера\' должен быть не длинее 64 символов.';
// Value in \'Port\' field must be a number.
$labels['err.port.num'] = '\'Порт\' должен быть числом.';
// Value in \'Port\' field must be between 1 and 65535.
$labels['err.port.range'] = '\'Порт\' должен быть в диапазоне от 1 до 65535.';