Skip to content

Commit

Permalink
- Fix setting task name according to auth state. So, any action befor…
Browse files Browse the repository at this point in the history
…e user

  is authenticated is assigned to 'login' task instead of 'mail'. Now binding
  plugins to 'login' task is possible and realy usefull. It's also possible 
  to bind to all tasks excluding 'login'.
  • Loading branch information
alecpl committed Feb 6, 2010
1 parent a65bf3a commit 9b94eb6
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
@@ -1,6 +1,7 @@
CHANGELOG RoundCube Webmail
===========================

- Fix setting task name according to auth state
- Password: fix vpopmaild driver (#1486478)
- Add workaround for MySQL bug [http://bugs.mysql.com/bug.php?id=46293] (#1486474)
- Fix quoted text wrapping when replying to an HTML email in plain text (#1484141)
Expand Down
10 changes: 6 additions & 4 deletions index.php
Expand Up @@ -80,7 +80,7 @@
$RCMAIL->action = $startup['action'];

// try to log in
if ($RCMAIL->action=='login' && $RCMAIL->task=='mail') {
if ($RCMAIL->task == 'login' && $RCMAIL->action == 'login') {
// purge the session in case of new login when a session already exists
$RCMAIL->kill_session();

Expand Down Expand Up @@ -117,6 +117,8 @@
if ($url = get_input_value('_url', RCUBE_INPUT_POST))
parse_str($url, $query);

$RCMAIL->set_task('mail');

// allow plugins to control the redirect url after login success
$redir = $RCMAIL->plugins->exec_hook('login_after', $query + array('task' => $RCMAIL->task));
unset($redir['abort']);
Expand All @@ -132,7 +134,7 @@
}

// end session
else if ($RCMAIL->task=='logout' && isset($_SESSION['user_id'])) {
else if ($RCMAIL->task == 'logout' && isset($_SESSION['user_id'])) {
$userdata = array('user' => $_SESSION['username'], 'host' => $_SESSION['imap_host'], 'lang' => $RCMAIL->user->language);
$OUTPUT->show_message('loggedout');
$RCMAIL->logout_actions();
Expand All @@ -141,7 +143,7 @@
}

// check session and auth cookie
else if ($RCMAIL->action != 'login' && $_SESSION['user_id'] && $RCMAIL->action != 'send') {
else if ($RCMAIL->task != 'login' && $_SESSION['user_id'] && $RCMAIL->action != 'send') {
if (!$RCMAIL->authenticate_session()) {
$OUTPUT->show_message('sessionerror', 'error');
$RCMAIL->kill_session();
Expand All @@ -168,7 +170,7 @@
if (empty($RCMAIL->user->ID)) {
if ($OUTPUT->ajax_call)
$OUTPUT->redirect(array(), 2000);

if (!empty($_REQUEST['_framed']))
$OUTPUT->command('redirect', '?');

Expand Down
3 changes: 0 additions & 3 deletions plugins/archive/archive.php
Expand Up @@ -17,9 +17,6 @@ function init()
{
$rcmail = rcmail::get_instance();

if (!$rcmail->user->ID)
return;

$this->register_action('plugin.archive', array($this, 'request_action'));

// There is no "Archived flags"
Expand Down
3 changes: 2 additions & 1 deletion plugins/autologon/autologon.php
Expand Up @@ -6,6 +6,7 @@
*/
class autologon extends rcube_plugin
{
public $task = 'login';

function init()
{
Expand All @@ -18,7 +19,7 @@ function startup($args)
$rcmail = rcmail::get_instance();

// change action to login
if ($args['task'] == 'mail' && empty($args['action']) && empty($_SESSION['user_id']) && !empty($_GET['_autologin']) && $this->is_localhost())
if (empty($_SESSION['user_id']) && !empty($_GET['_autologin']) && $this->is_localhost())
$args['action'] = 'login';

return $args;
Expand Down
6 changes: 3 additions & 3 deletions plugins/help/help.php
Expand Up @@ -12,13 +12,13 @@

class help extends rcube_plugin
{
// all task excluding 'login' and 'logout'
public $task = '?(?!login|logout).*';

function init()
{
$rcmail = rcmail::get_instance();

if (!$rcmail->user->ID)
return;

$this->add_texts('localization/', false);

// register actions
Expand Down
3 changes: 2 additions & 1 deletion plugins/http_authentication/http_authentication.php
Expand Up @@ -10,6 +10,7 @@
*/
class http_authentication extends rcube_plugin
{
public $task = 'login';

function init()
{
Expand All @@ -20,7 +21,7 @@ function init()
function startup($args)
{
// change action to login
if ($args['task'] == 'mail' && empty($args['action']) && empty($_SESSION['user_id'])
if (empty($args['action']) && empty($_SESSION['user_id'])
&& !empty($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_PW']))
$args['action'] = 'login';

Expand Down
3 changes: 0 additions & 3 deletions plugins/markasjunk/markasjunk.php
Expand Up @@ -17,9 +17,6 @@ function init()
{
$rcmail = rcmail::get_instance();

if (!$rcmail->user->ID)
return;

$this->register_action('plugin.markasjunk', array($this, 'request_action'));

if ($rcmail->action == '' || $rcmail->action == 'show') {
Expand Down
2 changes: 2 additions & 0 deletions plugins/new_user_identity/new_user_identity.php
Expand Up @@ -22,6 +22,8 @@
*/
class new_user_identity extends rcube_plugin
{
public $task = 'login';

function init()
{
$this->add_hook('create_user', array($this, 'lookup_user_name'));
Expand Down
2 changes: 2 additions & 0 deletions plugins/squirrelmail_usercopy/squirrelmail_usercopy.php
Expand Up @@ -10,6 +10,8 @@
*/
class squirrelmail_usercopy extends rcube_plugin
{
public $task = 'login|settings';

private $prefs = null;
private $abook = array();

Expand Down
20 changes: 13 additions & 7 deletions program/include/rcmail.php
Expand Up @@ -39,7 +39,7 @@ class rcmail
public $imap;
public $output;
public $plugins;
public $task = 'mail';
public $task;
public $action = '';
public $comm_path = './';

Expand Down Expand Up @@ -91,10 +91,6 @@ private function startup()
openlog($syslog_id, LOG_ODELAY, $syslog_facility);
}

// set task and action properties
$this->set_task(get_input_value('_task', RCUBE_INPUT_GPC));
$this->action = asciiwords(get_input_value('_action', RCUBE_INPUT_GPC));

// connect to database
$GLOBALS['DB'] = $this->get_dbh();

Expand Down Expand Up @@ -123,6 +119,10 @@ private function startup()
// create user object
$this->set_user(new rcube_user($_SESSION['user_id']));

// set task and action properties
$this->set_task(get_input_value('_task', RCUBE_INPUT_GPC));
$this->action = asciiwords(get_input_value('_action', RCUBE_INPUT_GPC));

// reset some session parameters when changing task
if ($_SESSION['task'] != $this->task)
rcube_sess_unset('page');
Expand All @@ -131,7 +131,7 @@ private function startup()
$_SESSION['task'] = $this->task;

// create IMAP object
if ($this->task == 'mail')
if ($this->task == 'login')
$this->imap_init();

// create plugin API and load plugins
Expand All @@ -147,7 +147,13 @@ private function startup()
public function set_task($task)
{
$task = asciiwords($task);
$this->task = $task ? $task : 'mail';

if ($this->user && $this->user->ID)
$task = !$task || $task == 'login' ? 'mail' : $task;
else
$task = 'login';

$this->task = $task;
$this->comm_path = $this->url(array('task' => $this->task));

if ($this->output)
Expand Down
2 changes: 1 addition & 1 deletion program/include/rcube_plugin_api.php
Expand Up @@ -90,7 +90,7 @@ public function init()
if (class_exists($plugin_name, false)) {
$plugin = new $plugin_name($this);
// check inheritance and task specification
if (is_subclass_of($plugin, 'rcube_plugin') && (!$plugin->task || preg_match('/('.$plugin->task.')/i', $rcmail->task))) {
if (is_subclass_of($plugin, 'rcube_plugin') && (!$plugin->task || preg_match('/^('.$plugin->task.')$/i', $rcmail->task))) {
$plugin->init();
$this->plugins[] = $plugin;
}
Expand Down
2 changes: 2 additions & 0 deletions program/steps/mail/func.inc
Expand Up @@ -24,6 +24,8 @@ $EMAIL_ADDRESS_PATTERN = '([a-z0-9][a-z0-9\-\.\+\_]*@[a-z0-9][a-z0-9\-\.]*\\.[a-
// actions that do not require imap connection
$NOIMAP_ACTIONS = array('spell', 'addcontact', 'autocomplete', 'upload', 'display-attachment', 'remove-attachment');

// Init IMAP object
$RCMAIL->imap_init();

// log in to imap server
if (!in_array($RCMAIL->action, $NOIMAP_ACTIONS) && !$RCMAIL->imap_connect()) {
Expand Down

0 comments on commit 9b94eb6

Please sign in to comment.