From 39cd51aff59d8a85321474ee573b09b507b3f24e Mon Sep 17 00:00:00 2001 From: alecpl <alec@alec.pl> Date: Thu, 04 Dec 2008 14:07:29 -0500 Subject: [PATCH] - performance: connect to imap server only when needed (some mail actions do not require imap connection) --- index.php | 13 ------------- program/steps/mail/func.inc | 21 ++++++++++++++++++++- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/index.php b/index.php index d4fc543..74c7c21 100644 --- a/index.php +++ b/index.php @@ -121,14 +121,6 @@ } -// log in to imap server -if (!empty($RCMAIL->user->ID) && $RCMAIL->task == 'mail') { - if (!$RCMAIL->imap_connect()) { - $RCMAIL->kill_session(); - } -} - - // check client X-header to verify request origin if ($OUTPUT->ajax_call) { if (!$RCMAIL->config->get('devel_mode') && !rc_request_header('X-RoundCube-Referer')) { @@ -222,11 +214,6 @@ } } - -// make sure the message count is refreshed (for default view) -if ($RCMAIL->task == 'mail') { - $IMAP->messagecount($_SESSION['mbox'], 'ALL', true); -} // parse main template (default) $OUTPUT->send($RCMAIL->task); diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc index dc0a708..33503ae 100644 --- a/program/steps/mail/func.inc +++ b/program/steps/mail/func.inc @@ -22,8 +22,24 @@ require_once('lib/enriched.inc'); require_once('include/rcube_smtp.inc'); - $EMAIL_ADDRESS_PATTERN = '/([a-z0-9][a-z0-9\-\.\+\_]*@[a-z0-9]([a-z0-9\-][.]?)*[a-z0-9]\\.[a-z]{2,5})/i'; + +// actions that do not require imap connection +$NOIMAP_ACTIONS = array('spell', 'addcontact', 'autocomplete', 'upload'); + + +// log in to imap server +if (!in_array($RCMAIL->action, $NOIMAP_ACTIONS) && !$RCMAIL->imap_connect()) { + $RCMAIL->kill_session(); + + if ($OUTPUT->ajax_call) + $OUTPUT->redirect(array(), 2000); + + $OUTPUT->set_env('task', 'login'); + $OUTPUT->send('login'); +} + + // set imap properties and session vars if ($mbox = get_input_value('_mbox', RCUBE_INPUT_GPC)) @@ -64,6 +80,9 @@ $_SESSION['search'][$search_request] = $IMAP->get_search_set(); $OUTPUT->set_env('search_request', $search_request); } + + // make sure the message count is refreshed (for default view) + $IMAP->messagecount($mbox_name, 'ALL', true); } // set current mailbox in client environment -- Gitblit v1.9.1