Finally works correct for SMTP too. Closes #24.

This commit is contained in:
Boris Gulay
2018-07-16 20:30:48 +03:00
parent a437a107ba
commit a48481c57d
2 changed files with 23 additions and 7 deletions

View File

@@ -16,3 +16,6 @@ This plugin allows users to switch between different accounts (including remote)
* Branch 3.X - for Roundcube v1.3 * 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. 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.

View File

@@ -150,16 +150,29 @@ class ident_switch extends rcube_plugin
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' . self::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;