save special folders from normal dialog

This commit is contained in:
Christian Landvogt
2019-12-13 12:16:16 +01:00
parent f30f72099b
commit f1d2e3193a

View File

@@ -31,16 +31,17 @@ class ident_switch extends rcube_plugin
$this->add_hook('identity_create_after', array($this, 'on_identity_create_after')); $this->add_hook('identity_create_after', array($this, 'on_identity_create_after'));
$this->add_hook('identity_delete', array($this, 'on_identity_delete')); $this->add_hook('identity_delete', array($this, 'on_identity_delete'));
$this->add_hook('template_object_composeheaders', array($this, 'on_template_object_composeheaders')); $this->add_hook('template_object_composeheaders', array($this, 'on_template_object_composeheaders'));
$this->add_hook('preferences_list', array($this, 'on_special_folders_form'));
$this->add_hook('preferences_save', array($this, 'on_special_folders_update'));
$this->register_action('plugin.ident_switch.switch', array($this, 'on_switch')); $this->register_action('plugin.ident_switch.switch', array($this, 'on_switch'));
$rc = rcmail::get_instance(); $rc = rcmail::get_instance();
$saveFromConfig = Array('drafts_mbox', 'sent_mbox', 'trash_mbox', 'junk_mbox'); foreach (rcube_storage::$folder_types as $type)
foreach ($saveFromConfig as $k)
{ {
$key = $k . '_default' . self::MY_POSTFIX; $key = $type . '_mbox_default' . self::MY_POSTFIX;
if (!$_SESSION[$key]) if (!$_SESSION[$key])
$_SESSION[$key] = $rc->config->get($k); $_SESSION[$key] = $rc->config->get($type . '_mbox');
} }
} }
@@ -60,13 +61,12 @@ class ident_switch extends rcube_plugin
} }
} }
$setConfig = Array('drafts_mbox', 'sent_mbox', 'trash_mbox', 'junk_mbox'); foreach (rcube_storage::$folder_types as $type)
foreach ($setConfig as $k)
{ {
$defaultKey = $k . '_default' . self::MY_POSTFIX; $defaultKey = $type . '_mbox_default' . self::MY_POSTFIX;
$otherKey = $k . self::MY_POSTFIX; $otherKey = $type . '_mbox' . self::MY_POSTFIX;
$val = $_SESSION[$otherKey] ? $_SESSION[$otherKey] : $_SESSION[$defaultKey]; $val = $_SESSION[$otherKey] ? $_SESSION[$otherKey] : $_SESSION[$defaultKey];
$rc->config->set($k, $val); $rc->config->set($type . '_mbox', $val);
} }
return $args; return $args;
@@ -414,6 +414,84 @@ class ident_switch extends rcube_plugin
} }
} }
function on_special_folders_form($args)
{
$rc = rcmail::get_instance();
if (($args['section'] == 'folders') &&
(strcasecmp($rc->user->data['username'], $_SESSION['username']) !== 0))
{
$no_override = array_flip((array)$rc->config->get('dont_override'));
$onchange = "if ($(this).val() == 'INBOX') $(this).val('')";
$args['blocks']['main']['name'] .= ' (remote)';
$select = $rc->folder_selector(array('noselection' => '---',
'realnames' => true,
'maxlength' => 30,
'folder_filter' => 'mail',
'folder_rights' => 'w'));
foreach (rcube_storage::$folder_types as $type)
{
if (isset($no_override[$type . '_mbox']))
continue;
$defaultKey = $type . '_mbox_default' . self::MY_POSTFIX;
$otherKey = $type . '_mbox' . self::MY_POSTFIX;
$selected = $_SESSION[$otherKey] ? $_SESSION[$otherKey] : $_SESSION[$defaultKey];
$attr = array('id' => '_' . $type . '_mbox', 'name' => '_' . $type . '_mbox', 'onchange' => $onchange);
$args['blocks']['main']['options'][$type . '_mbox']['content'] = $select->show($selected, $attr);
}
}
return $args;
}
function on_special_folders_update($args)
{
$rc = rcmail::get_instance();
if (($args['section'] == 'folders') &&
(strcasecmp($rc->user->data['username'], $_SESSION['username']) !== 0))
{
$sql = 'SELECT id FROM ' . $rc->db->table_name(self::TABLE) . ' WHERE iid = ? AND user_id = ?';
$q = $rc->db->query($sql, $_SESSION['iid' . self::MY_POSTFIX], $rc->user->ID);
$r = $rc->db->fetch_assoc($q);
if ($r)
{
$sql = 'UPDATE ' .
$rc->db->table_name(self::TABLE) .
' SET drafts_mbox = ?, sent_mbox = ?, junk_mbox = ?, trash_mbox = ?' .
' WHERE id = ?';
$rc->db->query(
$sql,
$args['prefs']['drafts_mbox'],
$args['prefs']['sent_mbox'],
$args['prefs']['junk_mbox'],
$args['prefs']['trash_mbox'],
$r['id']
);
//abuse $plugin['abort'] to prevent RC main from saving prefs
$args['abort'] = true;
$args['result'] = true;
foreach (rcube_storage::$folder_types as $type)
{
if ($args['prefs'][$type . '_mbox']) {
$otherKey = $type . '_mbox' . self::MY_POSTFIX;
$_SESSION[$otherKey] = $args['prefs'][$type . '_mbox'];
}
}
return $args;
}
$args['abort'] = true;
$args['result'] = false;
}
return $args;
}
private static function check_field_values() private static function check_field_values()
{ {
@@ -570,10 +648,9 @@ class ident_switch extends rcube_plugin
$_SESSION['password'] = $_SESSION['password' . self::MY_POSTFIX]; $_SESSION['password'] = $_SESSION['password' . self::MY_POSTFIX];
$_SESSION['iid' . self::MY_POSTFIX] = -1; $_SESSION['iid' . self::MY_POSTFIX] = -1;
$delFromConfig = Array('drafts_mbox', 'sent_mbox', 'trash_mbox', 'junk_mbox'); foreach (rcube_storage::$folder_types as $type)
foreach ($delFromConfig as $k)
{ {
$otherKey = $k . self::MY_POSTFIX; $otherKey = $type . '_mbox' . self::MY_POSTFIX;
if ($_SESSION[$otherKey]) if ($_SESSION[$otherKey])
$rc->session->remove($otherKey); $rc->session->remove($otherKey);
} }
@@ -609,7 +686,7 @@ class ident_switch extends rcube_plugin
} }
} }
$moreToSave = Array('password', 'imap_delimiter'); $moreToSave = array('password', 'imap_delimiter');
foreach ($moreToSave as $k) foreach ($moreToSave as $k)
{ {
if (!$_SESSION[$k . self::MY_POSTFIX]) if (!$_SESSION[$k . self::MY_POSTFIX])
@@ -642,12 +719,11 @@ class ident_switch extends rcube_plugin
$_SESSION['password'] = $r['password']; $_SESSION['password'] = $r['password'];
$_SESSION['iid' . self::MY_POSTFIX] = $r['iid']; $_SESSION['iid' . self::MY_POSTFIX] = $r['iid'];
$saveToSessiong = Array('drafts_mbox', 'sent_mbox', 'trash_mbox', 'junk_mbox'); foreach (rcube_storage::$folder_types as $type)
foreach ($saveToSessiong as $k)
{ {
if ($r[$k]) { if ($r[$type . '_mbox']) {
$otherKey = $k . self::MY_POSTFIX; $otherKey = $type . '_mbox' . self::MY_POSTFIX;
$_SESSION[$otherKey] = $r[$k]; $_SESSION[$otherKey] = $r[$type . '_mbox'];
} }
} }
} }