Username is not a required field anymore. If empty - email from identity

is used.
This commit is contained in:
Boris Gulay
2016-06-02 16:17:48 +03:00
parent 6849c47fd9
commit 7a97816d1c
5 changed files with 32 additions and 15 deletions

5
SQL/mysql/2016060200.sql Normal file
View File

@@ -0,0 +1,5 @@
ALTER TABLE
ident_switch
MODIFY
username
varchar(64);

View File

@@ -0,0 +1,5 @@
ALTER TABLE
ident_switch
ALTER COLUMN
username
DROP NOT NULL;

View File

@@ -84,6 +84,15 @@ class ident_switch extends rcube_plugin
$lbl = $r['label'];
if (!$lbl)
{
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']);
$rIid = $rc->db->fetch_assoc($q);
$r['username'] = $rIid['email'];
}
if (strpos($r['username'], '@') === false)
$lbl = $r['username'] . '@' . ($r['host'] ? $r['host'] : 'localhost');
else
@@ -167,7 +176,7 @@ class ident_switch extends rcube_plugin
'onchange' => 'plugin_switchIdent_secure_onChange();'
),
'ident_switch.form.port' => array('type' => 'text', 'size' => 5),
'ident_switch.form.username' => array('type' => 'text', 'size' => 64),
'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' => '.'),
),
@@ -243,14 +252,9 @@ class ident_switch extends rcube_plugin
$errMsg = 'user.long';
else
{
if (!$fUser)
$errMsg = 'user.empty';
else
{
$fDelim = self::ntrim(get_input_value('_ident_switch_form_delimiter', RCUBE_INPUT_POST));
if (strlen($fDelim) > 1)
$errMsg = 'delim.long';
}
$fDelim = self::ntrim(get_input_value('_ident_switch_form_delimiter', RCUBE_INPUT_POST));
if (strlen($fDelim) > 1)
$errMsg = 'delim.long';
}
}
}
@@ -372,6 +376,15 @@ class ident_switch extends rcube_plugin
$r = $rc->db->fetch_assoc($q);
if (is_array($r))
{
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']);
$rIid = $rc->db->fetch_assoc($q);
$r['username'] = $rIid['email'];
}
$rc->write_log(
$this->my_log,
'Switching mailbox to one for identity with ID = ' . $r['iid'] . ' (username = \'' . $r['username'] . '\').'

View File

@@ -31,9 +31,6 @@ $labels['form.password'] = 'Password';
// Folder hierarchy delimiter
$labels['form.delimiter'] = 'Folder hierarchy delimiter';
// \'Username\' field in IMAP section cannot be empty.
$labels['err.user.empty'] = '\'Username\' field in IMAP section cannot be empty.';
// 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).';

View File

@@ -31,9 +31,6 @@ $labels['form.password'] = 'Пароль';
// Folder hierarchy delimiter
$labels['form.delimiter'] = 'Разделитель в иерархии папок';
// \'Username\' field in IMAP section cannot be empty.
$labels['err.user.empty'] = '\'Имя пользователя\' в разделе IMAP не может быть пустым.';
// Value in \'Label\' field of IMAP section is too long (32 chars max).
$labels['err.label.long'] = '\'Название\' в разделе IMAP должно быть не длинее 32 символов.';