@@ -16,19 +16,22 @@ CREATE TABLE ident_switch
|
|||||||
varchar(64),
|
varchar(64),
|
||||||
password
|
password
|
||||||
varchar(64),
|
varchar(64),
|
||||||
host
|
imap_host
|
||||||
varchar(64),
|
varchar(64),
|
||||||
port
|
imap_port
|
||||||
integer
|
integer
|
||||||
CHECK(port > 0 AND port <= 65535),
|
CHECK(port > 0 AND port <= 65535),
|
||||||
delimiter
|
|
||||||
char(1),
|
|
||||||
label
|
label
|
||||||
varchar(32),
|
varchar(32),
|
||||||
flags
|
flags
|
||||||
integer
|
integer
|
||||||
NOT NULL
|
NOT NULL
|
||||||
DEFAULT(0),
|
DEFAULT(0),
|
||||||
|
smtp_host
|
||||||
|
varchar(64),
|
||||||
|
smtp_port
|
||||||
|
integer
|
||||||
|
CHECK(port > 0 AND port <= 65535),
|
||||||
UNIQUE (user_id, label)
|
UNIQUE (user_id, label)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
31
SQL/postgres/2018121800.sql
Normal file
31
SQL/postgres/2018121800.sql
Normal 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;
|
||||||
@@ -19,8 +19,9 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.3.0",
|
"php": ">=5.3.0",
|
||||||
"roundcube/plugin-installer": ">=0.1.3"
|
"roundcube/plugin-installer": ">=0.1.3",
|
||||||
|
"ext-ctype": "*"
|
||||||
},
|
},
|
||||||
"conflict": {
|
"conflict": {
|
||||||
"elm/identity_smtp": "*"
|
"elm/identity_smtp": "*"
|
||||||
|
|||||||
@@ -3,39 +3,33 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
$("INPUT[name='_ident_switch.form.enabled']").change();
|
$("INPUT[name='_ident_switch.form.common.enabled']").change();
|
||||||
$("SELECT[name='_ident_switch.form.secure']").change();
|
|
||||||
plugin_switchIdent_processPreconfig();
|
plugin_switchIdent_processPreconfig();
|
||||||
});
|
});
|
||||||
|
|
||||||
function plugin_switchIdent_processPreconfig() {
|
function plugin_switchIdent_processPreconfig() {
|
||||||
var disFld = $("INPUT[name='_ident_switch.form.readonly']");
|
var disFld = $("INPUT[name='_ident_switch.form.common.readonly']");
|
||||||
disFld.parentsUntil("TABLE", "TR").hide();
|
disFld.parentsUntil("TABLE", "TR").hide();
|
||||||
|
|
||||||
var disVal = disFld.val();
|
var disVal = disFld.val();
|
||||||
if (disVal > 0) {
|
if (disVal > 0) {
|
||||||
$("INPUT[name='_ident_switch.form.host']").prop("disabled", true);
|
$("INPUT[name='_ident_switch.form.imap.host']").prop("disabled", true);
|
||||||
$("SELECT[name='_ident_switch.form.secure']").prop("disabled", true);
|
$("SELECT[name='_ident_switch.form.imap.tls']").prop("disabled", true);
|
||||||
$("INPUT[name='_ident_switch.form.port']").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) {
|
if (2 == disVal) {
|
||||||
$("INPUT[name='_ident_switch.form.username']").prop("disabled", true);
|
$("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) {
|
function plugin_switchIdent_enabled_onChange(e) {
|
||||||
var $enFld = $("INPUT[name='_ident_switch.form.enabled']");
|
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.enabled'], SELECT", $enFld.parents("FIELDSET")).prop("disabled", !$enFld.is(":checked"));
|
$("INPUT[name!='_ident_switch.form.common.enabled']", $enFld.parents("FIELDSET")).prop("disabled", !$enFld.is(":checked"));
|
||||||
plugin_switchIdent_processPreconfig();
|
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);
|
|
||||||
}
|
}
|
||||||
2
ident_switch-form.min.js
vendored
2
ident_switch-form.min.js
vendored
@@ -1 +1 @@
|
|||||||
$(function(){$("INPUT[name='_ident_switch.form.enabled']").change();$("SELECT[name='_ident_switch.form.secure']").change();plugin_switchIdent_processPreconfig()});function plugin_switchIdent_processPreconfig(){var a=$("INPUT[name='_ident_switch.form.readonly']");a.parentsUntil("TABLE","TR").hide();var b=a.val();if(b>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==b){$("INPUT[name='_ident_switch.form.username']").prop("disabled",true)}}function plugin_switchIdent_enabled_onChange(a){var b=$("INPUT[name='_ident_switch.form.enabled']");$("INPUT[name!='_ident_switch.form.enabled'], SELECT",b.parents("FIELDSET")).prop("disabled",!b.is(":checked"));plugin_switchIdent_processPreconfig()}function plugin_switchIdent_secure_onChange(c){var b=$("SELECT[name='_ident_switch.form.secure']");var a=$("INPUT[name='_ident_switch.form.port']");if("SSL"===b.val().toUpperCase()){a.attr("placeholder",993)}else{a.attr("placeholder",143)}};
|
$(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()};
|
||||||
277
ident_switch.php
277
ident_switch.php
@@ -16,9 +16,9 @@ class ident_switch extends rcube_plugin
|
|||||||
const MY_POSTFIX = '_iswitch';
|
const MY_POSTFIX = '_iswitch';
|
||||||
|
|
||||||
// Flags user in database
|
// Flags user in database
|
||||||
const DB_ENABLED = 1;
|
const DB_ENABLED = 1;
|
||||||
const DB_SECURE_SSL = 2;
|
//const DB_SECURE_SSL = 2; // Not supported any more
|
||||||
const DB_SECURE_TLS = 4;
|
const DB_SECURE_IMAP_TLS = 4;
|
||||||
|
|
||||||
function init()
|
function init()
|
||||||
{
|
{
|
||||||
@@ -62,6 +62,7 @@ class ident_switch extends rcube_plugin
|
|||||||
{
|
{
|
||||||
case 'mail':
|
case 'mail':
|
||||||
$this->render_switch($rc, $args);
|
$this->render_switch($rc, $args);
|
||||||
|
break;
|
||||||
case 'settings':
|
case 'settings':
|
||||||
$this->include_script('ident_switch-form.js');
|
$this->include_script('ident_switch-form.js');
|
||||||
break;
|
break;
|
||||||
@@ -156,7 +157,7 @@ class ident_switch extends rcube_plugin
|
|||||||
|
|
||||||
$rc = rcmail::get_instance();
|
$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);
|
$q = $rc->db->query($sql, $iid ,$rc->user->ID);
|
||||||
$r = $rc->db->fetch_assoc($q);
|
$r = $rc->db->fetch_assoc($q);
|
||||||
if (is_array($r))
|
if (is_array($r))
|
||||||
@@ -164,106 +165,117 @@ class ident_switch extends rcube_plugin
|
|||||||
if (!$r['username'])
|
if (!$r['username'])
|
||||||
{ // Load email from identity
|
{ // Load email from identity
|
||||||
$sql = 'SELECT email FROM ' . $rc->db->table_name('identities') . ' WHERE identity_id = ?';
|
$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);
|
$rIid = $rc->db->fetch_assoc($q);
|
||||||
|
|
||||||
$r['username'] = $rIid['email'];
|
$r['username'] = $rIid['email'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exactly the same in core SMTP handler
|
$args['smtp_user'] = $r['username'];
|
||||||
$args['smtp_user'] = str_replace('%u', $r['username'], $args['smtp_user']);
|
$args['smtp_pass'] = $rc->decrypt($r['password']);
|
||||||
$args['smtp_pass'] = str_replace('%p', $rc->decrypt($r['password']), $args['smtp_pass']);
|
$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
|
||||||
|
|
||||||
|
self::write_log(print_r($args, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $args;
|
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)
|
function on_identity_form($args)
|
||||||
{
|
{
|
||||||
$rc = rcmail::get_instance();
|
$rc = rcmail::get_instance();
|
||||||
|
|
||||||
// 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');
|
||||||
|
|
||||||
// Load data if exists
|
$row = null;
|
||||||
if (isset($args['record']['identity_id']))
|
if (isset($args['record']['identity_id']))
|
||||||
{
|
{
|
||||||
$sql = 'SELECT * FROM ' . $rc->db->table_name(self::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);
|
$row = $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']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create our field set
|
$record = &$args['record'];
|
||||||
// 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
|
// Load data if exists
|
||||||
$addAfter = '';
|
if ($row)
|
||||||
$table = new html_table(array('cols' => 2));
|
|
||||||
foreach ($fieldset as $col => $colprop)
|
|
||||||
{
|
{
|
||||||
$data = $args['record'][$col];
|
$dbToForm = array(
|
||||||
if ($colprop['type'] == 'hidden')
|
'label' => 'common.label',
|
||||||
{
|
'imap_host' => 'imap.host',
|
||||||
$addAfter .= rcube_output::get_edit_field($col, $data, $colprop, $colprop['type']);
|
'imap_port' => 'imap.port',
|
||||||
}
|
'username' => 'imap.username',
|
||||||
else
|
'password' => 'imap.password',
|
||||||
{
|
'smtp_host' => 'smtp.host',
|
||||||
$colprop['id'] = 'rcmfd_' . $col;
|
'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)));
|
// Parse flags
|
||||||
$table->add(null, $value);
|
$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.common'] = array(
|
||||||
$args['form']['ident_switch'] = array(
|
'name' => $this->gettext('form.common.caption'),
|
||||||
'name' => $this->gettext('form.caption'),
|
'content' => ident_switch::get_common_form($record)
|
||||||
'content' => $table->show(array('class' => 'propform')) . $addAfter // TODO: copy styles from other tables
|
);
|
||||||
|
$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;
|
return $args;
|
||||||
@@ -277,8 +289,7 @@ class ident_switch extends rcube_plugin
|
|||||||
if (strcasecmp($args['record']['email'], $rc->user->data['username']) === 0)
|
if (strcasecmp($args['record']['email'], $rc->user->data['username']) === 0)
|
||||||
return $args;
|
return $args;
|
||||||
|
|
||||||
// Process boolean fields
|
if (!self::get_field_value('common', 'enabled', false))
|
||||||
if (!rcube_utils::get_input_value('_ident_switch_form_enabled', rcube_utils::INPUT_POST))
|
|
||||||
{
|
{
|
||||||
self::sw_imap_off($args['id']);
|
self::sw_imap_off($args['id']);
|
||||||
return $args;
|
return $args;
|
||||||
@@ -307,8 +318,7 @@ class ident_switch extends rcube_plugin
|
|||||||
if (strcasecmp($args['record']['email'], $rc->user->data['username']) === 0)
|
if (strcasecmp($args['record']['email'], $rc->user->data['username']) === 0)
|
||||||
return $args;
|
return $args;
|
||||||
|
|
||||||
// Process boolean fields
|
if (!self::get_field_value('common', 'enabled', false))
|
||||||
if (!rcube_utils::get_input_value('_ident_switch_form_enabled', rcube_utils::INPUT_POST))
|
|
||||||
return $args;
|
return $args;
|
||||||
|
|
||||||
$data = self::check_field_values();
|
$data = self::check_field_values();
|
||||||
@@ -375,37 +385,49 @@ class ident_switch extends rcube_plugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static function check_field_values()
|
private static function check_field_values()
|
||||||
{
|
{
|
||||||
$retVal = array();
|
$retVal = array();
|
||||||
|
|
||||||
$retVal['label'] = self::ntrim(rcube_utils::get_input_value('_ident_switch_form_label', rcube_utils::INPUT_POST));
|
$retVal['common.label'] = self::get_field_value('common', 'label');
|
||||||
if (strlen($retVal['label']) > 32)
|
if (strlen($retVal['common.label']) > 32)
|
||||||
$retVal['err'] = 'label.long';
|
$retVal['err'] = 'label.long';
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$retVal['host'] = self::ntrim(rcube_utils::get_input_value('_ident_switch_form_host', rcube_utils::INPUT_POST));
|
$retVal['imap.host'] = self::get_field_value('imap', 'host');
|
||||||
if (strlen($retVal['host']) > 64)
|
if (strlen($retVal['imap.host']) > 64)
|
||||||
$retVal['err'] = 'host.long';
|
$retVal['err'] = 'host.long';
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$retVal['port'] = self::ntrim(rcube_utils::get_input_value('_ident_switch_form_port', rcube_utils::INPUT_POST));
|
$retVal['imap.port'] = self::get_field_value('imap', 'port');
|
||||||
if ($retVal['port'] && !ctype_digit($retVal['port']))
|
if ($retVal['imap.port'] && !ctype_digit($retVal['imap.port']))
|
||||||
$retVal['err'] = 'port.num';
|
$retVal['err'] = 'port.num';
|
||||||
else
|
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';
|
$retVal['err'] = 'port.range';
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$retVal['user'] = self::ntrim(rcube_utils::get_input_value('_ident_switch_form_username', rcube_utils::INPUT_POST));
|
$retVal['imap.user'] = self::get_field_value('imap', 'username');
|
||||||
if (strlen($retVal['user']) > 64)
|
if (strlen($retVal['imap.user']) > 64)
|
||||||
$retVal['err'] = 'user.long';
|
$retVal['err'] = 'user.long';
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$retVal['delim'] = self::ntrim(rcube_utils::get_input_value('_ident_switch_form_delimiter', rcube_utils::INPUT_POST));
|
$retVal['smtp.host'] = self::get_field_value('smtp', 'host');
|
||||||
if (strlen($retVal['delim']) > 1)
|
if (strlen($retVal['smtp.host']) > 64)
|
||||||
$retVal['err'] = 'delim.long';
|
$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 +435,29 @@ class ident_switch extends rcube_plugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get also password
|
// 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
|
// Parse secure settings
|
||||||
$retVal['flags'] = self::DB_ENABLED;
|
$retVal['flags'] = self::DB_ENABLED;
|
||||||
$ssl = rcube_utils::get_input_value('_ident_switch_form_secure', rcube_utils::INPUT_POST);
|
|
||||||
if (strcasecmp($ssl, 'tls') === 0)
|
$tls = self::get_field_value('imap', 'tls', false);
|
||||||
$retVal['flags'] |= self::DB_SECURE_TLS;
|
if ($tls)
|
||||||
elseif (strcasecmp($ssl, 'ssl') === 0)
|
$retVal['flags'] |= self::DB_SECURE_IMAP_TLS;
|
||||||
$retVal['flags'] |= self::DB_SECURE_SSL;
|
|
||||||
|
|
||||||
return $retVal;
|
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)
|
private static function save_field_values($rc, $data)
|
||||||
{
|
{
|
||||||
@@ -436,14 +468,14 @@ class ident_switch extends rcube_plugin
|
|||||||
{ // Record already exists, will update it
|
{ // Record already exists, will update it
|
||||||
$sql = 'UPDATE ' .
|
$sql = 'UPDATE ' .
|
||||||
$rc->db->table_name(self::TABLE) .
|
$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 = ?';
|
' WHERE id = ?';
|
||||||
}
|
}
|
||||||
else if ($data['flags'] & self::DB_ENABLED)
|
else if ($data['flags'] & self::DB_ENABLED)
|
||||||
{ // No record exists, create new one
|
{ // No record exists, create new one
|
||||||
$sql = 'INSERT INTO ' .
|
$sql = 'INSERT INTO ' .
|
||||||
$rc->db->table_name(self::TABLE) .
|
$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)
|
if ($sql)
|
||||||
@@ -456,11 +488,12 @@ class ident_switch extends rcube_plugin
|
|||||||
$sql,
|
$sql,
|
||||||
$data['flags'],
|
$data['flags'],
|
||||||
$data['label'],
|
$data['label'],
|
||||||
$data['host'],
|
$data['imap.host'],
|
||||||
$data['port'],
|
$data['imap.port'],
|
||||||
$data['user'],
|
$data['imap.user'],
|
||||||
$data['pass'],
|
$data['imap.pass'],
|
||||||
$data['delim'],
|
$data['smtp.host'],
|
||||||
|
$data['smtp.port'],
|
||||||
$rc->user->ID,
|
$rc->user->ID,
|
||||||
$data['id'],
|
$data['id'],
|
||||||
$r['id']
|
$r['id']
|
||||||
@@ -499,7 +532,7 @@ class ident_switch extends rcube_plugin
|
|||||||
}
|
}
|
||||||
else
|
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);
|
$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))
|
||||||
@@ -515,22 +548,14 @@ class ident_switch extends rcube_plugin
|
|||||||
|
|
||||||
self::write_log('Switching mailbox to one for identity with ID = ' . $r['iid'] . ' (username = \'' . $r['username'] . '\').');
|
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;
|
$ssl = null;
|
||||||
if ($r['flags'] & self::DB_SECURE_TLS)
|
if ($r['flags'] & self::DB_SECURE_IMAP_TLS)
|
||||||
{
|
{
|
||||||
$ssl = '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)
|
$port = $r['imap_port'] ? $r['imap_port'] : $def_port;
|
||||||
{
|
|
||||||
$ssl = 'ssl';
|
|
||||||
$def_port = 993; // Default SSL port here!
|
|
||||||
}
|
|
||||||
|
|
||||||
$port = $r['port'];
|
|
||||||
if (!$port)
|
|
||||||
$port = $def_port;
|
|
||||||
|
|
||||||
// If we are in default account now
|
// If we are in default account now
|
||||||
// save everything with STORAGE
|
// save everything with STORAGE
|
||||||
@@ -549,7 +574,7 @@ class ident_switch extends rcube_plugin
|
|||||||
if (!$_SESSION['password' . self::MY_POSTFIX])
|
if (!$_SESSION['password' . self::MY_POSTFIX])
|
||||||
$_SESSION['password' . self::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['imap_host'] ? $r['imap_host'] : 'localhost'; // Default IMAP 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'];
|
||||||
@@ -577,7 +602,7 @@ class ident_switch extends rcube_plugin
|
|||||||
private static 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(self::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, ~self::DB_ENABLED, $iid, $rc->user->ID);
|
$rc->db->query($sql, ~self::DB_ENABLED, $iid, $rc->user->ID);
|
||||||
}
|
}
|
||||||
@@ -613,15 +638,13 @@ class ident_switch extends rcube_plugin
|
|||||||
{ // Parse and set host and related
|
{ // Parse and set host and related
|
||||||
$urlArr = parse_url($cfg['host']);
|
$urlArr = parse_url($cfg['host']);
|
||||||
|
|
||||||
$record['ident_switch.form.host'] = $urlArr['host'] ? rcube::Q($urlArr['host'], 'url') : '';
|
$record['ident_switch.form.imap.host'] = $urlArr['host'] ? rcube::Q($urlArr['host'], 'url') : '';
|
||||||
$record['ident_switch.form.port'] = $urlArr['port'] ? intval($urlArr['port']) : '';
|
$record['ident_switch.form.imap.port'] = $urlArr['port'] ? intval($urlArr['port']) : '';
|
||||||
|
|
||||||
if (strcasecmp('tls', $urlArr['scheme']) === 0)
|
if (strcasecmp('tls', $urlArr['scheme']) === 0)
|
||||||
$record['ident_switch.form.secure'] = 'tls';
|
$record['ident_switch.form.imap.tls'] = true;
|
||||||
elseif (strcasecmp('ssl', $urlArr['scheme']) === 0)
|
|
||||||
$record['ident_switch.form.secure'] = 'ssl';
|
|
||||||
else
|
else
|
||||||
$record['ident_switch.form.secure'] = '';
|
$record['ident_switch.form.imap.rls'] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$loginSet = false;
|
$loginSet = false;
|
||||||
@@ -630,11 +653,11 @@ class ident_switch extends rcube_plugin
|
|||||||
switch (strtoupper($cfg['user']))
|
switch (strtoupper($cfg['user']))
|
||||||
{
|
{
|
||||||
case 'EMAIL':
|
case 'EMAIL':
|
||||||
$record['ident_switch.form.username'] = $email;
|
$record['ident_switch.form.imap.username'] = $email;
|
||||||
$loginSet = true;
|
$loginSet = true;
|
||||||
break;
|
break;
|
||||||
case 'MBOX':
|
case 'MBOX':
|
||||||
$record['ident_switch.form.username'] = strstr($email, '@', true);
|
$record['ident_switch.form.imap.username'] = strstr($email, '@', true);
|
||||||
$loginSet = true;
|
$loginSet = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -642,13 +665,15 @@ class ident_switch extends rcube_plugin
|
|||||||
|
|
||||||
if ($cfg['readonly'])
|
if ($cfg['readonly'])
|
||||||
{
|
{
|
||||||
$record['ident_switch.form.readonly'] = 1;
|
$record['ident_switch.form.common.readonly'] = 1;
|
||||||
if ($loginSet)
|
if ($loginSet)
|
||||||
$record['ident_switch.form.readonly'] = 2;
|
$record['ident_switch.form.common.readonly'] = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $cfg['readonly'];
|
return $cfg['readonly'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function ntrim($str)
|
private static function ntrim($str)
|
||||||
|
|||||||
@@ -4,47 +4,64 @@
|
|||||||
*/
|
*/
|
||||||
$labels = array();
|
$labels = array();
|
||||||
|
|
||||||
// IMAP
|
// Common
|
||||||
$labels['form.caption'] = 'IMAP';
|
$labels['form.common.caption'] = 'Плагин ident_switch';
|
||||||
|
|
||||||
// Enabled
|
// Enabled
|
||||||
$labels['form.enabled'] = 'Включено';
|
$labels['form.common.enabled'] = 'Включено';
|
||||||
|
|
||||||
// Label
|
// 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
|
// Server host name
|
||||||
$labels['form.host'] = 'Адрес сервера';
|
$labels['form.imap.host'] = 'Адрес сервера';
|
||||||
|
|
||||||
// Secure connection (SSL/TLS)
|
// Secure connection (TLS)
|
||||||
$labels['form.secure'] = 'Защита подключения';
|
$labels['form.imap.tls'] = 'Безопасное подключение (TLS)';
|
||||||
|
|
||||||
// Port
|
// Port
|
||||||
$labels['form.port'] = 'Порт';
|
$labels['form.imap.port'] = 'Порт';
|
||||||
|
|
||||||
// Username
|
// Username
|
||||||
$labels['form.username'] = 'Имя пользователя';
|
$labels['form.imap.username'] = 'Имя пользователя';
|
||||||
|
|
||||||
// Password
|
// Password
|
||||||
$labels['form.password'] = 'Пароль';
|
$labels['form.imap.password'] = 'Пароль';
|
||||||
|
|
||||||
// Folder hierarchy delimiter
|
// Value in \'Username\' field is too long (64 chars max).
|
||||||
$labels['form.delimiter'] = 'Разделитель в иерархии папок';
|
$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).
|
// SMTP
|
||||||
$labels['err.host.long'] = '\'Адрес сервера\' в разделе IMAP должен быть не длинее 64 символов.';
|
$labels['form.smtp.caption'] = 'SMTP';
|
||||||
|
|
||||||
// Value in \'Username\' field of IMAP section is too long (64 chars max).
|
// Server host name
|
||||||
$labels['err.user.long'] = '\'Имя пользователя\' в секции IMAP должно быть не длинее 64 символов.';
|
$labels['form.smtp.host'] = 'Адрес сервера';
|
||||||
|
|
||||||
// Value in \'Folder hierarchy delimiter\' field of IMAP section is too long (1 char max).
|
// Secure connection (TLS)
|
||||||
$labels['err.delim.long'] = '\'Разделитель в иерархии папок\' в секции IMAP должен быть не длинее 1 символа.';
|
$labels['form.smtp.tls'] = 'Безопасное подключение (TLS)';
|
||||||
|
|
||||||
// Value in \'Port\' field of IMAP section must be a number.
|
// Port
|
||||||
$labels['err.port.num'] = '\'Порт\' в секции IMAP должен быть числом.';
|
$labels['form.smtp.port'] = 'Порт';
|
||||||
|
|
||||||
// Value in \'Port\' field of IMAP section must be between 1 and 65535.
|
// Authorization requtired
|
||||||
$labels['err.port.range'] = '\'Порт\' в секции IMAP должен быть в диапазоне от 1 до 65535.';
|
$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.';
|
||||||
Reference in New Issue
Block a user