UI -> Ui
authorMichael M Slusarz <slusarz@curecanti.org>
Mon, 30 Nov 2009 07:36:38 +0000 (00:36 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Mon, 30 Nov 2009 18:27:42 +0000 (11:27 -0700)
33 files changed:
imp/ajax.php
imp/compose-dimp.php
imp/compose-mimp.php
imp/compose.php
imp/folders.php
imp/lib/Auth.php
imp/lib/Block/Newmail.php
imp/lib/Compose.php
imp/lib/Imap/Flags.php
imp/lib/LoginTasks/SystemTask/UpgradeFromImp4.php
imp/lib/Mime/Viewer/Plain.php
imp/lib/UI/Compose.php [deleted file]
imp/lib/UI/Folder.php [deleted file]
imp/lib/UI/Mailbox.php [deleted file]
imp/lib/UI/Message.php [deleted file]
imp/lib/UI/Search.php [deleted file]
imp/lib/Ui/Compose.php [new file with mode: 0644]
imp/lib/Ui/Folder.php [new file with mode: 0644]
imp/lib/Ui/Mailbox.php [new file with mode: 0644]
imp/lib/Ui/Message.php [new file with mode: 0644]
imp/lib/Ui/Search.php [new file with mode: 0644]
imp/lib/Views/Compose.php
imp/lib/Views/ListMessages.php
imp/lib/Views/ShowMessage.php
imp/mailbox-mimp.php
imp/mailbox.php
imp/message-dimp.php
imp/message-mimp.php
imp/message.php
imp/rss.php
imp/search-basic.php
imp/search.php
imp/thread.php

index c591708..f4eff0c 100644 (file)
@@ -586,7 +586,7 @@ case 'GetForwardData':
     try {
         $imp_contents = IMP_Contents::singleton($idx_string);
         $imp_compose = IMP_Compose::singleton(Horde_Util::getPost('imp_compose'));
-        $imp_ui = new IMP_UI_Compose();
+        $imp_ui = new IMP_Ui_Compose();
         $fwd_msg = $imp_ui->getForwardData($imp_compose, $imp_contents, $idx_string);
         $header = $fwd_msg['headers'];
         $header['replytype'] = 'forward';
@@ -782,7 +782,7 @@ case 'SendMDN':
         break;
     }
 
-    $imp_ui = new IMP_UI_Message();
+    $imp_ui = new IMP_Ui_Message();
     $imp_ui->MDNCheck($mbox, $uid, $reset($fetch_ret[$uid]['headertext']), true);
     break;
 
index 3dbb9a4..962b1f1 100644 (file)
@@ -52,8 +52,8 @@ if (!$prefs->isLocked('default_identity')) {
 /* Initialize the IMP_Compose:: object. */
 $imp_compose = IMP_Compose::singleton(Horde_Util::getFormData('composeCache'));
 
-/* Init IMP_UI_Compose:: object. */
-$imp_ui = new IMP_UI_Compose();
+/* Init IMP_Ui_Compose:: object. */
+$imp_ui = new IMP_Ui_Compose();
 
 if (count($_POST)) {
     $result = new stdClass;
index 8fee695..610b09f 100644 (file)
@@ -85,7 +85,7 @@ case 'd':
 
 case _("Expand Names"):
     $action = Horde_Util::getFormData('action');
-    $imp_ui = new IMP_UI_Compose();
+    $imp_ui = new IMP_Ui_Compose();
     $header['to'] = $imp_ui->expandAddresses(Horde_Util::getFormData('to'), $imp_compose);
     if ($action !== 'rc') {
         if ($prefs->getValue('compose_cc')) {
@@ -132,7 +132,7 @@ case _("Redirect"):
         break;
     }
 
-    $imp_ui = new IMP_UI_Compose();
+    $imp_ui = new IMP_Ui_Compose();
 
     $f_to = $imp_ui->getAddressList(Horde_Util::getFormData('to'));
 
@@ -202,7 +202,7 @@ case _("Send"):
     $header['replyto'] = $identity->getValue('replyto_addr');
     $header['subject'] = Horde_Util::getFormData('subject');
 
-    $imp_ui = new IMP_UI_Compose();
+    $imp_ui = new IMP_Ui_Compose();
 
     $header['to'] = $imp_ui->getAddressList(Horde_Util::getFormData('to'));
     if ($prefs->getValue('compose_cc')) {
index 7d4dace..a8c11a6 100644 (file)
@@ -158,8 +158,8 @@ try {
     $notification->push($e);
 }
 
-/* Init IMP_UI_Compose:: object. */
-$imp_ui = new IMP_UI_Compose();
+/* Init IMP_Ui_Compose:: object. */
+$imp_ui = new IMP_Ui_Compose();
 
 /* Set the default charset & encoding.
  * $charset - charset to use when sending messages
index a43f352..9209a06 100644 (file)
@@ -425,7 +425,7 @@ if (!empty($newmsgs)) {
 }
 
 /* Get the tree images. */
-$imp_ui_folder = new IMP_UI_Folder();
+$imp_ui_folder = new IMP_Ui_Folder();
 $tree_imgs = $imp_ui_folder->getTreeImages($raw_rows, array('expand_url' => $folders_url));
 
 /* Add some further information to the $raw_rows array. */
index 6f33859..3198d0c 100644 (file)
@@ -464,7 +464,7 @@ class IMP_Auth
         }
 
         /* Is the HTML editor available? */
-        $imp_ui = new IMP_UI_Compose();
+        $imp_ui = new IMP_Ui_Compose();
         $editor = Horde_Editor::singleton('Ckeditor', array('no_notify' => true));
         $sess['rteavail'] = $editor->supportedByBrowser();
 
index 9903bfd..03269aa 100644 (file)
@@ -36,7 +36,7 @@ class IMP_Block_Newmail extends Horde_Block
             $html .= '<tr><td><em>' . _("No unread messages") . '</em></td></tr>';
         } else {
             $charset = Horde_Nls::getCharset();
-            $imp_ui = new IMP_UI_Mailbox('INBOX');
+            $imp_ui = new IMP_Ui_Mailbox('INBOX');
             $shown = empty($this->_params['msgs_shown']) ? 3 : $this->_params['msgs_shown'];
 
             try {
index fa9833d..897b1d5 100644 (file)
@@ -1352,7 +1352,7 @@ class IMP_Compose
         }
 
         if (in_array($type, array('reply_auto', 'reply_list', '*'))) {
-            $imp_ui = new IMP_UI_Message();
+            $imp_ui = new IMP_Ui_Message();
             $list_info = $imp_ui->getListInformation($h);
             if ($list_info['exists']) {
                 $header['to'] = $list_info['reply_list'];
@@ -2477,7 +2477,7 @@ class IMP_Compose
             return;
         }
 
-        $imp_ui = new IMP_UI_Compose();
+        $imp_ui = new IMP_Ui_Compose();
 
         $headers = array();
         foreach (array('to', 'cc', 'bcc', 'subject') as $val) {
index 40f0919..c8c4db2 100644 (file)
@@ -272,7 +272,7 @@ class IMP_Imap_Flags
         }
 
         if (!empty($options['priority'])) {
-            $imp_msg_ui = new IMP_UI_Message();
+            $imp_msg_ui = new IMP_Ui_Message();
             switch ($imp_msg_ui->getXpriority($options['priority'])) {
             case 'high':
                 $process['highpri'] = $f['highpri'];
@@ -285,7 +285,7 @@ class IMP_Imap_Flags
         }
 
         if (!empty($options['atc'])) {
-            $imp_mbox_ui = new IMP_UI_Mailbox();
+            $imp_mbox_ui = new IMP_Ui_Mailbox();
             if ($type = $imp_mbox_ui->getAttachmentType($options['atc']->getType())) {
                 $process[$type] = $f[$type];
             }
index 5ba8b7a..c47b2d0 100644 (file)
@@ -67,7 +67,7 @@ class IMP_LoginTasks_SystemTask_UpgradeFromImp4 extends Horde_LoginTasks_SystemT
             return;
         }
 
-        $imp_ui_search = new IMP_UI_Search();
+        $imp_ui_search = new IMP_Ui_Search();
 
         foreach ($vfolders as $id => $vfolder) {
             /* If this is already a stdClass object, we have already
index 7424e74..51256f3 100644 (file)
@@ -94,7 +94,7 @@ class IMP_Horde_Mime_Viewer_Plain extends Horde_Mime_Viewer_Plain
                 (($show == 'thread') && (basename(Horde::selfUrl()) == 'thread.php'));
             if (!$hideBlocks && in_array($show, array('list', 'listthread'))) {
                 $header = $this->_params['contents']->getHeaderOb();
-                $imp_ui = new IMP_UI_Message();
+                $imp_ui = new IMP_Ui_Message();
                 $list_info = $imp_ui->getListInformation($header);
                 $hideBlocks = $list_info['exists'];
             }
diff --git a/imp/lib/UI/Compose.php b/imp/lib/UI/Compose.php
deleted file mode 100644 (file)
index 516a6fb..0000000
+++ /dev/null
@@ -1,214 +0,0 @@
-<?php
-/**
- * The IMP_UI_Compose:: class is designed to provide a place to store common
- * code shared among IMP's various UI views for the compose page.
- *
- * Copyright 2006-2009 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @author  Michael Slusarz <slusarz@horde.org>
- * @package IMP
- */
-class IMP_UI_Compose
-{
-    /**
-     */
-    public function expandAddresses($input, $imp_compose)
-    {
-        $addr_list = $this->getAddressList($input);
-        if (empty($addr_list)) {
-            return '';
-        }
-
-        $res = $imp_compose->expandAddresses($addr_list);
-
-        if (is_array($res)) {
-            $GLOBALS['notification']->push(_("Please resolve ambiguous or invalid addresses."), 'horde.warning');
-        }
-
-        return $res;
-    }
-
-    /**
-     * $encoding = DEPRECATED
-     *
-     * @throws Horde_Exception
-     */
-    public function redirectMessage($to, $imp_compose, $contents, $encoding)
-    {
-        try {
-            $recip = $imp_compose->recipientList(array('to' => $to));
-        } catch (IMP_Compose_Exception $e) {
-            throw new Horde_Exception($recip);
-        }
-        $recipients = implode(', ', $recip['list']);
-
-        $identity = Horde_Preffs_Identity::singleton(array('imp', 'imp'));
-        $from_addr = $identity->getFromAddress();
-
-        $headers = $contents->getHeaderOb();
-        $headers->addResentHeaders($from_addr, $recip['header']['to']);
-
-        $mime_message = $contents->getMIMEMessage();
-        $charset = $mime_message->getCharset();
-        if (is_null($charset)) {
-            $charset = $encoding;
-        }
-
-        /* We need to set the Return-Path header to the current user - see
-           RFC 2821 [4.4]. */
-        $headers->removeHeader('return-path');
-        $headers->addHeader('Return-Path', $from_addr);
-
-        /* Store history information. */
-        if (!empty($GLOBALS['conf']['maillog']['use_maillog'])) {
-            IMP_Maillog::log('redirect', $headers->getValue('message-id'), $recipients);
-        }
-
-        try {
-            $imp_compose->sendMessage($recipients, $headers, $mime_message, $charset);
-        } catch (IMP_Compose_Exception $e) {
-            throw new Horde_Exception($e);
-        }
-
-        $entry = sprintf("%s Redirected message sent to %s from %s",
-                         $_SERVER['REMOTE_ADDR'], $recipients, Horde_Auth::getAuth());
-        Horde::logMessage($entry, __FILE__, __LINE__, PEAR_LOG_INFO);
-
-        if ($GLOBALS['conf']['sentmail']['driver'] != 'none') {
-            $sentmail = IMP_Sentmail::factory();
-            $sentmail->log('redirect', $headers->getValue('message-id'), $recipients);
-        }
-    }
-
-    /**
-     */
-    public function getForwardData(&$imp_compose, &$imp_contents, $index)
-    {
-        $fwd_msg = $imp_compose->forwardMessage($imp_contents);
-        $subject_header = $imp_compose->attachIMAPMessage(array($index), $fwd_msg['headers']);
-        if ($subject_header !== false) {
-            $fwd_msg['headers']['subject'] = $subject_header;
-        }
-
-        return $fwd_msg;
-    }
-
-    /**
-     */
-    public function attachAutoCompleter($fields)
-    {
-        /* Attach autocompleters to the compose form elements. */
-        foreach ($fields as $val) {
-            $imple = Horde_Ajax_Imple::factory(array('imp', 'ContactAutoCompleter'), array('triggerId' => $val));
-            $imple->attach();
-        }
-    }
-
-    /**
-     */
-    public function attachSpellChecker($mode, $add_br = false)
-    {
-        $menu_view = $GLOBALS['prefs']->getValue('menu_view');
-        $show_text = ($menu_view == 'text' || $menu_view == 'both');
-        $br = ($add_br) ? '<br />' : '';
-        $spell_img = Horde::img('spellcheck.png');
-        $args = array(
-            'id' => ($mode == 'dimp' ? 'DIMP.' : 'IMP.') . 'SpellCheckerObject',
-            'targetId' => 'composeMessage',
-            'triggerId' => 'spellcheck',
-            'states' => array(
-                'CheckSpelling' => $spell_img . ($show_text ? $br . _("Check Spelling") : ''),
-                'Checking' => $spell_img . $br . _("Checking ..."),
-                'ResumeEdit' => $spell_img . $br . _("Resume Editing"),
-                'Error' => $spell_img . $br . _("Spell Check Failed")
-            )
-        );
-
-        $imple = Horde_Ajax_Imple::factory('SpellChecker', $args);
-        $imple->attach();
-    }
-
-    /**
-     */
-    public function getAddressList($to, $to_list = array(), $to_field = array(),
-                                   $to_new = '', $expand = false)
-    {
-        $to = rtrim(trim($to), ',');
-        if (!empty($to)) {
-            // Although we allow ';' to delimit addresses in the UI, need to
-            // convert to RFC-compliant ',' delimiter for processing.
-            $clean_to = '';
-            foreach (Horde_Mime_Address::explode($to, ',;') as $val) {
-                $val = trim($val);
-                $clean_to .= $val . (($val[Horde_String::length($val) - 1] == ';') ? ' ' : ', ');
-            }
-            if ($expand) {
-                return $clean_to;
-            } else {
-                return IMP_Compose::formatAddr($clean_to);
-            }
-        }
-
-        $tmp = array();
-        if (is_array($to_field)) {
-            foreach ($to_field as $key => $address) {
-                $tmp[$key] = $address;
-            }
-        }
-        if (is_array($to_list)) {
-            foreach ($to_list as $key => $address) {
-                if ($address != '') {
-                    $tmp[$key] = $address;
-                }
-            }
-        }
-
-        $to_new = rtrim(trim($to_new), ',');
-        if (!empty($to_new)) {
-            $tmp[] = $to_new;
-        }
-        return implode(', ', $tmp);
-    }
-
-    /**
-     * Initialize the Rich Text Editor (RTE).
-     *
-     * @param boolean $mini  Load the basic ckeditor stub?
-     */
-    public function initRTE($basic = false)
-    {
-        $editor = Horde_Editor::singleton('Ckeditor', array('basic' => $basic));
-
-        $config = array(
-            /* To more closely match "normal" textarea behavior, send <BR> on
-             * enter instead of <P>. */
-            // CKEDITOR.ENTER_BR
-            'enterMode: 2',
-            // CKEDITOR.ENTER_P
-            'shiftEnterMode: 1',
-
-            /* Don't load the config.js file. */
-            'customConfig: ""',
-
-            /* Disable resize of the textarea. */
-            'resize_enabled: false',
-
-            /* Use the old skin for now. */
-            'skin: "v2"'
-        );
-
-        $buttons = $GLOBALS['prefs']->getValue('ckeditor_buttons');
-        if (!empty($buttons)) {
-            $config[] = 'toolbar: ' . $GLOBALS['prefs']->getValue('ckeditor_buttons');
-        }
-
-        Horde::addInlineScript(array(
-            'if (!window.IMP) { window.IMP = {}; }',
-            'IMP.ckeditor_config = {' . implode(',', $config) . '}'
-        ));
-    }
-
-}
diff --git a/imp/lib/UI/Folder.php b/imp/lib/UI/Folder.php
deleted file mode 100644 (file)
index bb19e14..0000000
+++ /dev/null
@@ -1,131 +0,0 @@
-<?php
-/**
- * The IMP_UI_Folder:: class is designed to provide a place to store common
- * code shared among IMP's various UI views for folders.
- *
- * Copyright 2009 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @author  Michael Slusarz <slusarz@horde.org>
- * @package IMP
- */
-class IMP_UI_Folder
-{
-    /**
-     * Temporary array used to determine tree levels.
-     *
-     * @var array
-     */
-    var $_moreMbox = array();
-
-    /**
-     * Create the tree images for a list of folder elements.
-     *
-     * @var array $rows     Folder rows returned from IMP_Imap_Tree::build().
-     * @var array $options  Additional options:
-     * <pre>
-     * 'expand_url' - (string) The URL to use for expand/collapse links.
-     * </pre>
-     *
-     * @return array  An array of tree image strings.
-     */
-    public function getTreeImages($rows, $options = array())
-    {
-        $this->_moreMbox = array();
-        $out = array();
-
-        reset($rows);
-        while (list($key, $elt) = each($rows)) {
-            $out[$key] = $this->_getTreeImage($elt, $options);
-        }
-
-        return $out;
-    }
-
-    /**
-     * Create a tree image from a folder element entry.
-     *
-     * @var array $elt      An entry returned from IMP_Imap_Tree::element().
-     * @var array $options  See self::getTreeImages().
-     *
-     * @return string  The image string.
-     */
-    protected function _getTreeImage($elt, $options = array())
-    {
-        $alt = $dir = null;
-        $dir2 = $elt['user_icon']
-            ? Horde::img($elt['icon'], $elt['alt'], null, $elt['icondir'])
-            : '<span class="foldersImg ' . $elt['class'] . '"></span>';
-        $imaptree = IMP_Imap_Tree::singleton();
-
-        if ($elt['children'] && isset($options['expand_url'])) {
-            $dir = Horde_Util::addParameter($options['expand_url'], 'folder', $elt['value']);
-
-            if ($imaptree->isOpen($elt['base_elt'])) {
-                if (!is_null($dir)) {
-                    $dir = Horde_Util::addParameter($dir, 'actionID', 'collapse_folder');
-                    $alt = _("Collapse Folder");
-                }
-
-                if (empty($GLOBALS['nls']['rtl'][$GLOBALS['language']])) {
-                    $tree_img = ($elt['value'] == 'INBOX')
-                        ? 9
-                        : ($elt['peek'] ? 10 : 11);
-                } else {
-                    $tree_img = ($elt['value'] == 'INBOX')
-                        ? 12
-                        : ($elt['peek'] ? 13 : 14);
-                }
-            } else {
-                if (!is_null($dir)) {
-                    $dir = Horde_Util::addParameter($dir, 'actionID', 'expand_folder');
-                    $alt = _("Expand Folder");
-                }
-
-                if (empty($GLOBALS['nls']['rtl'][$GLOBALS['language']])) {
-                    $tree_img = ($elt['value'] == 'INBOX')
-                        ? 15
-                        : ($elt['peek'] ? 16 : 17);
-                } else {
-                    $tree_img = ($elt['value'] == 'INBOX')
-                        ? 18
-                        : ($elt['peek'] ? 19 : 20);
-                }
-            }
-
-            if (!is_null($dir)) {
-                $dir = Horde::link($dir, $alt) . '<span class="treeImg treeImg' . $tree_img . '"></span></a>' . $dir2;
-            }
-        } else {
-            if (($elt['value'] == 'INBOX') && !$elt['peek']) {
-                $dir = '<span class="treeImg"></span>' . $dir2;
-            } else {
-                if (empty($GLOBALS['nls']['rtl'][$GLOBALS['language']])) {
-                    $tree_img = ($elt['value'] == 'INBOX')
-                        ? 3
-                        : ($elt['peek'] ? 2 : 4);
-                } else {
-                    $tree_img = ($elt['value'] == 'INBOX')
-                        ? 7
-                        : ($elt['peek'] ? 6 : 8);
-                }
-                $dir = '<span class="treeImg treeImg' . $tree_img . '"></span>' . $dir2;
-            }
-        }
-
-        $line = '';
-        $this->_moreMbox[$elt['level']] = $elt['peek'];
-        for ($i = 0; $i < $elt['level']; $i++) {
-            if ($this->_moreMbox[$i]) {
-                $line .= '<span class="treeImg treeImg' . (empty($GLOBALS['nls']['rtl'][$GLOBALS['language']]) ? 1 : 5) . '"></span>';
-            } else {
-                $line .= '<span class="treeImg"></span>';
-            }
-        }
-
-        return $line . $dir;
-    }
-
-}
diff --git a/imp/lib/UI/Mailbox.php b/imp/lib/UI/Mailbox.php
deleted file mode 100644 (file)
index 556b283..0000000
+++ /dev/null
@@ -1,259 +0,0 @@
-<?php
-/**
- * The IMP_UI_Mailbox:: class is designed to provide a place to store common
- * code shared among IMP's various UI views for the mailbox page.
- *
- * Copyright 2006-2009 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @author  Michael Slusarz <slusarz@horde.org>
- * @package IMP
- */
-class IMP_UI_Mailbox
-{
-    /**
-     * The current mailbox.
-     *
-     * @var string
-     */
-    private $_mailbox;
-
-    /**
-     * Cached data.
-     *
-     * @var array
-     */
-    private $_cache = array();
-
-    /**
-     * Constructor.
-     *
-     * @param string $mailbox  The current mailbox.
-     */
-    public function __construct($mailbox = null)
-    {
-        $this->_mailbox = $mailbox;
-    }
-
-    /**
-     * Get From address information for display on mailbox page.
-     *
-     * @param array $ob       An array of envelope information.
-     * @param array $options  Additional options:
-     * <pre>
-     * 'fullfrom' - (boolean) If true, returns 'fullfrom' information.
-     *              DEFAULT: false
-     * 'specialchars' - (string) If set, run 'from' return through
-     *                  htmlspecialchars() using the given charset.
-     * </pre>
-     *
-     * @return array  An array of information:
-     * <pre>
-     * 'error' - (boolean)
-     * 'from' - (string)
-     * 'fullfrom' - (string)
-     * 'to' - (boolean)
-     * </pre>
-     */
-    public function getFrom($ob, $options = array())
-    {
-        $ret = array('error' => false, 'to' => false);
-
-        if (empty($ob['from'])) {
-            $ret['from'] = $ret['fullfrom'] = _("Invalid Address");
-            $ret['error'] = true;
-            return $ret;
-        }
-
-        if (!isset($this->_cache['drafts_sm_folder'])) {
-            $this->_cache['drafts_sm_folder'] = IMP::isSpecialFolder($this->_mailbox);
-        }
-
-        $from = Horde_Mime_Address::getAddressesFromObject($ob['from']);
-        $from = reset($from);
-
-        if (empty($from)) {
-            $ret['from'] = _("Invalid Address");
-            $ret['error'] = true;
-        } else {
-            $identity = Horde_Prefs_Identity::singleton(array('imp', 'imp'));
-            if ($identity->hasAddress($from['inner'])) {
-                /* This message was sent by one of the user's identity
-                 * addresses - show To: information instead. */
-                if (empty($ob['to'])) {
-                    $ret['from'] = _("Undisclosed Recipients");
-                    $ret['error'] = true;
-                } else {
-                    $to = Horde_Mime_Address::getAddressesFromObject($ob['to']);
-                    $first_to = reset($to);
-                    if (empty($first_to)) {
-                        $ret['from'] = _("Undisclosed Recipients");
-                        $ret['error'] = true;
-                    } else {
-                        $ret['from'] = empty($first_to['personal'])
-                            ? $first_to['inner']
-                            : $first_to['personal'];
-                        if (!empty($options['fullfrom'])) {
-                            $ret['fullfrom'] = $first_to['display'];
-                        }
-                    }
-                }
-                if (!$this->_cache['drafts_sm_folder']) {
-                    $ret['from'] = _("To") . ': ' . $ret['from'];
-                }
-                $ret['to'] = true;
-            } else {
-                $ret['from'] = empty($from['personal'])
-                    ? $from['inner']
-                    : $from['personal'];
-                if ($this->_cache['drafts_sm_folder']) {
-                    $ret['from'] = _("From") . ': ' . $ret['from'];
-                }
-                if (!empty($options['fullfrom'])) {
-                    $ret['fullfrom'] = $from['display'];
-                }
-            }
-        }
-
-        if (!empty($options['fullfrom']) && !isset($ret['fullfrom'])) {
-            $ret['fullfrom'] = $ret['from'];
-        }
-
-        if (!empty($ret['from']) && !empty($options['specialchars'])) {
-            $old_error = error_reporting(0);
-            $res = htmlspecialchars($ret['from'], ENT_QUOTES, $options['specialchars']);
-            if (empty($res)) {
-                $res = htmlspecialchars($ret['from']);
-            }
-            $ret['from'] = $res;
-            error_reporting($old_error);
-        }
-
-        return $ret;
-    }
-
-    /**
-     * Get size display information.
-     *
-     * @param integer $size  The size of the message, in bytes.
-     *
-     * @return string  A formatted size string.
-     */
-    public function getSize($size)
-    {
-        if ($size < 1024) {
-            return $size;
-        }
-
-        if (!isset($this->_cache['localeinfo'])) {
-            $this->_cache['localeinfo'] = Horde_Nls::getLocaleInfo();
-        }
-
-        $size = $size / 1024;
-
-        return ($size > 1024)
-            ? sprintf(_("%s MB"), number_format($size / 1024, 1, $this->_cache['localeinfo']['decimal_point'], $this->_cache['localeinfo']['thousands_sep']))
-            : sprintf(_("%s KB"), number_format($size, 0, $this->_cache['localeinfo']['decimal_point'], $this->_cache['localeinfo']['thousands_sep']));
-    }
-
-    /**
-     * Return the icon to use for a given attachment.
-     *
-     * @return string  The mailbox display icon type (attach, encrypt,
-     *                 signed).
-     */
-    public function getAttachmentType($type)
-    {
-        list($primary, $sub) = explode('/', $type, 2);
-        if ($primary == 'multipart') {
-            switch ($sub) {
-            case 'signed':
-                return 'signed';
-
-            case 'encrypted':
-                return 'encrypt';
-
-            case 'alternative':
-            case 'related':
-                /* Treat this as no attachments. */
-                break;
-
-            default:
-                return 'attach';
-            }
-        } elseif ($type == 'application/pkcs7-mime') {
-             return 'encrypt';
-        }
-
-        return '';
-    }
-
-    /**
-     * Formats the date header.
-     *
-     * @param integer $date  The UNIX timestamp.
-     *
-     * @return string  The formatted date header.
-     */
-    public function getDate($date)
-    {
-        if (!isset($this->_cache['today_start'])) {
-            $this->_cache['today_start'] = strtotime('today');
-            $this->_cache['today_end'] = strtotime('today + 1 day');
-        }
-
-        try {
-            $d = new DateTime($date);
-        } catch (Exception $e) {
-            /* Bug #5717 - Check for UT vs. UTC. */
-            if (substr(rtrim($date), -3) != ' UT') {
-                return _("Unknown Date");
-            }
-            try {
-                $d = new DateTime($date . 'C');
-            } catch (Exception $e) {
-                return _("Unknown Date");
-            }
-        }
-        $udate = $d->format('U');
-
-        if (($udate < $this->_cache['today_start']) ||
-            ($udate > $this->_cache['today_end'])) {
-            /* Not today, use the date. */
-            return strftime($GLOBALS['prefs']->getValue('date_format'), $udate);
-        }
-
-        /* Else, it's today, use the time. */
-        return strftime($GLOBALS['prefs']->getValue('time_format'), $udate);
-    }
-
-    /**
-     * Formats the subject header.
-     *
-     * @param string $subject     The MIME encoded subject header.
-     * @param string $htmlspaces  HTML-ize spaces?
-     *
-     * @return string  The formatted subject header.
-     */
-    public function getSubject($subject, $htmlspaces = false)
-    {
-        $subject = Horde_Mime::decode($subject);
-        if (empty($subject)) {
-            return _("[No Subject]");
-        }
-
-        $new_subject = $subject = IMP::filterText(preg_replace("/\s+/", ' ', $subject));
-
-        if ($htmlspaces) {
-            $new_subject = Horde_Text_Filter::filter($subject, 'space2html', array('charset' => Horde_Nls::getCharset(), 'encode' => true));
-            if (empty($new_subject)) {
-                $new_subject = htmlspecialchars($subject);
-            }
-        }
-
-        return empty($new_subject) ? $subject : $new_subject;
-    }
-
-}
diff --git a/imp/lib/UI/Message.php b/imp/lib/UI/Message.php
deleted file mode 100644 (file)
index eb1ed7c..0000000
+++ /dev/null
@@ -1,613 +0,0 @@
-<?php
-/**
- * The IMP_UI_Message:: class is designed to provide a place to store common
- * code shared among IMP's various UI views for the message page.
- *
- * Copyright 2006-2009 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @author  Michael Slusarz <slusarz@horde.org>
- * @package IMP
- */
-class IMP_UI_Message
-{
-    /**
-     * Return a list of "basic" headers w/gettext translations.
-     *
-     * @return array  Header name -> gettext translation mapping.
-     */
-    public function basicHeaders()
-    {
-        return array(
-            'date'      =>  _("Date"),
-            'from'      =>  _("From"),
-            'to'        =>  _("To"),
-            'cc'        =>  _("Cc"),
-            'bcc'       =>  _("Bcc"),
-            'reply-to'  =>  _("Reply-To"),
-            'subject'   =>  _("Subject")
-        );
-    }
-
-    /**
-     * Get the list of user-defined headers to display.
-     *
-     * @return array  The list of user-defined headers.
-     */
-    public function getUserHeaders()
-    {
-        $user_hdrs = $GLOBALS['prefs']->getValue('mail_hdr');
-
-        /* Split the list of headers by new lines and sort the list of headers
-         * to make sure there are no duplicates. */
-        if (is_array($user_hdrs)) {
-            $user_hdrs = implode("\n", $user_hdrs);
-        }
-        $user_hdrs = trim($user_hdrs);
-        if (empty($user_hdrs)) {
-            return array();
-        }
-
-        $user_hdrs = array_filter(array_keys(array_flip(array_map('trim', preg_split("/[\n\r]+/", str_replace(':', '', $user_hdrs))))));
-        natcasesort($user_hdrs);
-
-        return $user_hdrs;
-    }
-
-    /**
-     * Check if we need to send a MDN, and send if needed.
-     *
-     * @param string $mailbox     The mailbox of the message.
-     * @param integer $uid        The UID of the message.
-     * @param array $headers      The headers of the message.
-     * @param boolean $confirmed  Has the MDN request been confirmed?
-     *
-     * @return boolean  True if the MDN request needs to be confirmed.
-     */
-    public function MDNCheck($mailbox, $uid, $headers, $confirmed = false)
-    {
-        if (!$GLOBALS['prefs']->getValue('disposition_send_mdn') ||
-            $GLOBALS['imp_imap']->isReadOnly($mailbox)) {
-            return false;
-        }
-
-        /* Check to see if an MDN has been requested. */
-        $mdn = new Horde_Mime_Mdn($headers);
-        $return_addr = $mdn->getMDNReturnAddr();
-        if (!$return_addr) {
-            return false;
-        }
-
-        $msg_id = $headers->getValue('message-id');
-        $mdn_flag = $mdn_sent = false;
-
-        /* See if we have already processed this message. */
-        /* 1st test: $MDNSent keyword (RFC 3503 [3.1]). */
-        try {
-            $status = $GLOBALS['imp_imap']->ob()->status($mailbox, Horde_Imap_Client::STATUS_PERMFLAGS);
-            if (in_array('\\*', $status['permflags']) ||
-                in_array('$mdnsent', $status['permflags'])) {
-                $mdn_flag = true;
-                $res = $GLOBALS['imp_imap']->ob()->fetch($mailbox, array(
-                        Horde_Imap_Client::FETCH_FLAGS => true
-                    ), array('ids' => array($uid)));
-                $mdn_sent = in_array('$mdnsent', $res[$uid]['flags']);
-            }
-        } catch (Horde_Imap_Client_Exception $e) {}
-
-        if (!$mdn_flag) {
-            /* 2nd test: Use Maillog as a fallback. */
-            $mdn_sent = IMP_Maillog::sentMDN($msg_id, 'displayed');
-        }
-
-        if ($mdn_sent) {
-            return false;
-        }
-
-        /* See if we need to query the user. */
-        if ($mdn->userConfirmationNeeded() && !$confirmed) {
-            return true;
-        }
-
-        /* Send out the MDN now. */
-        try {
-            $mail_driver = IMP_Compose::getMailDriver();
-            $mdn->generate(false, $confirmed, 'displayed', $mail_driver['driver'], $mail_driver['params']);
-            IMP_Maillog::log('mdn', $msg_id, 'displayed');
-            $success = true;
-
-            if ($mdn_flag) {
-                $imp_message = IMP_Message::singleton();
-                $imp_message->flag(array('$MDNSent'), $uid . IMP::IDX_SEP . $mailbox, true);
-            }
-        } catch (Horde_Mime_Exception $e) {
-            $success = false;
-        }
-
-        if ($GLOBALS['conf']['sentmail']['driver'] != 'none') {
-            $sentmail = IMP_Sentmail::factory();
-            $sentmail->log('mdn', '', $return_addr, $success);
-        }
-
-        return false;
-    }
-
-    /**
-     * Adds the local time string to the date header.
-     *
-     * @param string $date  The date string.
-     *
-     * @return string  The local formatted time string.
-     */
-    public function getLocalTime($date)
-    {
-        if (empty($date)) {
-            $ltime = false;
-        } else {
-            $date = preg_replace('/\s+\(\w+\)$/', '', $date);
-            $ltime = strtotime($date);
-        }
-
-        if (($ltime === false) || ($ltime === -1)) {
-            return '';
-        }
-
-        $time_str = strftime($GLOBALS['prefs']->getValue('time_format'), $ltime);
-        $tz = strftime('%Z');
-
-        if ((date('Y') != @date('Y', $ltime)) ||
-            (date('M') != @date('M', $ltime)) ||
-            (date('d') != @date('d', $ltime))) {
-            /* Not today, use the date. */
-            $date_str = strftime($GLOBALS['prefs']->getValue('date_format'), $ltime);
-            return sprintf('%s %s %s', $date_str, $time_str, $tz);
-        }
-
-        /* Else, it's today, use the time only. */
-        return sprintf(_("Today, %s %s"), $time_str, $tz);
-    }
-
-    /**
-     * Parses all of the available mailing list headers.
-     *
-     * @param Horde_Mime_Headers $headers  A Horde_Mime_Headers object.
-     *
-     * @return array  TODO
-     */
-    public function parseAllListHeaders($headers)
-    {
-        $ret = array();
-
-        foreach (array_keys($headers->listHeaders()) as $val) {
-            if (($data = $headers->getValue($val))) {
-                $ret[$val] = $this->parseListHeaders($data);
-            }
-        }
-
-        return $ret;
-    }
-
-    /**
-     * Parse the information in mailing list headers.
-     *
-     * @param string $data  The header text to process.
-     * @param array $opts   Additional options:
-     * <pre>
-     * 'email' - (boolean) Only return e-mail values.
-     *           DEFAULT: false
-     * 'raw' - (boolean) Should the raw URL be returned instead of linking
-     *                   the header value?
-     *                   DEFAULT: false
-     * </pre>
-     *
-     * @return string  The header value.
-     */
-    public function parseListHeaders($data, $opts = array())
-    {
-        $output = '';
-
-        /* Split the incoming data by the ',' character. */
-        foreach (preg_split("/,/", $data) as $entry) {
-            /* Get the data inside of the brackets. If there is no brackets,
-             * then return the raw text. */
-            if (!preg_match("/\<([^\>]+)\>/", $entry, $matches)) {
-                return trim($entry);
-            }
-
-            /* Remove all whitespace from between brackets (RFC 2369 [2]). */
-            $match = preg_replace("/\s+/", '', $matches[1]);
-
-            /* Determine if there are any comments. */
-            preg_match("/(\(.+\))/", $entry, $comments);
-
-            /* RFC 2369 [2] states that we should only show the *FIRST* URL
-             * that appears in a header that we can adequately handle. */
-            if (stristr($match, 'mailto:') !== false) {
-                $match = substr($match, strpos($match, ':') + 1);
-                if (!empty($opts['raw'])) {
-                    return $match;
-                }
-                $output = Horde::link(IMP::composeLink($match)) . $match . '</a>';
-                if (!empty($comments[1])) {
-                    $output .= '&nbsp;' . $comments[1];
-                }
-                break;
-            } elseif (empty($data['email'])) {
-                if ($url = Horde_Text_Filter::filter($match, 'linkurls', array('callback' => 'Horde::externalUrl'))) {
-                    if (!empty($opts['raw'])) {
-                        return $match;
-                    }
-                    $output = $url;
-                    if (!empty($comments[1])) {
-                        $output .= '&nbsp;' . $comments[1];
-                    }
-                    break;
-                } else {
-                    /* Use this entry unless we can find a better one. */
-                    $output = $match;
-                }
-            }
-        }
-
-        return $output;
-    }
-
-    /**
-     * Determines the X-Priority of the message based on the headers.
-     *
-     * @param string $header  The X-Priority header.
-     *
-     * @return string  'high', 'low', or 'normal'.
-     */
-    public function getXpriority($header)
-    {
-        if ($header && preg_match('/\s*(\d+)\s*/', $header, $matches)) {
-            if (in_array($matches[1], array(1, 2))) {
-                return 'high';
-            } elseif (in_array($matches[1], array(4, 5))) {
-                return 'low';
-            }
-        }
-
-        return 'normal';
-    }
-
-    /**
-     * Returns e-mail information for a mailing list.
-     *
-     * @param Horde_Mime_Headers $headers  A Horde_Mime_Headers object.
-     *
-     * @return array  An array with 2 elements: 'exists' and 'reply_list'.
-     */
-    public function getListInformation($headers)
-    {
-        $ret = array('exists' => false, 'reply_list' => null);
-
-        if ($headers->listHeadersExist()) {
-            $ret['exists'] = true;
-
-            /* See if the List-Post header provides an e-mail address for the
-             * list. */
-            if (($val = $headers->getValue('list-post')) &&
-                ($val != 'NO')) {
-                $ret['reply_list'] = $this->parseListHeaders($val, array('email' => true, 'raw' => true));
-            }
-        }
-
-        return $ret;
-    }
-
-    /**
-     * Builds a string containing a list of addresses.
-     *
-     * @param array $addrlist  The list of addresses from
-     *                         Horde_Mime_Address::parseAddressList().
-     * @param integer $addURL  The self URL.
-     * @param boolean $link    Link each address to the compose screen?
-     *
-     * @return string  String containing the formatted address list.
-     */
-    public function buildAddressLinks($addrlist, $addURL = null, $link = true)
-    {
-        global $prefs, $registry;
-
-        /* Make sure this is a valid object address field. */
-        if (empty($addrlist) || !is_array($addrlist)) {
-            return null;
-        }
-
-        $add_link = null;
-        $addr_array = array();
-        $mimp_view = ($_SESSION['imp']['view'] == 'mimp');
-
-        /* Set up the add address icon link if contact manager is
-         * available. */
-        if (!is_null($addURL) && $link && $prefs->getValue('add_source')) {
-            try {
-                $add_link = $registry->hasMethod('contacts/import')
-                    ? Horde_Util::addParameter($addURL, 'actionID', 'add_address')
-                    : null;
-            } catch (Horde_Exception $e) {}
-        }
-
-        foreach (Horde_Mime_Address::getAddressesFromObject($addrlist) as $ob) {
-            if (isset($ob['groupname'])) {
-                $group_array = array();
-                foreach ($ob['addresses'] as $ad) {
-                    if (empty($ad['address']) || empty($ad['inner'])) {
-                        continue;
-                    }
-
-                    $ret = $mimp_view
-                        ? $ad['display']
-                        : htmlspecialchars($ad['display']);
-
-                    if ($link) {
-                        $ret = Horde::link(IMP::composeLink(array('to' => $ad['address'])), sprintf(_("New Message to %s"), $ad['inner'])) . htmlspecialchars($ad['display']) . '</a>';
-                    }
-
-                    /* Append the add address icon to every address if contact
-                     * manager is available. */
-                    if ($add_link) {
-                        $curr_link = Horde_Util::addParameter($add_link, array('name' => $ad['personal'], 'address' => $ad['inner']));
-                        $ret .= Horde::link($curr_link, sprintf(_("Add %s to my Address Book"), $ad['inner'])) .
-                            Horde::img('addressbook_add.png', sprintf(_("Add %s to my Address Book"), $ad['inner'])) . '</a>';
-                    }
-
-                    $group_array[] = $ret;
-                }
-
-                if (!$mimp_view) {
-                    $ob['groupname'] = htmlspecialchars($ob['groupname']);
-                }
-
-                $addr_array[] = $ob['groupname'] . ':' . (count($group_array) ? ' ' . implode(', ', $group_array) : '');
-            } elseif (!empty($ob['address']) && !empty($ob['inner'])) {
-                $ret = $mimp_view
-                    ? $ob['display']
-                    : htmlspecialchars($ob['display']);
-
-                /* If this is an incomplete e-mail address, don't link to
-                 * anything. */
-                if (stristr($ob['host'], 'UNKNOWN') === false) {
-                    if ($link) {
-                        $ret = Horde::link(IMP::composeLink(array('to' => $ob['address'])), sprintf(_("New Message to %s"), $ob['inner'])) . htmlspecialchars($ob['display']) . '</a>';
-                    }
-
-                    /* Append the add address icon to every address if contact
-                     * manager is available. */
-                    if ($add_link) {
-                        $curr_link = Horde_Util::addParameter($add_link, array('name' => $ob['personal'], 'address' => $ob['inner']));
-                        $ret .= Horde::link($curr_link, sprintf(_("Add %s to my Address Book"), $ob['inner'])) .
-                            Horde::img('addressbook_add.png', sprintf(_("Add %s to my Address Book"), $ob['inner'])) . '</a>';
-                    }
-                }
-
-                $addr_array[] = $ret;
-            }
-        }
-
-        if ($_SESSION['imp']['view'] == 'mimp') {
-            return implode(', ', $addr_array);
-        }
-
-        /* If left with an empty address list ($ret), inform the user that the
-         * recipient list is purposely "undisclosed". */
-        if (empty($addr_array)) {
-            $ret = _("Undisclosed Recipients");
-        } else {
-            /* Build the address line. */
-            $addr_count = count($addr_array);
-            $ret = '<span class="nowrap">' . implode(',</span> <span class="nowrap">', $addr_array) . '</span>';
-            if ($link && $addr_count > 15) {
-                $ret = '<span>' .
-                    '<span onclick="[ this, this.next(), this.next(1) ].invoke(\'toggle\')" class="widget largeaddrlist">' . sprintf(_("[Show Addresses - %d recipients]"), $addr_count) . '</span>' .
-                    '<span onclick="[ this, this.previous(), this.next() ].invoke(\'toggle\')" class="widget largeaddrlist" style="display:none">' . _("[Hide Addresses]") . '</span>' .
-                    '<span style="display:none">' .
-                    $ret . '</span></span>';
-            }
-        }
-
-        return $ret;
-    }
-
-    /**
-     * Prints out a MIME summary (in HTML).
-     *
-     * @param array $summary  Summary information from
-     *                        IMP_Summary::getSummary().
-     * @param array $display  The fields to display (in this order).
-     * @param boolean $atc    Is this an attachment?
-     *
-     * @return string  The formatted summary string.
-     */
-    public function formatSummary($summary, $display, $atc = false)
-    {
-        $tmp_summary = array();
-        foreach ($display as $val) {
-            $tmp_summary[] = $summary[$val];
-        }
-        return '<div class="mimePartInfo' . ($atc ? ' mimePartInfoAtc' : '') . '"><div>' . implode(' ', $tmp_summary) . '</div></div>';
-    }
-
-    /**
-     * Prints out a MIME status message (in HTML).
-     *
-     * @param array $data  An array of information (as returned from
-                           Horde_Mime_Viewer::render()).
-     *
-     * @return string  The formatted status message string.
-     */
-    public function formatStatusMsg($data)
-    {
-        $out = '';
-
-        foreach ($data as $val) {
-            if (empty($val)) {
-                continue;
-            }
-
-            $out .= '<div><table class="mimeStatusMessageTable"' . (isset($val['id']) ? (' id="' . $val['id'] . '" ') : '') . '>';
-
-            /* If no image, simply print out the message. */
-            if (empty($val['icon'])) {
-                foreach ($val['text'] as $val) {
-                    $out .= '<tr><td>' . $val . '</td></tr>';
-                }
-            } else {
-                $out .= '<tr><td class="mimeStatusIcon">' . $val['icon'] . '</td><td><table>';
-                foreach ($val['text'] as $val) {
-                    $out .= '<tr><td>' . $val . '</td></tr>';
-                }
-                $out .= '</table></td></tr>';
-            }
-
-            $out .= '</table></div>';
-        }
-
-        return $out
-            ? '<div class="mimeStatusMessage">' . $out . '</div>'
-            : '';
-    }
-
-    /**
-     * Output inline message display for the imp and dimp views.
-     *
-     * @param object $imp_contents      The IMP_Contents object containing the
-     *                                  message data.
-     * @param integer $contents_mask    The mask needed for a
-     *                                  IMP_Contents::getSummary() call.
-     * @param array $part_info_display  The list of summary fields to display.
-     * @param string $show_parts        The value of the 'show_parts' pref.
-     *
-     * @return array  An array with the following keys:
-     * <pre>
-     * 'atc_parts' - (array) The list of attachment MIME IDs.
-     * 'display_ids' - (array) The list of display MIME IDs.
-     * 'js_onload' - (array) A list of javascript code to run onload.
-     * 'msgtext' - (string) The rendered HTML code.
-     * </pre>
-     */
-    public function getInlineOutput($imp_contents, $contents_mask,
-                                    $part_info_display, $show_parts)
-    {
-        $atc_parts = $display_ids = $js_onload = $wrap_ids = array();
-        $msgtext = '';
-        $parts_list = $imp_contents->getContentTypeMap();
-
-        if ($show_parts == 'all') {
-            $atc_parts = array_keys($parts_list);
-        }
-
-        foreach ($parts_list as $mime_id => $mime_type) {
-            if (in_array($mime_id, $display_ids, true)) {
-                continue;
-            }
-
-            if (!($render_mode = $imp_contents->canDisplay($mime_id, IMP_Contents::RENDER_INLINE | IMP_Contents::RENDER_INFO))) {
-                if ($imp_contents->isAttachment($mime_type)) {
-                    if ($show_parts == 'atc') {
-                        $atc_parts[] = $mime_id;
-                    }
-
-                    if ($GLOBALS['prefs']->getValue('atc_display')) {
-                        $msgtext .= $this->formatSummary($imp_contents->getSummary($mime_id, $contents_mask), $part_info_display, true);
-                    }
-                }
-                continue;
-            }
-
-            $render_part = $imp_contents->renderMIMEPart($mime_id, $render_mode);
-            if (($render_mode & IMP_Contents::RENDER_INLINE) &&
-                empty($render_part)) {
-                /* This meant that nothing was rendered - allow this part to
-                 * appear in the attachment list instead. */
-                if ($show_parts == 'atc') {
-                    $atc_parts[] = $mime_id;
-                }
-                continue;
-            }
-
-            reset($render_part);
-            while (list($id, $info) = each($render_part)) {
-                $display_ids[] = $id;
-
-                if (empty($info)) {
-                    continue;
-                }
-
-                while (count($wrap_ids) &&
-                       !Horde_Mime::isChild(end($wrap_ids), $id)) {
-                    array_pop($wrap_ids);
-                    $msgtext .= '</div>';
-                }
-
-                if (!empty($info['wrap'])) {
-                    $msgtext .= '<div class="' . $info['wrap'] . '">';
-                    $wrap_ids[] = $mime_id;
-                }
-
-                if (empty($info['attach'])) {
-                    $msgtext .= $this->formatSummary($imp_contents->getSummary($id, $contents_mask), $part_info_display) .
-                        $this->formatStatusMsg($info['status']) .
-                        '<div class="mimePartData">' . $info['data'] . '</div>';
-                } else {
-                    if ($show_parts == 'atc') {
-                        $atc_parts[] = $id;
-                    }
-
-                    if ($GLOBALS['prefs']->getValue('atc_display')) {
-                        $msgtext .= $this->formatSummary($imp_contents->getSummary($id, $contents_mask), $part_info_display, true);
-                    }
-                }
-
-                if (isset($info['js'])) {
-                    $js_onload = array_merge($js_onload, $info['js']);
-                }
-            }
-        }
-
-        while (count($wrap_ids)) {
-            $msgtext .= '</div>';
-            array_pop($wrap_ids);
-        }
-
-        if (!strlen($msgtext)) {
-            $msgtext = $this->formatStatusMsg(array(array('text' => array(_("There are no parts that can be shown inline.")))));
-        }
-
-        return array(
-            'atc_parts' => $atc_parts,
-            'display_ids' => $display_ids,
-            'js_onload' => $js_onload,
-            'msgtext' => $msgtext
-        );
-    }
-
-    /**
-     * Get the display subject (filtered, formatted, and linked).
-     *
-     * @param string $subject  The subject text.
-     *
-     * @return string  The display subject string.
-     */
-    public function getDisplaySubject($subject)
-    {
-        return Horde_Text_Filter::filter(IMP::filterText($subject), 'text2html', array('parselevel' => Horde_Text_Filter_Text2html::MICRO, 'class' => null, 'callback' => null));
-    }
-
-    /**
-     * Redirect to mailbox after deleting a message?
-     *
-     * @return boolean  Return to mailbox?
-     */
-    public function moveAfterAction()
-    {
-        return (($_SESSION['imp']['protocol'] != 'pop') &&
-                !IMP::hideDeletedMsgs($GLOBALS['imp_mbox']['mailbox']) &&
-                !$GLOBALS['prefs']->getValue('use_trash'));
-    }
-
-}
diff --git a/imp/lib/UI/Search.php b/imp/lib/UI/Search.php
deleted file mode 100644 (file)
index 489ed77..0000000
+++ /dev/null
@@ -1,164 +0,0 @@
-<?php
-/**
- * The IMP_UI_Search:: class is designed to provide a place to store common
- * code shared among IMP's various UI views for the search page.
- *
- * Copyright 2009 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @author  Michael Slusarz <slusarz@horde.org>
- * @package IMP
- */
-class IMP_UI_Search
-{
-    /**
-     * Creates a search query.
-     *
-     * @param array $search  The list of search criteria.
-     *
-     * @return object  A search object (Horde_Imap_Client_Search_Query).
-     */
-    public function createQuery($search)
-    {
-        $query = new Horde_Imap_Client_Search_Query();
-
-        $search_array = array();
-        $search_fields = $GLOBALS['imp_search']->searchFields();
-        $flag_fields = $GLOBALS['imp_search']->flagFields();
-        $imp_flags = IMP_Imap_Flags::singleton();
-        $or_search = false;
-
-        foreach ($search as $rule) {
-            $ob = new Horde_Imap_Client_Search_Query();
-
-            $type = isset($search_fields[$rule->t]['type'])
-                ? $search_fields[$rule->t]['type']
-                : $rule->t;
-
-            switch ($type) {
-            case 'or':
-                $query->orSearch($search_array);
-                $search_array = array();
-                $or_search = true;
-                break;
-
-            case 'flag':
-                if (isset($flag_fields[$rule->v])) {
-                    $val = $imp_flags->parseFormId($rule->t);
-                    $ob->flag($val['flag'], $val['set']);
-                    $search_array[] = $ob;
-                }
-                break;
-
-            case 'header':
-                if (!empty($rule->v)) {
-                    $ob->headerText($rule->t, $rule->v, !empty($rule->n));
-                    $search_array[] = $ob;
-                }
-                break;
-
-            case 'customhdr':
-                if (!empty($rule->v)) {
-                    $ob->headerText($rule->v->h, $rule->v->s, !empty($rule->n));
-                    $search_array[] = $ob;
-                }
-                break;
-
-            case 'body':
-            case 'text':
-                if (!empty($rule->v)) {
-                    $ob->text($rule->c, $search_fields[$rule->t]['type'] == 'body', !empty($rule->n));
-                    $search_array[] = $ob;
-                }
-                break;
-
-            case 'date':
-                if (!empty($rule->v)) {
-                    $date = new Horde_Date(array('year' => $rule->v->y, 'month' => $rule->v->m + 1, 'mday' => $rule->v->d));
-                    $ob->dateSearch($date, ($rule->t == 'date_on') ? Horde_Imap_Client_Search_Query::DATE_ON : (($rule->t == 'date_until') ? Horde_Imap_Client_Search_Query::DATE_BEFORE : Horde_Imap_Client_Search_Query::DATE_SINCE));
-                    $search_array[] = $ob;
-                }
-                break;
-
-            case 'within':
-                /* Limited to day granularity because that is the technical
-                 * limit for IMAP servers without 'WITHIN' extension. */
-                if (!empty($rule->v)) {
-                    $secs = $rule->v->v * 60 * 60 * 24;
-
-                    switch ($rule->v->l) {
-                    case 'y':
-                        $secs *= 365;
-                        break;
-
-                    case 'm':
-                        $secs *= 30;
-                        break;
-                    }
-
-                    $ob->intervalSearch($secs, $rule->t == 'older' ? Horde_Imap_Client_Search_Query::INTERVAL_OLDER : Horde_Imap_Client_Search_Query::INTERVAL_YOUNGER);
-                    $search_array[] = $ob;
-                }
-                break;
-
-            case 'size':
-                if (!empty($rule->v)) {
-                    $ob->size(intval($rule->v), $rule->t == 'size_larger');
-                    $search_array[] = $ob;
-                }
-                break;
-            }
-        }
-
-        if ($or_search) {
-            $query->orSearch($search_array);
-        } else {
-            $query->andSearch($search_array);
-        }
-
-        return $query;
-    }
-
-    /**
-     * Create a search query from input gathered from the basic search script
-     * (imp/search-basic.php).
-     *
-     * @param string $mbox      The mailbox to search.
-     * @param string $criteria  The criteria to search.
-     * @param string $text      The criteria text.
-     * @param boolean $not      Should the criteria search be a not search?
-     * @param string $flag      A flag to search for.
-     *
-     * @return string  The search query ID.
-     */
-    public function processBasicSearch($mbox, $criteria, $text, $not, $flag)
-    {
-        $c_list = array();
-
-        if ($criteria) {
-            $search_fields = $GLOBALS['imp_search']->searchFields();
-            $tmp = new stdClass;
-            $tmp->t = $criteria;
-            $tmp->v = ($search_fields[$criteria]['type'] == 'size')
-                ? floatval($text) * 1024
-                : $text;
-            if ($search_fields[$criteria]['not']) {
-                $tmp->n = (bool)$not;
-            }
-            $c_list[] = $tmp;
-        }
-
-        if ($flag) {
-            $tmp = new stdClass;
-            $tmp->t = 'flag';
-            $tmp->v = $flag;
-            $c_list[] = $tmp;
-        }
-
-        /* Set the search in the IMP session. */
-        return $GLOBALS['imp_search']->createSearchQuery($this->createQuery($c_list), array($mbox), $c_list, _("Search Results"), IMP_Search::MBOX_PREFIX . IMP_Search::BASIC_SEARCH);
-    }
-
-}
diff --git a/imp/lib/Ui/Compose.php b/imp/lib/Ui/Compose.php
new file mode 100644 (file)
index 0000000..2b42798
--- /dev/null
@@ -0,0 +1,214 @@
+<?php
+/**
+ * The IMP_Ui_Compose:: class is designed to provide a place to store common
+ * code shared among IMP's various UI views for the compose page.
+ *
+ * Copyright 2006-2009 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author  Michael Slusarz <slusarz@horde.org>
+ * @package IMP
+ */
+class IMP_Ui_Compose
+{
+    /**
+     */
+    public function expandAddresses($input, $imp_compose)
+    {
+        $addr_list = $this->getAddressList($input);
+        if (empty($addr_list)) {
+            return '';
+        }
+
+        $res = $imp_compose->expandAddresses($addr_list);
+
+        if (is_array($res)) {
+            $GLOBALS['notification']->push(_("Please resolve ambiguous or invalid addresses."), 'horde.warning');
+        }
+
+        return $res;
+    }
+
+    /**
+     * $encoding = DEPRECATED
+     *
+     * @throws Horde_Exception
+     */
+    public function redirectMessage($to, $imp_compose, $contents, $encoding)
+    {
+        try {
+            $recip = $imp_compose->recipientList(array('to' => $to));
+        } catch (IMP_Compose_Exception $e) {
+            throw new Horde_Exception($recip);
+        }
+        $recipients = implode(', ', $recip['list']);
+
+        $identity = Horde_Preffs_Identity::singleton(array('imp', 'imp'));
+        $from_addr = $identity->getFromAddress();
+
+        $headers = $contents->getHeaderOb();
+        $headers->addResentHeaders($from_addr, $recip['header']['to']);
+
+        $mime_message = $contents->getMIMEMessage();
+        $charset = $mime_message->getCharset();
+        if (is_null($charset)) {
+            $charset = $encoding;
+        }
+
+        /* We need to set the Return-Path header to the current user - see
+           RFC 2821 [4.4]. */
+        $headers->removeHeader('return-path');
+        $headers->addHeader('Return-Path', $from_addr);
+
+        /* Store history information. */
+        if (!empty($GLOBALS['conf']['maillog']['use_maillog'])) {
+            IMP_Maillog::log('redirect', $headers->getValue('message-id'), $recipients);
+        }
+
+        try {
+            $imp_compose->sendMessage($recipients, $headers, $mime_message, $charset);
+        } catch (IMP_Compose_Exception $e) {
+            throw new Horde_Exception($e);
+        }
+
+        $entry = sprintf("%s Redirected message sent to %s from %s",
+                         $_SERVER['REMOTE_ADDR'], $recipients, Horde_Auth::getAuth());
+        Horde::logMessage($entry, __FILE__, __LINE__, PEAR_LOG_INFO);
+
+        if ($GLOBALS['conf']['sentmail']['driver'] != 'none') {
+            $sentmail = IMP_Sentmail::factory();
+            $sentmail->log('redirect', $headers->getValue('message-id'), $recipients);
+        }
+    }
+
+    /**
+     */
+    public function getForwardData(&$imp_compose, &$imp_contents, $index)
+    {
+        $fwd_msg = $imp_compose->forwardMessage($imp_contents);
+        $subject_header = $imp_compose->attachIMAPMessage(array($index), $fwd_msg['headers']);
+        if ($subject_header !== false) {
+            $fwd_msg['headers']['subject'] = $subject_header;
+        }
+
+        return $fwd_msg;
+    }
+
+    /**
+     */
+    public function attachAutoCompleter($fields)
+    {
+        /* Attach autocompleters to the compose form elements. */
+        foreach ($fields as $val) {
+            $imple = Horde_Ajax_Imple::factory(array('imp', 'ContactAutoCompleter'), array('triggerId' => $val));
+            $imple->attach();
+        }
+    }
+
+    /**
+     */
+    public function attachSpellChecker($mode, $add_br = false)
+    {
+        $menu_view = $GLOBALS['prefs']->getValue('menu_view');
+        $show_text = ($menu_view == 'text' || $menu_view == 'both');
+        $br = ($add_br) ? '<br />' : '';
+        $spell_img = Horde::img('spellcheck.png');
+        $args = array(
+            'id' => ($mode == 'dimp' ? 'DIMP.' : 'IMP.') . 'SpellCheckerObject',
+            'targetId' => 'composeMessage',
+            'triggerId' => 'spellcheck',
+            'states' => array(
+                'CheckSpelling' => $spell_img . ($show_text ? $br . _("Check Spelling") : ''),
+                'Checking' => $spell_img . $br . _("Checking ..."),
+                'ResumeEdit' => $spell_img . $br . _("Resume Editing"),
+                'Error' => $spell_img . $br . _("Spell Check Failed")
+            )
+        );
+
+        $imple = Horde_Ajax_Imple::factory('SpellChecker', $args);
+        $imple->attach();
+    }
+
+    /**
+     */
+    public function getAddressList($to, $to_list = array(), $to_field = array(),
+                                   $to_new = '', $expand = false)
+    {
+        $to = rtrim(trim($to), ',');
+        if (!empty($to)) {
+            // Although we allow ';' to delimit addresses in the UI, need to
+            // convert to RFC-compliant ',' delimiter for processing.
+            $clean_to = '';
+            foreach (Horde_Mime_Address::explode($to, ',;') as $val) {
+                $val = trim($val);
+                $clean_to .= $val . (($val[Horde_String::length($val) - 1] == ';') ? ' ' : ', ');
+            }
+            if ($expand) {
+                return $clean_to;
+            } else {
+                return IMP_Compose::formatAddr($clean_to);
+            }
+        }
+
+        $tmp = array();
+        if (is_array($to_field)) {
+            foreach ($to_field as $key => $address) {
+                $tmp[$key] = $address;
+            }
+        }
+        if (is_array($to_list)) {
+            foreach ($to_list as $key => $address) {
+                if ($address != '') {
+                    $tmp[$key] = $address;
+                }
+            }
+        }
+
+        $to_new = rtrim(trim($to_new), ',');
+        if (!empty($to_new)) {
+            $tmp[] = $to_new;
+        }
+        return implode(', ', $tmp);
+    }
+
+    /**
+     * Initialize the Rich Text Editor (RTE).
+     *
+     * @param boolean $mini  Load the basic ckeditor stub?
+     */
+    public function initRTE($basic = false)
+    {
+        $editor = Horde_Editor::singleton('Ckeditor', array('basic' => $basic));
+
+        $config = array(
+            /* To more closely match "normal" textarea behavior, send <BR> on
+             * enter instead of <P>. */
+            // CKEDITOR.ENTER_BR
+            'enterMode: 2',
+            // CKEDITOR.ENTER_P
+            'shiftEnterMode: 1',
+
+            /* Don't load the config.js file. */
+            'customConfig: ""',
+
+            /* Disable resize of the textarea. */
+            'resize_enabled: false',
+
+            /* Use the old skin for now. */
+            'skin: "v2"'
+        );
+
+        $buttons = $GLOBALS['prefs']->getValue('ckeditor_buttons');
+        if (!empty($buttons)) {
+            $config[] = 'toolbar: ' . $GLOBALS['prefs']->getValue('ckeditor_buttons');
+        }
+
+        Horde::addInlineScript(array(
+            'if (!window.IMP) { window.IMP = {}; }',
+            'IMP.ckeditor_config = {' . implode(',', $config) . '}'
+        ));
+    }
+
+}
diff --git a/imp/lib/Ui/Folder.php b/imp/lib/Ui/Folder.php
new file mode 100644 (file)
index 0000000..b726089
--- /dev/null
@@ -0,0 +1,131 @@
+<?php
+/**
+ * The IMP_Ui_Folder:: class is designed to provide a place to store common
+ * code shared among IMP's various UI views for folders.
+ *
+ * Copyright 2009 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author  Michael Slusarz <slusarz@horde.org>
+ * @package IMP
+ */
+class IMP_Ui_Folder
+{
+    /**
+     * Temporary array used to determine tree levels.
+     *
+     * @var array
+     */
+    var $_moreMbox = array();
+
+    /**
+     * Create the tree images for a list of folder elements.
+     *
+     * @var array $rows     Folder rows returned from IMP_Imap_Tree::build().
+     * @var array $options  Additional options:
+     * <pre>
+     * 'expand_url' - (string) The URL to use for expand/collapse links.
+     * </pre>
+     *
+     * @return array  An array of tree image strings.
+     */
+    public function getTreeImages($rows, $options = array())
+    {
+        $this->_moreMbox = array();
+        $out = array();
+
+        reset($rows);
+        while (list($key, $elt) = each($rows)) {
+            $out[$key] = $this->_getTreeImage($elt, $options);
+        }
+
+        return $out;
+    }
+
+    /**
+     * Create a tree image from a folder element entry.
+     *
+     * @var array $elt      An entry returned from IMP_Imap_Tree::element().
+     * @var array $options  See self::getTreeImages().
+     *
+     * @return string  The image string.
+     */
+    protected function _getTreeImage($elt, $options = array())
+    {
+        $alt = $dir = null;
+        $dir2 = $elt['user_icon']
+            ? Horde::img($elt['icon'], $elt['alt'], null, $elt['icondir'])
+            : '<span class="foldersImg ' . $elt['class'] . '"></span>';
+        $imaptree = IMP_Imap_Tree::singleton();
+
+        if ($elt['children'] && isset($options['expand_url'])) {
+            $dir = Horde_Util::addParameter($options['expand_url'], 'folder', $elt['value']);
+
+            if ($imaptree->isOpen($elt['base_elt'])) {
+                if (!is_null($dir)) {
+                    $dir = Horde_Util::addParameter($dir, 'actionID', 'collapse_folder');
+                    $alt = _("Collapse Folder");
+                }
+
+                if (empty($GLOBALS['nls']['rtl'][$GLOBALS['language']])) {
+                    $tree_img = ($elt['value'] == 'INBOX')
+                        ? 9
+                        : ($elt['peek'] ? 10 : 11);
+                } else {
+                    $tree_img = ($elt['value'] == 'INBOX')
+                        ? 12
+                        : ($elt['peek'] ? 13 : 14);
+                }
+            } else {
+                if (!is_null($dir)) {
+                    $dir = Horde_Util::addParameter($dir, 'actionID', 'expand_folder');
+                    $alt = _("Expand Folder");
+                }
+
+                if (empty($GLOBALS['nls']['rtl'][$GLOBALS['language']])) {
+                    $tree_img = ($elt['value'] == 'INBOX')
+                        ? 15
+                        : ($elt['peek'] ? 16 : 17);
+                } else {
+                    $tree_img = ($elt['value'] == 'INBOX')
+                        ? 18
+                        : ($elt['peek'] ? 19 : 20);
+                }
+            }
+
+            if (!is_null($dir)) {
+                $dir = Horde::link($dir, $alt) . '<span class="treeImg treeImg' . $tree_img . '"></span></a>' . $dir2;
+            }
+        } else {
+            if (($elt['value'] == 'INBOX') && !$elt['peek']) {
+                $dir = '<span class="treeImg"></span>' . $dir2;
+            } else {
+                if (empty($GLOBALS['nls']['rtl'][$GLOBALS['language']])) {
+                    $tree_img = ($elt['value'] == 'INBOX')
+                        ? 3
+                        : ($elt['peek'] ? 2 : 4);
+                } else {
+                    $tree_img = ($elt['value'] == 'INBOX')
+                        ? 7
+                        : ($elt['peek'] ? 6 : 8);
+                }
+                $dir = '<span class="treeImg treeImg' . $tree_img . '"></span>' . $dir2;
+            }
+        }
+
+        $line = '';
+        $this->_moreMbox[$elt['level']] = $elt['peek'];
+        for ($i = 0; $i < $elt['level']; $i++) {
+            if ($this->_moreMbox[$i]) {
+                $line .= '<span class="treeImg treeImg' . (empty($GLOBALS['nls']['rtl'][$GLOBALS['language']]) ? 1 : 5) . '"></span>';
+            } else {
+                $line .= '<span class="treeImg"></span>';
+            }
+        }
+
+        return $line . $dir;
+    }
+
+}
diff --git a/imp/lib/Ui/Mailbox.php b/imp/lib/Ui/Mailbox.php
new file mode 100644 (file)
index 0000000..9de3a81
--- /dev/null
@@ -0,0 +1,259 @@
+<?php
+/**
+ * The IMP_Ui_Mailbox:: class is designed to provide a place to store common
+ * code shared among IMP's various UI views for the mailbox page.
+ *
+ * Copyright 2006-2009 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author  Michael Slusarz <slusarz@horde.org>
+ * @package IMP
+ */
+class IMP_Ui_Mailbox
+{
+    /**
+     * The current mailbox.
+     *
+     * @var string
+     */
+    private $_mailbox;
+
+    /**
+     * Cached data.
+     *
+     * @var array
+     */
+    private $_cache = array();
+
+    /**
+     * Constructor.
+     *
+     * @param string $mailbox  The current mailbox.
+     */
+    public function __construct($mailbox = null)
+    {
+        $this->_mailbox = $mailbox;
+    }
+
+    /**
+     * Get From address information for display on mailbox page.
+     *
+     * @param array $ob       An array of envelope information.
+     * @param array $options  Additional options:
+     * <pre>
+     * 'fullfrom' - (boolean) If true, returns 'fullfrom' information.
+     *              DEFAULT: false
+     * 'specialchars' - (string) If set, run 'from' return through
+     *                  htmlspecialchars() using the given charset.
+     * </pre>
+     *
+     * @return array  An array of information:
+     * <pre>
+     * 'error' - (boolean)
+     * 'from' - (string)
+     * 'fullfrom' - (string)
+     * 'to' - (boolean)
+     * </pre>
+     */
+    public function getFrom($ob, $options = array())
+    {
+        $ret = array('error' => false, 'to' => false);
+
+        if (empty($ob['from'])) {
+            $ret['from'] = $ret['fullfrom'] = _("Invalid Address");
+            $ret['error'] = true;
+            return $ret;
+        }
+
+        if (!isset($this->_cache['drafts_sm_folder'])) {
+            $this->_cache['drafts_sm_folder'] = IMP::isSpecialFolder($this->_mailbox);
+        }
+
+        $from = Horde_Mime_Address::getAddressesFromObject($ob['from']);
+        $from = reset($from);
+
+        if (empty($from)) {
+            $ret['from'] = _("Invalid Address");
+            $ret['error'] = true;
+        } else {
+            $identity = Horde_Prefs_Identity::singleton(array('imp', 'imp'));
+            if ($identity->hasAddress($from['inner'])) {
+                /* This message was sent by one of the user's identity
+                 * addresses - show To: information instead. */
+                if (empty($ob['to'])) {
+                    $ret['from'] = _("Undisclosed Recipients");
+                    $ret['error'] = true;
+                } else {
+                    $to = Horde_Mime_Address::getAddressesFromObject($ob['to']);
+                    $first_to = reset($to);
+                    if (empty($first_to)) {
+                        $ret['from'] = _("Undisclosed Recipients");
+                        $ret['error'] = true;
+                    } else {
+                        $ret['from'] = empty($first_to['personal'])
+                            ? $first_to['inner']
+                            : $first_to['personal'];
+                        if (!empty($options['fullfrom'])) {
+                            $ret['fullfrom'] = $first_to['display'];
+                        }
+                    }
+                }
+                if (!$this->_cache['drafts_sm_folder']) {
+                    $ret['from'] = _("To") . ': ' . $ret['from'];
+                }
+                $ret['to'] = true;
+            } else {
+                $ret['from'] = empty($from['personal'])
+                    ? $from['inner']
+                    : $from['personal'];
+                if ($this->_cache['drafts_sm_folder']) {
+                    $ret['from'] = _("From") . ': ' . $ret['from'];
+                }
+                if (!empty($options['fullfrom'])) {
+                    $ret['fullfrom'] = $from['display'];
+                }
+            }
+        }
+
+        if (!empty($options['fullfrom']) && !isset($ret['fullfrom'])) {
+            $ret['fullfrom'] = $ret['from'];
+        }
+
+        if (!empty($ret['from']) && !empty($options['specialchars'])) {
+            $old_error = error_reporting(0);
+            $res = htmlspecialchars($ret['from'], ENT_QUOTES, $options['specialchars']);
+            if (empty($res)) {
+                $res = htmlspecialchars($ret['from']);
+            }
+            $ret['from'] = $res;
+            error_reporting($old_error);
+        }
+
+        return $ret;
+    }
+
+    /**
+     * Get size display information.
+     *
+     * @param integer $size  The size of the message, in bytes.
+     *
+     * @return string  A formatted size string.
+     */
+    public function getSize($size)
+    {
+        if ($size < 1024) {
+            return $size;
+        }
+
+        if (!isset($this->_cache['localeinfo'])) {
+            $this->_cache['localeinfo'] = Horde_Nls::getLocaleInfo();
+        }
+
+        $size = $size / 1024;
+
+        return ($size > 1024)
+            ? sprintf(_("%s MB"), number_format($size / 1024, 1, $this->_cache['localeinfo']['decimal_point'], $this->_cache['localeinfo']['thousands_sep']))
+            : sprintf(_("%s KB"), number_format($size, 0, $this->_cache['localeinfo']['decimal_point'], $this->_cache['localeinfo']['thousands_sep']));
+    }
+
+    /**
+     * Return the icon to use for a given attachment.
+     *
+     * @return string  The mailbox display icon type (attach, encrypt,
+     *                 signed).
+     */
+    public function getAttachmentType($type)
+    {
+        list($primary, $sub) = explode('/', $type, 2);
+        if ($primary == 'multipart') {
+            switch ($sub) {
+            case 'signed':
+                return 'signed';
+
+            case 'encrypted':
+                return 'encrypt';
+
+            case 'alternative':
+            case 'related':
+                /* Treat this as no attachments. */
+                break;
+
+            default:
+                return 'attach';
+            }
+        } elseif ($type == 'application/pkcs7-mime') {
+             return 'encrypt';
+        }
+
+        return '';
+    }
+
+    /**
+     * Formats the date header.
+     *
+     * @param integer $date  The UNIX timestamp.
+     *
+     * @return string  The formatted date header.
+     */
+    public function getDate($date)
+    {
+        if (!isset($this->_cache['today_start'])) {
+            $this->_cache['today_start'] = strtotime('today');
+            $this->_cache['today_end'] = strtotime('today + 1 day');
+        }
+
+        try {
+            $d = new DateTime($date);
+        } catch (Exception $e) {
+            /* Bug #5717 - Check for UT vs. UTC. */
+            if (substr(rtrim($date), -3) != ' UT') {
+                return _("Unknown Date");
+            }
+            try {
+                $d = new DateTime($date . 'C');
+            } catch (Exception $e) {
+                return _("Unknown Date");
+            }
+        }
+        $udate = $d->format('U');
+
+        if (($udate < $this->_cache['today_start']) ||
+            ($udate > $this->_cache['today_end'])) {
+            /* Not today, use the date. */
+            return strftime($GLOBALS['prefs']->getValue('date_format'), $udate);
+        }
+
+        /* Else, it's today, use the time. */
+        return strftime($GLOBALS['prefs']->getValue('time_format'), $udate);
+    }
+
+    /**
+     * Formats the subject header.
+     *
+     * @param string $subject     The MIME encoded subject header.
+     * @param string $htmlspaces  HTML-ize spaces?
+     *
+     * @return string  The formatted subject header.
+     */
+    public function getSubject($subject, $htmlspaces = false)
+    {
+        $subject = Horde_Mime::decode($subject);
+        if (empty($subject)) {
+            return _("[No Subject]");
+        }
+
+        $new_subject = $subject = IMP::filterText(preg_replace("/\s+/", ' ', $subject));
+
+        if ($htmlspaces) {
+            $new_subject = Horde_Text_Filter::filter($subject, 'space2html', array('charset' => Horde_Nls::getCharset(), 'encode' => true));
+            if (empty($new_subject)) {
+                $new_subject = htmlspecialchars($subject);
+            }
+        }
+
+        return empty($new_subject) ? $subject : $new_subject;
+    }
+
+}
diff --git a/imp/lib/Ui/Message.php b/imp/lib/Ui/Message.php
new file mode 100644 (file)
index 0000000..df70048
--- /dev/null
@@ -0,0 +1,613 @@
+<?php
+/**
+ * The IMP_Ui_Message:: class is designed to provide a place to store common
+ * code shared among IMP's various UI views for the message page.
+ *
+ * Copyright 2006-2009 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author  Michael Slusarz <slusarz@horde.org>
+ * @package IMP
+ */
+class IMP_Ui_Message
+{
+    /**
+     * Return a list of "basic" headers w/gettext translations.
+     *
+     * @return array  Header name -> gettext translation mapping.
+     */
+    public function basicHeaders()
+    {
+        return array(
+            'date'      =>  _("Date"),
+            'from'      =>  _("From"),
+            'to'        =>  _("To"),
+            'cc'        =>  _("Cc"),
+            'bcc'       =>  _("Bcc"),
+            'reply-to'  =>  _("Reply-To"),
+            'subject'   =>  _("Subject")
+        );
+    }
+
+    /**
+     * Get the list of user-defined headers to display.
+     *
+     * @return array  The list of user-defined headers.
+     */
+    public function getUserHeaders()
+    {
+        $user_hdrs = $GLOBALS['prefs']->getValue('mail_hdr');
+
+        /* Split the list of headers by new lines and sort the list of headers
+         * to make sure there are no duplicates. */
+        if (is_array($user_hdrs)) {
+            $user_hdrs = implode("\n", $user_hdrs);
+        }
+        $user_hdrs = trim($user_hdrs);
+        if (empty($user_hdrs)) {
+            return array();
+        }
+
+        $user_hdrs = array_filter(array_keys(array_flip(array_map('trim', preg_split("/[\n\r]+/", str_replace(':', '', $user_hdrs))))));
+        natcasesort($user_hdrs);
+
+        return $user_hdrs;
+    }
+
+    /**
+     * Check if we need to send a MDN, and send if needed.
+     *
+     * @param string $mailbox     The mailbox of the message.
+     * @param integer $uid        The UID of the message.
+     * @param array $headers      The headers of the message.
+     * @param boolean $confirmed  Has the MDN request been confirmed?
+     *
+     * @return boolean  True if the MDN request needs to be confirmed.
+     */
+    public function MDNCheck($mailbox, $uid, $headers, $confirmed = false)
+    {
+        if (!$GLOBALS['prefs']->getValue('disposition_send_mdn') ||
+            $GLOBALS['imp_imap']->isReadOnly($mailbox)) {
+            return false;
+        }
+
+        /* Check to see if an MDN has been requested. */
+        $mdn = new Horde_Mime_Mdn($headers);
+        $return_addr = $mdn->getMDNReturnAddr();
+        if (!$return_addr) {
+            return false;
+        }
+
+        $msg_id = $headers->getValue('message-id');
+        $mdn_flag = $mdn_sent = false;
+
+        /* See if we have already processed this message. */
+        /* 1st test: $MDNSent keyword (RFC 3503 [3.1]). */
+        try {
+            $status = $GLOBALS['imp_imap']->ob()->status($mailbox, Horde_Imap_Client::STATUS_PERMFLAGS);
+            if (in_array('\\*', $status['permflags']) ||
+                in_array('$mdnsent', $status['permflags'])) {
+                $mdn_flag = true;
+                $res = $GLOBALS['imp_imap']->ob()->fetch($mailbox, array(
+                        Horde_Imap_Client::FETCH_FLAGS => true
+                    ), array('ids' => array($uid)));
+                $mdn_sent = in_array('$mdnsent', $res[$uid]['flags']);
+            }
+        } catch (Horde_Imap_Client_Exception $e) {}
+
+        if (!$mdn_flag) {
+            /* 2nd test: Use Maillog as a fallback. */
+            $mdn_sent = IMP_Maillog::sentMDN($msg_id, 'displayed');
+        }
+
+        if ($mdn_sent) {
+            return false;
+        }
+
+        /* See if we need to query the user. */
+        if ($mdn->userConfirmationNeeded() && !$confirmed) {
+            return true;
+        }
+
+        /* Send out the MDN now. */
+        try {
+            $mail_driver = IMP_Compose::getMailDriver();
+            $mdn->generate(false, $confirmed, 'displayed', $mail_driver['driver'], $mail_driver['params']);
+            IMP_Maillog::log('mdn', $msg_id, 'displayed');
+            $success = true;
+
+            if ($mdn_flag) {
+                $imp_message = IMP_Message::singleton();
+                $imp_message->flag(array('$MDNSent'), $uid . IMP::IDX_SEP . $mailbox, true);
+            }
+        } catch (Horde_Mime_Exception $e) {
+            $success = false;
+        }
+
+        if ($GLOBALS['conf']['sentmail']['driver'] != 'none') {
+            $sentmail = IMP_Sentmail::factory();
+            $sentmail->log('mdn', '', $return_addr, $success);
+        }
+
+        return false;
+    }
+
+    /**
+     * Adds the local time string to the date header.
+     *
+     * @param string $date  The date string.
+     *
+     * @return string  The local formatted time string.
+     */
+    public function getLocalTime($date)
+    {
+        if (empty($date)) {
+            $ltime = false;
+        } else {
+            $date = preg_replace('/\s+\(\w+\)$/', '', $date);
+            $ltime = strtotime($date);
+        }
+
+        if (($ltime === false) || ($ltime === -1)) {
+            return '';
+        }
+
+        $time_str = strftime($GLOBALS['prefs']->getValue('time_format'), $ltime);
+        $tz = strftime('%Z');
+
+        if ((date('Y') != @date('Y', $ltime)) ||
+            (date('M') != @date('M', $ltime)) ||
+            (date('d') != @date('d', $ltime))) {
+            /* Not today, use the date. */
+            $date_str = strftime($GLOBALS['prefs']->getValue('date_format'), $ltime);
+            return sprintf('%s %s %s', $date_str, $time_str, $tz);
+        }
+
+        /* Else, it's today, use the time only. */
+        return sprintf(_("Today, %s %s"), $time_str, $tz);
+    }
+
+    /**
+     * Parses all of the available mailing list headers.
+     *
+     * @param Horde_Mime_Headers $headers  A Horde_Mime_Headers object.
+     *
+     * @return array  TODO
+     */
+    public function parseAllListHeaders($headers)
+    {
+        $ret = array();
+
+        foreach (array_keys($headers->listHeaders()) as $val) {
+            if (($data = $headers->getValue($val))) {
+                $ret[$val] = $this->parseListHeaders($data);
+            }
+        }
+
+        return $ret;
+    }
+
+    /**
+     * Parse the information in mailing list headers.
+     *
+     * @param string $data  The header text to process.
+     * @param array $opts   Additional options:
+     * <pre>
+     * 'email' - (boolean) Only return e-mail values.
+     *           DEFAULT: false
+     * 'raw' - (boolean) Should the raw URL be returned instead of linking
+     *                   the header value?
+     *                   DEFAULT: false
+     * </pre>
+     *
+     * @return string  The header value.
+     */
+    public function parseListHeaders($data, $opts = array())
+    {
+        $output = '';
+
+        /* Split the incoming data by the ',' character. */
+        foreach (preg_split("/,/", $data) as $entry) {
+            /* Get the data inside of the brackets. If there is no brackets,
+             * then return the raw text. */
+            if (!preg_match("/\<([^\>]+)\>/", $entry, $matches)) {
+                return trim($entry);
+            }
+
+            /* Remove all whitespace from between brackets (RFC 2369 [2]). */
+            $match = preg_replace("/\s+/", '', $matches[1]);
+
+            /* Determine if there are any comments. */
+            preg_match("/(\(.+\))/", $entry, $comments);
+
+            /* RFC 2369 [2] states that we should only show the *FIRST* URL
+             * that appears in a header that we can adequately handle. */
+            if (stristr($match, 'mailto:') !== false) {
+                $match = substr($match, strpos($match, ':') + 1);
+                if (!empty($opts['raw'])) {
+                    return $match;
+                }
+                $output = Horde::link(IMP::composeLink($match)) . $match . '</a>';
+                if (!empty($comments[1])) {
+                    $output .= '&nbsp;' . $comments[1];
+                }
+                break;
+            } elseif (empty($data['email'])) {
+                if ($url = Horde_Text_Filter::filter($match, 'linkurls', array('callback' => 'Horde::externalUrl'))) {
+                    if (!empty($opts['raw'])) {
+                        return $match;
+                    }
+                    $output = $url;
+                    if (!empty($comments[1])) {
+                        $output .= '&nbsp;' . $comments[1];
+                    }
+                    break;
+                } else {
+                    /* Use this entry unless we can find a better one. */
+                    $output = $match;
+                }
+            }
+        }
+
+        return $output;
+    }
+
+    /**
+     * Determines the X-Priority of the message based on the headers.
+     *
+     * @param string $header  The X-Priority header.
+     *
+     * @return string  'high', 'low', or 'normal'.
+     */
+    public function getXpriority($header)
+    {
+        if ($header && preg_match('/\s*(\d+)\s*/', $header, $matches)) {
+            if (in_array($matches[1], array(1, 2))) {
+                return 'high';
+            } elseif (in_array($matches[1], array(4, 5))) {
+                return 'low';
+            }
+        }
+
+        return 'normal';
+    }
+
+    /**
+     * Returns e-mail information for a mailing list.
+     *
+     * @param Horde_Mime_Headers $headers  A Horde_Mime_Headers object.
+     *
+     * @return array  An array with 2 elements: 'exists' and 'reply_list'.
+     */
+    public function getListInformation($headers)
+    {
+        $ret = array('exists' => false, 'reply_list' => null);
+
+        if ($headers->listHeadersExist()) {
+            $ret['exists'] = true;
+
+            /* See if the List-Post header provides an e-mail address for the
+             * list. */
+            if (($val = $headers->getValue('list-post')) &&
+                ($val != 'NO')) {
+                $ret['reply_list'] = $this->parseListHeaders($val, array('email' => true, 'raw' => true));
+            }
+        }
+
+        return $ret;
+    }
+
+    /**
+     * Builds a string containing a list of addresses.
+     *
+     * @param array $addrlist  The list of addresses from
+     *                         Horde_Mime_Address::parseAddressList().
+     * @param integer $addURL  The self URL.
+     * @param boolean $link    Link each address to the compose screen?
+     *
+     * @return string  String containing the formatted address list.
+     */
+    public function buildAddressLinks($addrlist, $addURL = null, $link = true)
+    {
+        global $prefs, $registry;
+
+        /* Make sure this is a valid object address field. */
+        if (empty($addrlist) || !is_array($addrlist)) {
+            return null;
+        }
+
+        $add_link = null;
+        $addr_array = array();
+        $mimp_view = ($_SESSION['imp']['view'] == 'mimp');
+
+        /* Set up the add address icon link if contact manager is
+         * available. */
+        if (!is_null($addURL) && $link && $prefs->getValue('add_source')) {
+            try {
+                $add_link = $registry->hasMethod('contacts/import')
+                    ? Horde_Util::addParameter($addURL, 'actionID', 'add_address')
+                    : null;
+            } catch (Horde_Exception $e) {}
+        }
+
+        foreach (Horde_Mime_Address::getAddressesFromObject($addrlist) as $ob) {
+            if (isset($ob['groupname'])) {
+                $group_array = array();
+                foreach ($ob['addresses'] as $ad) {
+                    if (empty($ad['address']) || empty($ad['inner'])) {
+                        continue;
+                    }
+
+                    $ret = $mimp_view
+                        ? $ad['display']
+                        : htmlspecialchars($ad['display']);
+
+                    if ($link) {
+                        $ret = Horde::link(IMP::composeLink(array('to' => $ad['address'])), sprintf(_("New Message to %s"), $ad['inner'])) . htmlspecialchars($ad['display']) . '</a>';
+                    }
+
+                    /* Append the add address icon to every address if contact
+                     * manager is available. */
+                    if ($add_link) {
+                        $curr_link = Horde_Util::addParameter($add_link, array('name' => $ad['personal'], 'address' => $ad['inner']));
+                        $ret .= Horde::link($curr_link, sprintf(_("Add %s to my Address Book"), $ad['inner'])) .
+                            Horde::img('addressbook_add.png', sprintf(_("Add %s to my Address Book"), $ad['inner'])) . '</a>';
+                    }
+
+                    $group_array[] = $ret;
+                }
+
+                if (!$mimp_view) {
+                    $ob['groupname'] = htmlspecialchars($ob['groupname']);
+                }
+
+                $addr_array[] = $ob['groupname'] . ':' . (count($group_array) ? ' ' . implode(', ', $group_array) : '');
+            } elseif (!empty($ob['address']) && !empty($ob['inner'])) {
+                $ret = $mimp_view
+                    ? $ob['display']
+                    : htmlspecialchars($ob['display']);
+
+                /* If this is an incomplete e-mail address, don't link to
+                 * anything. */
+                if (stristr($ob['host'], 'UNKNOWN') === false) {
+                    if ($link) {
+                        $ret = Horde::link(IMP::composeLink(array('to' => $ob['address'])), sprintf(_("New Message to %s"), $ob['inner'])) . htmlspecialchars($ob['display']) . '</a>';
+                    }
+
+                    /* Append the add address icon to every address if contact
+                     * manager is available. */
+                    if ($add_link) {
+                        $curr_link = Horde_Util::addParameter($add_link, array('name' => $ob['personal'], 'address' => $ob['inner']));
+                        $ret .= Horde::link($curr_link, sprintf(_("Add %s to my Address Book"), $ob['inner'])) .
+                            Horde::img('addressbook_add.png', sprintf(_("Add %s to my Address Book"), $ob['inner'])) . '</a>';
+                    }
+                }
+
+                $addr_array[] = $ret;
+            }
+        }
+
+        if ($_SESSION['imp']['view'] == 'mimp') {
+            return implode(', ', $addr_array);
+        }
+
+        /* If left with an empty address list ($ret), inform the user that the
+         * recipient list is purposely "undisclosed". */
+        if (empty($addr_array)) {
+            $ret = _("Undisclosed Recipients");
+        } else {
+            /* Build the address line. */
+            $addr_count = count($addr_array);
+            $ret = '<span class="nowrap">' . implode(',</span> <span class="nowrap">', $addr_array) . '</span>';
+            if ($link && $addr_count > 15) {
+                $ret = '<span>' .
+                    '<span onclick="[ this, this.next(), this.next(1) ].invoke(\'toggle\')" class="widget largeaddrlist">' . sprintf(_("[Show Addresses - %d recipients]"), $addr_count) . '</span>' .
+                    '<span onclick="[ this, this.previous(), this.next() ].invoke(\'toggle\')" class="widget largeaddrlist" style="display:none">' . _("[Hide Addresses]") . '</span>' .
+                    '<span style="display:none">' .
+                    $ret . '</span></span>';
+            }
+        }
+
+        return $ret;
+    }
+
+    /**
+     * Prints out a MIME summary (in HTML).
+     *
+     * @param array $summary  Summary information from
+     *                        IMP_Summary::getSummary().
+     * @param array $display  The fields to display (in this order).
+     * @param boolean $atc    Is this an attachment?
+     *
+     * @return string  The formatted summary string.
+     */
+    public function formatSummary($summary, $display, $atc = false)
+    {
+        $tmp_summary = array();
+        foreach ($display as $val) {
+            $tmp_summary[] = $summary[$val];
+        }
+        return '<div class="mimePartInfo' . ($atc ? ' mimePartInfoAtc' : '') . '"><div>' . implode(' ', $tmp_summary) . '</div></div>';
+    }
+
+    /**
+     * Prints out a MIME status message (in HTML).
+     *
+     * @param array $data  An array of information (as returned from
+                           Horde_Mime_Viewer::render()).
+     *
+     * @return string  The formatted status message string.
+     */
+    public function formatStatusMsg($data)
+    {
+        $out = '';
+
+        foreach ($data as $val) {
+            if (empty($val)) {
+                continue;
+            }
+
+            $out .= '<div><table class="mimeStatusMessageTable"' . (isset($val['id']) ? (' id="' . $val['id'] . '" ') : '') . '>';
+
+            /* If no image, simply print out the message. */
+            if (empty($val['icon'])) {
+                foreach ($val['text'] as $val) {
+                    $out .= '<tr><td>' . $val . '</td></tr>';
+                }
+            } else {
+                $out .= '<tr><td class="mimeStatusIcon">' . $val['icon'] . '</td><td><table>';
+                foreach ($val['text'] as $val) {
+                    $out .= '<tr><td>' . $val . '</td></tr>';
+                }
+                $out .= '</table></td></tr>';
+            }
+
+            $out .= '</table></div>';
+        }
+
+        return $out
+            ? '<div class="mimeStatusMessage">' . $out . '</div>'
+            : '';
+    }
+
+    /**
+     * Output inline message display for the imp and dimp views.
+     *
+     * @param object $imp_contents      The IMP_Contents object containing the
+     *                                  message data.
+     * @param integer $contents_mask    The mask needed for a
+     *                                  IMP_Contents::getSummary() call.
+     * @param array $part_info_display  The list of summary fields to display.
+     * @param string $show_parts        The value of the 'show_parts' pref.
+     *
+     * @return array  An array with the following keys:
+     * <pre>
+     * 'atc_parts' - (array) The list of attachment MIME IDs.
+     * 'display_ids' - (array) The list of display MIME IDs.
+     * 'js_onload' - (array) A list of javascript code to run onload.
+     * 'msgtext' - (string) The rendered HTML code.
+     * </pre>
+     */
+    public function getInlineOutput($imp_contents, $contents_mask,
+                                    $part_info_display, $show_parts)
+    {
+        $atc_parts = $display_ids = $js_onload = $wrap_ids = array();
+        $msgtext = '';
+        $parts_list = $imp_contents->getContentTypeMap();
+
+        if ($show_parts == 'all') {
+            $atc_parts = array_keys($parts_list);
+        }
+
+        foreach ($parts_list as $mime_id => $mime_type) {
+            if (in_array($mime_id, $display_ids, true)) {
+                continue;
+            }
+
+            if (!($render_mode = $imp_contents->canDisplay($mime_id, IMP_Contents::RENDER_INLINE | IMP_Contents::RENDER_INFO))) {
+                if ($imp_contents->isAttachment($mime_type)) {
+                    if ($show_parts == 'atc') {
+                        $atc_parts[] = $mime_id;
+                    }
+
+                    if ($GLOBALS['prefs']->getValue('atc_display')) {
+                        $msgtext .= $this->formatSummary($imp_contents->getSummary($mime_id, $contents_mask), $part_info_display, true);
+                    }
+                }
+                continue;
+            }
+
+            $render_part = $imp_contents->renderMIMEPart($mime_id, $render_mode);
+            if (($render_mode & IMP_Contents::RENDER_INLINE) &&
+                empty($render_part)) {
+                /* This meant that nothing was rendered - allow this part to
+                 * appear in the attachment list instead. */
+                if ($show_parts == 'atc') {
+                    $atc_parts[] = $mime_id;
+                }
+                continue;
+            }
+
+            reset($render_part);
+            while (list($id, $info) = each($render_part)) {
+                $display_ids[] = $id;
+
+                if (empty($info)) {
+                    continue;
+                }
+
+                while (count($wrap_ids) &&
+                       !Horde_Mime::isChild(end($wrap_ids), $id)) {
+                    array_pop($wrap_ids);
+                    $msgtext .= '</div>';
+                }
+
+                if (!empty($info['wrap'])) {
+                    $msgtext .= '<div class="' . $info['wrap'] . '">';
+                    $wrap_ids[] = $mime_id;
+                }
+
+                if (empty($info['attach'])) {
+                    $msgtext .= $this->formatSummary($imp_contents->getSummary($id, $contents_mask), $part_info_display) .
+                        $this->formatStatusMsg($info['status']) .
+                        '<div class="mimePartData">' . $info['data'] . '</div>';
+                } else {
+                    if ($show_parts == 'atc') {
+                        $atc_parts[] = $id;
+                    }
+
+                    if ($GLOBALS['prefs']->getValue('atc_display')) {
+                        $msgtext .= $this->formatSummary($imp_contents->getSummary($id, $contents_mask), $part_info_display, true);
+                    }
+                }
+
+                if (isset($info['js'])) {
+                    $js_onload = array_merge($js_onload, $info['js']);
+                }
+            }
+        }
+
+        while (count($wrap_ids)) {
+            $msgtext .= '</div>';
+            array_pop($wrap_ids);
+        }
+
+        if (!strlen($msgtext)) {
+            $msgtext = $this->formatStatusMsg(array(array('text' => array(_("There are no parts that can be shown inline.")))));
+        }
+
+        return array(
+            'atc_parts' => $atc_parts,
+            'display_ids' => $display_ids,
+            'js_onload' => $js_onload,
+            'msgtext' => $msgtext
+        );
+    }
+
+    /**
+     * Get the display subject (filtered, formatted, and linked).
+     *
+     * @param string $subject  The subject text.
+     *
+     * @return string  The display subject string.
+     */
+    public function getDisplaySubject($subject)
+    {
+        return Horde_Text_Filter::filter(IMP::filterText($subject), 'text2html', array('parselevel' => Horde_Text_Filter_Text2html::MICRO, 'class' => null, 'callback' => null));
+    }
+
+    /**
+     * Redirect to mailbox after deleting a message?
+     *
+     * @return boolean  Return to mailbox?
+     */
+    public function moveAfterAction()
+    {
+        return (($_SESSION['imp']['protocol'] != 'pop') &&
+                !IMP::hideDeletedMsgs($GLOBALS['imp_mbox']['mailbox']) &&
+                !$GLOBALS['prefs']->getValue('use_trash'));
+    }
+
+}
diff --git a/imp/lib/Ui/Search.php b/imp/lib/Ui/Search.php
new file mode 100644 (file)
index 0000000..7eb6581
--- /dev/null
@@ -0,0 +1,164 @@
+<?php
+/**
+ * The IMP_Ui_Search:: class is designed to provide a place to store common
+ * code shared among IMP's various UI views for the search page.
+ *
+ * Copyright 2009 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author  Michael Slusarz <slusarz@horde.org>
+ * @package IMP
+ */
+class IMP_Ui_Search
+{
+    /**
+     * Creates a search query.
+     *
+     * @param array $search  The list of search criteria.
+     *
+     * @return object  A search object (Horde_Imap_Client_Search_Query).
+     */
+    public function createQuery($search)
+    {
+        $query = new Horde_Imap_Client_Search_Query();
+
+        $search_array = array();
+        $search_fields = $GLOBALS['imp_search']->searchFields();
+        $flag_fields = $GLOBALS['imp_search']->flagFields();
+        $imp_flags = IMP_Imap_Flags::singleton();
+        $or_search = false;
+
+        foreach ($search as $rule) {
+            $ob = new Horde_Imap_Client_Search_Query();
+
+            $type = isset($search_fields[$rule->t]['type'])
+                ? $search_fields[$rule->t]['type']
+                : $rule->t;
+
+            switch ($type) {
+            case 'or':
+                $query->orSearch($search_array);
+                $search_array = array();
+                $or_search = true;
+                break;
+
+            case 'flag':
+                if (isset($flag_fields[$rule->v])) {
+                    $val = $imp_flags->parseFormId($rule->t);
+                    $ob->flag($val['flag'], $val['set']);
+                    $search_array[] = $ob;
+                }
+                break;
+
+            case 'header':
+                if (!empty($rule->v)) {
+                    $ob->headerText($rule->t, $rule->v, !empty($rule->n));
+                    $search_array[] = $ob;
+                }
+                break;
+
+            case 'customhdr':
+                if (!empty($rule->v)) {
+                    $ob->headerText($rule->v->h, $rule->v->s, !empty($rule->n));
+                    $search_array[] = $ob;
+                }
+                break;
+
+            case 'body':
+            case 'text':
+                if (!empty($rule->v)) {
+                    $ob->text($rule->c, $search_fields[$rule->t]['type'] == 'body', !empty($rule->n));
+                    $search_array[] = $ob;
+                }
+                break;
+
+            case 'date':
+                if (!empty($rule->v)) {
+                    $date = new Horde_Date(array('year' => $rule->v->y, 'month' => $rule->v->m + 1, 'mday' => $rule->v->d));
+                    $ob->dateSearch($date, ($rule->t == 'date_on') ? Horde_Imap_Client_Search_Query::DATE_ON : (($rule->t == 'date_until') ? Horde_Imap_Client_Search_Query::DATE_BEFORE : Horde_Imap_Client_Search_Query::DATE_SINCE));
+                    $search_array[] = $ob;
+                }
+                break;
+
+            case 'within':
+                /* Limited to day granularity because that is the technical
+                 * limit for IMAP servers without 'WITHIN' extension. */
+                if (!empty($rule->v)) {
+                    $secs = $rule->v->v * 60 * 60 * 24;
+
+                    switch ($rule->v->l) {
+                    case 'y':
+                        $secs *= 365;
+                        break;
+
+                    case 'm':
+                        $secs *= 30;
+                        break;
+                    }
+
+                    $ob->intervalSearch($secs, $rule->t == 'older' ? Horde_Imap_Client_Search_Query::INTERVAL_OLDER : Horde_Imap_Client_Search_Query::INTERVAL_YOUNGER);
+                    $search_array[] = $ob;
+                }
+                break;
+
+            case 'size':
+                if (!empty($rule->v)) {
+                    $ob->size(intval($rule->v), $rule->t == 'size_larger');
+                    $search_array[] = $ob;
+                }
+                break;
+            }
+        }
+
+        if ($or_search) {
+            $query->orSearch($search_array);
+        } else {
+            $query->andSearch($search_array);
+        }
+
+        return $query;
+    }
+
+    /**
+     * Create a search query from input gathered from the basic search script
+     * (imp/search-basic.php).
+     *
+     * @param string $mbox      The mailbox to search.
+     * @param string $criteria  The criteria to search.
+     * @param string $text      The criteria text.
+     * @param boolean $not      Should the criteria search be a not search?
+     * @param string $flag      A flag to search for.
+     *
+     * @return string  The search query ID.
+     */
+    public function processBasicSearch($mbox, $criteria, $text, $not, $flag)
+    {
+        $c_list = array();
+
+        if ($criteria) {
+            $search_fields = $GLOBALS['imp_search']->searchFields();
+            $tmp = new stdClass;
+            $tmp->t = $criteria;
+            $tmp->v = ($search_fields[$criteria]['type'] == 'size')
+                ? floatval($text) * 1024
+                : $text;
+            if ($search_fields[$criteria]['not']) {
+                $tmp->n = (bool)$not;
+            }
+            $c_list[] = $tmp;
+        }
+
+        if ($flag) {
+            $tmp = new stdClass;
+            $tmp->t = 'flag';
+            $tmp->v = $flag;
+            $c_list[] = $tmp;
+        }
+
+        /* Set the search in the IMP session. */
+        return $GLOBALS['imp_search']->createSearchQuery($this->createQuery($c_list), array($mbox), $c_list, _("Search Results"), IMP_Search::MBOX_PREFIX . IMP_Search::BASIC_SEARCH);
+    }
+
+}
index ce8105e..58cb717 100644 (file)
@@ -87,7 +87,7 @@ class IMP_Views_Compose
             $compose_html = $GLOBALS['prefs']->getValue('compose_html');
             $rte = true;
 
-            $imp_ui = new IMP_UI_Compose();
+            $imp_ui = new IMP_Ui_Compose();
             $imp_ui->initRTE(!$compose_html);
         }
 
index 5bb7a47..5cf732e 100644 (file)
@@ -270,7 +270,7 @@ class IMP_Views_ListMessages
         /* Get mailbox information. */
         $overview = $imp_mailbox->getMailboxArray($msglist, array('headers' => array('list-post', 'x-priority'), 'structure' => $GLOBALS['prefs']->getValue('atc_flag')));
         $charset = Horde_Nls::getCharset();
-        $imp_ui = new IMP_UI_Mailbox($folder);
+        $imp_ui = new IMP_Ui_Mailbox($folder);
         $no_flags_hook = false;
 
         /* Display message information. */
index e42b793..c53b125 100644 (file)
@@ -131,8 +131,8 @@ class IMP_Views_ShowMessage
         $envelope = $fetch_ret[$uid]['envelope'];
         $mime_headers = reset($fetch_ret[$uid]['headertext']);
 
-        /* Get the IMP_UI_Message:: object. */
-        $imp_ui = new IMP_UI_Message();
+        /* Get the IMP_Ui_Message:: object. */
+        $imp_ui = new IMP_Ui_Message();
 
         /* Develop the list of Headers to display now. Deal with the 'basic'
          * header information first since there are various manipulations
@@ -199,7 +199,7 @@ class IMP_Views_ShowMessage
 
         if ($preview) {
             /* Get minidate. */
-            $imp_mailbox_ui = new IMP_UI_Mailbox();
+            $imp_mailbox_ui = new IMP_Ui_Mailbox();
             $minidate = $imp_mailbox_ui->getDate($envelope['date']);
             if (empty($minidate)) {
                 $minidate = _("Unknown Date");
index 1521cf8..2805226 100644 (file)
@@ -109,7 +109,7 @@ $curr_time -= $curr_time % 60;
 $msgs = array();
 $sortpref = IMP::getSort($imp_mbox['mailbox']);
 
-$imp_ui = new IMP_UI_Mailbox($imp_mbox['mailbox']);
+$imp_ui = new IMP_Ui_Mailbox($imp_mbox['mailbox']);
 
 /* Build the array of message information. */
 $mbox_info = $imp_mailbox->getMailboxArray(range($pageOb['begin'], $pageOb['end']), array('headers' => array('x-priority')));
index dd792e8..c162f67 100644 (file)
@@ -678,7 +678,7 @@ if ($pageOb['msgcount']) {
 
 /* Initialize repetitively used variables. */
 $fromlinkstyle = $prefs->getValue('from_link');
-$imp_ui = new IMP_UI_Mailbox($imp_mbox['mailbox']);
+$imp_ui = new IMP_Ui_Mailbox($imp_mbox['mailbox']);
 
 /* Display message information. */
 $msgs = array();
index fac7d31..eaec9a0 100644 (file)
@@ -19,7 +19,7 @@ if (!$uid || !$folder) {
     exit;
 }
 
-$imp_ui = new IMP_UI_Message();
+$imp_ui = new IMP_Ui_Message();
 $readonly = $imp_imap->isReadOnly($folder);
 
 $args = array(
@@ -64,8 +64,8 @@ if (!$disable_compose) {
     );
     $compose_result = IMP_Views_Compose::showCompose($compose_args);
 
-    /* Init IMP_UI_Compose:: object. */
-    $imp_ui = new IMP_UI_Compose();
+    /* Init IMP_Ui_Compose:: object. */
+    $imp_ui = new IMP_Ui_Compose();
 
     /* Attach spellchecker & auto completer. */
     $imp_ui->attachAutoCompleter(array('to', 'cc', 'bcc'));
index cc53f9f..7f72f6a 100644 (file)
@@ -29,7 +29,7 @@ if (!$imp_mailbox->isValidIndex(false)) {
 }
 
 $imp_message = IMP_Message::singleton();
-$imp_ui = new IMP_UI_Message();
+$imp_ui = new IMP_Ui_Message();
 
 /* Determine if mailbox is readonly. */
 $readonly = $imp_imap->isReadOnly($imp_mbox['mailbox']);
index d709970..49f8a69 100644 (file)
@@ -68,7 +68,7 @@ $uid = $index_array['uid'];
 $indices_array = array($mailbox_name => array($uid));
 
 $imp_flags = IMP_Imap_Flags::singleton();
-$imp_ui = new IMP_UI_Message();
+$imp_ui = new IMP_Ui_Message();
 
 switch ($actionID) {
 case 'blacklist':
index b719ef9..d3c082c 100644 (file)
@@ -57,7 +57,7 @@ if ($new_mail) {
 $ids = $imp_search->runSearchQuery($query, $mailbox, Horde_Imap_Client::SORT_DATE, 1);
 
 if (!empty($ids)) {
-    $imp_ui = new IMP_UI_Mailbox($imp_mbox['mailbox']);
+    $imp_ui = new IMP_Ui_Mailbox($imp_mbox['mailbox']);
 
     $overview = $imp_mailbox->getMailboxArray(array_slice($ids, 0, 20), array('preview' => $prefs->getValue('preview_enabled')));
 
index 4a08e86..343098e 100644 (file)
@@ -27,7 +27,7 @@ if ($_SESSION['imp']['protocol'] == 'pop') {
 /* If search_basic_mbox is set, we are processing the search query. */
 $search_mailbox = Horde_Util::getFormData('search_basic_mbox');
 if ($search_mailbox) {
-    $imp_ui_search = new IMP_UI_Search();
+    $imp_ui_search = new IMP_Ui_Search();
     $id = $imp_ui_search->processBasicSearch($search_mailbox, Horde_Util::getFormData('search_criteria'), Horde_Util::getFormData('search_criteria_text'), Horde_Util::getFormData('search_criteria_not'), Horde_Util::getFormData('search_flags'));
 
     /* Redirect to the mailbox screen. */
index 8a5288b..e4ae7a1 100644 (file)
@@ -52,7 +52,7 @@ if (!empty($criteria)) {
     $folders = Horde_Util::getFormData('search_folders_form');
 
     /* Create the search query. */
-    $imp_ui_search = new IMP_UI_Search();
+    $imp_ui_search = new IMP_Ui_Search();
     $query = $imp_ui_search->createQuery($criteria);
 
     /* Save the search if requested. */
@@ -95,7 +95,7 @@ if ($subscribe || !Horde_Util::getFormData('show_unsub')) {
 
 list($raw_rows,) = $imp_imap_tree->build($mask);
 
-$imp_ui_folder = new IMP_UI_Folder();
+$imp_ui_folder = new IMP_Ui_Folder();
 $tree_imgs = $imp_ui_folder->getTreeImages($raw_rows);
 
 $folders = array();
index 20f2386..ddf048d 100644 (file)
@@ -74,7 +74,7 @@ if ($mode == 'thread') {
 }
 
 $charset = Horde_Nls::getCharset();
-$imp_ui = new IMP_UI_Message();
+$imp_ui = new IMP_Ui_Message();
 
 foreach ($loop_array as $mbox => $idxlist) {
     $fetch_res = $GLOBALS['imp_imap']->ob()->fetch($mbox, array(