diff --git a/SQL/mysql/2016060200.sql b/SQL/mysql/2016060200.sql new file mode 100644 index 0000000..15297c3 --- /dev/null +++ b/SQL/mysql/2016060200.sql @@ -0,0 +1,5 @@ +ALTER TABLE + ident_switch +MODIFY + username + varchar(64); diff --git a/SQL/postgres/2016060200.sql b/SQL/postgres/2016060200.sql new file mode 100644 index 0000000..20fecd7 --- /dev/null +++ b/SQL/postgres/2016060200.sql @@ -0,0 +1,5 @@ +ALTER TABLE + ident_switch +ALTER COLUMN + username +DROP NOT NULL; diff --git a/ident_switch.php b/ident_switch.php index d130c2f..389f6bc 100644 --- a/ident_switch.php +++ b/ident_switch.php @@ -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'] . '\').' diff --git a/localization/en_US.inc b/localization/en_US.inc index a03b37a..8e77207 100644 --- a/localization/en_US.inc +++ b/localization/en_US.inc @@ -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).'; diff --git a/localization/ru_RU.inc b/localization/ru_RU.inc index cf60d0f..feb0266 100644 --- a/localization/ru_RU.inc +++ b/localization/ru_RU.inc @@ -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 символов.';