Bug #8447: Move IMP initialization to function
authorMichael M Slusarz <slusarz@curecanti.org>
Mon, 27 Jul 2009 17:27:10 +0000 (11:27 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Mon, 27 Jul 2009 17:29:19 +0000 (11:29 -0600)
imp/lib/IMP.php
imp/lib/LoginTasks/Task/DeleteAttachmentsMonthly.php
imp/lib/LoginTasks/Task/DeleteSentmailMonthly.php
imp/lib/LoginTasks/Task/PurgeSentmail.php
imp/lib/LoginTasks/Task/PurgeSpam.php
imp/lib/LoginTasks/Task/PurgeTrash.php
imp/lib/LoginTasks/Task/RenameSentmailMonthly.php
imp/lib/base.php

index 0f9d578..44c4216 100644 (file)
@@ -50,6 +50,68 @@ class IMP
     /* filesystemGC() cache. */
     static private $_dirlist = array();
 
+    /* Has init previously been called? */
+    static private $_init = false;
+
+    /**
+     * Performs IMP initialization.
+     */
+    static public function initialize()
+    {
+        if (self::$_init) {
+            return;
+        }
+
+        if (!defined('IMP_TEMPLATES')) {
+            $registry = Horde_Registry::singleton();
+            define('IMP_TEMPLATES', $registry->get('templates'));
+        }
+
+        // Start compression.
+        if (!Horde_Util::nonInputVar('imp_no_compress')) {
+            Horde::compressOutput();
+        }
+
+        // TODO: Remove once this can be autoloaded
+        require_once 'Horde/Identity.php';
+
+        // Initialize global $imp_imap object.
+        if (!isset($GLOBALS['imp_imap'])) {
+            $GLOBALS['imp_imap'] = new IMP_Imap();
+        }
+
+        // Initialize some message parsing variables.
+        Horde_Mime::$brokenRFC2231 = !empty($GLOBALS['conf']['mailformat']['brokenrfc2231']);
+
+        // Set default message character set, if necessary
+        if ($def_charset = $GLOBALS['prefs']->getValue('default_msg_charset')) {
+            Horde_Mime_Part::$defaultCharset = $def_charset;
+            Horde_Mime_Headers::$defaultCharset = $def_charset;
+        }
+
+        $GLOBALS['notification'] = Horde_Notification::singleton();
+        $viewmode = isset($_SESSION['imp']['view'])
+            ? $_SESSION['imp']['view']
+            : 'imp';
+
+        if ($viewmode == 'mimp') {
+            $GLOBALS['imp_notify'] = $GLOBALS['notification']->attach('status', null, 'Horde_Notification_Listener_Mobile');
+        } else {
+            $GLOBALS['imp_notify'] = $GLOBALS['notification']->attach('status', array('viewmode' => $viewmode), 'IMP_Notification_Listener_Status');
+            if ($viewmode == 'imp') {
+                $GLOBALS['notification']->attach('audio');
+            }
+        }
+
+        // Initialize global $imp_mbox array.
+        $GLOBALS['imp_mbox'] = IMP::getCurrentMailboxInfo();
+
+        // Initialize IMP_Search object.
+        $GLOBALS['imp_search'] = new IMP_Search(array('id' => (isset($_SESSION['imp']) && IMP_Search::isSearchMbox($GLOBALS['imp_mbox']['mailbox'])) ? $GLOBALS['imp_mbox']['mailbox'] : null));
+
+        self::$_init = true;
+    }
+
     /**
      * Returns the plain text label that is displayed for the current mailbox,
      * replacing virtual search mailboxes with an appropriate description and
index 310d5ef..9a61c54 100644 (file)
@@ -15,6 +15,8 @@ class IMP_LoginTasks_Task_DeleteAttachmentsMonthly extends Horde_LoginTasks_Task
      */
     public function __construct()
     {
+        IMP::initialize();
+
         $this->active = $GLOBALS['prefs']->getValue('delete_attachments_monthly');
         if ($this->active &&
             $GLOBALS['prefs']->isLocked('delete_attachments_monthly')) {
index 43022ae..27715d9 100644 (file)
@@ -17,6 +17,8 @@ class IMP_LoginTasks_Task_DeleteSentmailMonthly extends Horde_LoginTasks_Task
      */
     public function __construct()
     {
+        IMP::initialize();
+
         $this->active = $GLOBALS['prefs']->getValue('delete_sentmail_monthly');
         if ($this->active &&
             $GLOBALS['prefs']->isLocked('delete_sentmail_monthly')) {
index 11b08d8..01d9394 100644 (file)
@@ -18,6 +18,8 @@ class IMP_LoginTasks_Task_PurgeSentmail extends Horde_LoginTasks_Task
      */
     public function __construct()
     {
+        IMP::initialize();
+
         $this->active = $GLOBALS['prefs']->getValue('purge_sentmail');
         if ($this->active) {
             $this->interval = $GLOBALS['prefs']->getValue('purge_sentmail_interval');
index 244ff32..3a60685 100644 (file)
@@ -18,6 +18,8 @@ class IMP_LoginTasks_Task_PurgeSpam extends Horde_LoginTasks_Task
      */
     public function __construct()
     {
+        IMP::initialize();
+
         $this->active = $GLOBALS['prefs']->getValue('purge_spam');
         if ($this->active) {
             $this->interval = $GLOBALS['prefs']->getValue('purge_spam_interval');
index 6fad947..00f8f89 100644 (file)
@@ -17,6 +17,8 @@ class IMP_LoginTasks_Task_PurgeTrash extends Horde_LoginTasks_Task
      */
     public function __construct()
     {
+        IMP::initialize();
+
         $this->active = $GLOBALS['prefs']->getValue('purge_trash');
         if ($this->active) {
             $this->interval = $GLOBALS['prefs']->getValue('purge_trash_interval');
index 0f03d5a..b62572d 100644 (file)
@@ -17,6 +17,8 @@ class IMP_LoginTasks_Task_RenameSentmailMonthly extends Horde_LoginTasks_Task
      */
     public function __construct()
     {
+        IMP::initialize();
+
         $this->active = $GLOBALS['prefs']->getValue('rename_sentmail_monthly');
         if ($this->active &&
             $GLOBALS['prefs']->isLocked('rename_sentmail_monthly')) {
index ef46859..c2060bb 100644 (file)
@@ -114,46 +114,5 @@ try {
     Horde_Auth::authenticationFailureRedirect('imp', $e);
 }
 
-$conf = &$GLOBALS['conf'];
-if (!defined('IMP_TEMPLATES')) {
-    define('IMP_TEMPLATES', $registry->get('templates'));
-}
-
-// Start compression.
-if (!Horde_Util::nonInputVar('imp_no_compress')) {
-    Horde::compressOutput();
-}
-
-/* Some stuff that only needs to be initialized if we are authenticated. */
-// TODO: Remove once this can be autoloaded
-require_once 'Horde/Identity.php';
-
-// Initialize global $imp_imap object.
-if (!isset($GLOBALS['imp_imap'])) {
-    $GLOBALS['imp_imap'] = new IMP_Imap();
-}
-
-// Initialize some message parsing variables.
-Horde_Mime::$brokenRFC2231 = !empty($GLOBALS['conf']['mailformat']['brokenrfc2231']);
-
-// Set default message character set, if necessary
-if ($def_charset = $GLOBALS['prefs']->getValue('default_msg_charset')) {
-    Horde_Mime_Part::$defaultCharset = $def_charset;
-    Horde_Mime_Headers::$defaultCharset = $def_charset;
-}
-
-$notification = Horde_Notification::singleton();
-if ($viewmode == 'mimp') {
-    $GLOBALS['imp_notify'] = $notification->attach('status', null, 'Horde_Notification_Listener_Mobile');
-} else {
-    $GLOBALS['imp_notify'] = $notification->attach('status', array('viewmode' => $viewmode), 'IMP_Notification_Listener_Status');
-    if ($viewmode == 'imp') {
-        $notification->attach('audio');
-    }
-}
-
-// Initialize global $imp_mbox array.
-$GLOBALS['imp_mbox'] = IMP::getCurrentMailboxInfo();
-
-// Initialize IMP_Search object.
-$GLOBALS['imp_search'] = new IMP_Search(array('id' => (isset($_SESSION['imp']) && IMP_Search::isSearchMbox($GLOBALS['imp_mbox']['mailbox'])) ? $GLOBALS['imp_mbox']['mailbox'] : null));
+// All other initialization occurs in IMP::initialize().
+IMP::initialize();