From: Michael M Slusarz Date: Mon, 30 Nov 2009 07:36:38 +0000 (-0700) Subject: UI -> Ui X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=bc04a27cb087240e10845a6c22739ee82617b85a;p=horde.git UI -> Ui --- diff --git a/imp/ajax.php b/imp/ajax.php index c5917081c..f4eff0ced 100644 --- a/imp/ajax.php +++ b/imp/ajax.php @@ -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; diff --git a/imp/compose-dimp.php b/imp/compose-dimp.php index 3dbb9a487..962b1f1a1 100644 --- a/imp/compose-dimp.php +++ b/imp/compose-dimp.php @@ -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; diff --git a/imp/compose-mimp.php b/imp/compose-mimp.php index 8fee69590..610b09ffe 100644 --- a/imp/compose-mimp.php +++ b/imp/compose-mimp.php @@ -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')) { diff --git a/imp/compose.php b/imp/compose.php index 7d4daced8..a8c11a6c0 100644 --- a/imp/compose.php +++ b/imp/compose.php @@ -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 diff --git a/imp/folders.php b/imp/folders.php index a43f3523a..9209a061a 100644 --- a/imp/folders.php +++ b/imp/folders.php @@ -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. */ diff --git a/imp/lib/Auth.php b/imp/lib/Auth.php index 6f33859be..3198d0cd8 100644 --- a/imp/lib/Auth.php +++ b/imp/lib/Auth.php @@ -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(); diff --git a/imp/lib/Block/Newmail.php b/imp/lib/Block/Newmail.php index 9903bfd3a..03269aa02 100644 --- a/imp/lib/Block/Newmail.php +++ b/imp/lib/Block/Newmail.php @@ -36,7 +36,7 @@ class IMP_Block_Newmail extends Horde_Block $html .= '' . _("No unread messages") . ''; } 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 { diff --git a/imp/lib/Compose.php b/imp/lib/Compose.php index fa9833dbb..897b1d5eb 100644 --- a/imp/lib/Compose.php +++ b/imp/lib/Compose.php @@ -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) { diff --git a/imp/lib/Imap/Flags.php b/imp/lib/Imap/Flags.php index 40f0919ac..c8c4db236 100644 --- a/imp/lib/Imap/Flags.php +++ b/imp/lib/Imap/Flags.php @@ -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]; } diff --git a/imp/lib/LoginTasks/SystemTask/UpgradeFromImp4.php b/imp/lib/LoginTasks/SystemTask/UpgradeFromImp4.php index 5ba8b7ac5..c47b2d05f 100644 --- a/imp/lib/LoginTasks/SystemTask/UpgradeFromImp4.php +++ b/imp/lib/LoginTasks/SystemTask/UpgradeFromImp4.php @@ -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 diff --git a/imp/lib/Mime/Viewer/Plain.php b/imp/lib/Mime/Viewer/Plain.php index 7424e74d1..51256f320 100644 --- a/imp/lib/Mime/Viewer/Plain.php +++ b/imp/lib/Mime/Viewer/Plain.php @@ -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 index 516a6fbbc..000000000 --- a/imp/lib/UI/Compose.php +++ /dev/null @@ -1,214 +0,0 @@ - - * @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) ? '
' : ''; - $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
on - * enter instead of

. */ - // 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 index bb19e14f4..000000000 --- a/imp/lib/UI/Folder.php +++ /dev/null @@ -1,131 +0,0 @@ - - * @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: - *

-     * 'expand_url' - (string) The URL to use for expand/collapse links.
-     * 
- * - * @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']) - : ''; - $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) . '' . $dir2; - } - } else { - if (($elt['value'] == 'INBOX') && !$elt['peek']) { - $dir = '' . $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 = '' . $dir2; - } - } - - $line = ''; - $this->_moreMbox[$elt['level']] = $elt['peek']; - for ($i = 0; $i < $elt['level']; $i++) { - if ($this->_moreMbox[$i]) { - $line .= ''; - } else { - $line .= ''; - } - } - - return $line . $dir; - } - -} diff --git a/imp/lib/UI/Mailbox.php b/imp/lib/UI/Mailbox.php deleted file mode 100644 index 556b283aa..000000000 --- a/imp/lib/UI/Mailbox.php +++ /dev/null @@ -1,259 +0,0 @@ - - * @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: - *
-     * 'fullfrom' - (boolean) If true, returns 'fullfrom' information.
-     *              DEFAULT: false
-     * 'specialchars' - (string) If set, run 'from' return through
-     *                  htmlspecialchars() using the given charset.
-     * 
- * - * @return array An array of information: - *
-     * 'error' - (boolean)
-     * 'from' - (string)
-     * 'fullfrom' - (string)
-     * 'to' - (boolean)
-     * 
- */ - 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 index eb1ed7c44..000000000 --- a/imp/lib/UI/Message.php +++ /dev/null @@ -1,613 +0,0 @@ - - * @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: - *
-     * '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
-     * 
- * - * @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 . ''; - if (!empty($comments[1])) { - $output .= ' ' . $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 .= ' ' . $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']) . ''; - } - - /* 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'])) . ''; - } - - $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']) . ''; - } - - /* 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'])) . ''; - } - } - - $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 = '' . implode(', ', $addr_array) . ''; - if ($link && $addr_count > 15) { - $ret = '' . - '' . sprintf(_("[Show Addresses - %d recipients]"), $addr_count) . '' . - '' . - '' . - $ret . ''; - } - } - - 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 '
' . implode(' ', $tmp_summary) . '
'; - } - - /** - * 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 .= '
'; - - /* If no image, simply print out the message. */ - if (empty($val['icon'])) { - foreach ($val['text'] as $val) { - $out .= ''; - } - } else { - $out .= ''; - } - - $out .= '
' . $val . '
' . $val['icon'] . ''; - foreach ($val['text'] as $val) { - $out .= ''; - } - $out .= '
' . $val . '
'; - } - - return $out - ? '
' . $out . '
' - : ''; - } - - /** - * 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: - *
-     * '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.
-     * 
- */ - 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 .= ''; - } - - if (!empty($info['wrap'])) { - $msgtext .= '
'; - $wrap_ids[] = $mime_id; - } - - if (empty($info['attach'])) { - $msgtext .= $this->formatSummary($imp_contents->getSummary($id, $contents_mask), $part_info_display) . - $this->formatStatusMsg($info['status']) . - '
' . $info['data'] . '
'; - } 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 .= '
'; - 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 index 489ed7733..000000000 --- a/imp/lib/UI/Search.php +++ /dev/null @@ -1,164 +0,0 @@ - - * @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 index 000000000..2b427982c --- /dev/null +++ b/imp/lib/Ui/Compose.php @@ -0,0 +1,214 @@ + + * @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) ? '
' : ''; + $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
on + * enter instead of

. */ + // 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 index 000000000..b726089e3 --- /dev/null +++ b/imp/lib/Ui/Folder.php @@ -0,0 +1,131 @@ + + * @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: + *

+     * 'expand_url' - (string) The URL to use for expand/collapse links.
+     * 
+ * + * @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']) + : ''; + $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) . '' . $dir2; + } + } else { + if (($elt['value'] == 'INBOX') && !$elt['peek']) { + $dir = '' . $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 = '' . $dir2; + } + } + + $line = ''; + $this->_moreMbox[$elt['level']] = $elt['peek']; + for ($i = 0; $i < $elt['level']; $i++) { + if ($this->_moreMbox[$i]) { + $line .= ''; + } else { + $line .= ''; + } + } + + return $line . $dir; + } + +} diff --git a/imp/lib/Ui/Mailbox.php b/imp/lib/Ui/Mailbox.php new file mode 100644 index 000000000..9de3a8161 --- /dev/null +++ b/imp/lib/Ui/Mailbox.php @@ -0,0 +1,259 @@ + + * @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: + *
+     * 'fullfrom' - (boolean) If true, returns 'fullfrom' information.
+     *              DEFAULT: false
+     * 'specialchars' - (string) If set, run 'from' return through
+     *                  htmlspecialchars() using the given charset.
+     * 
+ * + * @return array An array of information: + *
+     * 'error' - (boolean)
+     * 'from' - (string)
+     * 'fullfrom' - (string)
+     * 'to' - (boolean)
+     * 
+ */ + 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 index 000000000..df70048ee --- /dev/null +++ b/imp/lib/Ui/Message.php @@ -0,0 +1,613 @@ + + * @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: + *
+     * '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
+     * 
+ * + * @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 . ''; + if (!empty($comments[1])) { + $output .= ' ' . $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 .= ' ' . $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']) . ''; + } + + /* 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'])) . ''; + } + + $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']) . ''; + } + + /* 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'])) . ''; + } + } + + $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 = '' . implode(', ', $addr_array) . ''; + if ($link && $addr_count > 15) { + $ret = '' . + '' . sprintf(_("[Show Addresses - %d recipients]"), $addr_count) . '' . + '' . + '' . + $ret . ''; + } + } + + 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 '
' . implode(' ', $tmp_summary) . '
'; + } + + /** + * 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 .= '
'; + + /* If no image, simply print out the message. */ + if (empty($val['icon'])) { + foreach ($val['text'] as $val) { + $out .= ''; + } + } else { + $out .= ''; + } + + $out .= '
' . $val . '
' . $val['icon'] . ''; + foreach ($val['text'] as $val) { + $out .= ''; + } + $out .= '
' . $val . '
'; + } + + return $out + ? '
' . $out . '
' + : ''; + } + + /** + * 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: + *
+     * '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.
+     * 
+ */ + 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 .= ''; + } + + if (!empty($info['wrap'])) { + $msgtext .= '
'; + $wrap_ids[] = $mime_id; + } + + if (empty($info['attach'])) { + $msgtext .= $this->formatSummary($imp_contents->getSummary($id, $contents_mask), $part_info_display) . + $this->formatStatusMsg($info['status']) . + '
' . $info['data'] . '
'; + } 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 .= '
'; + 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 index 000000000..7eb6581dc --- /dev/null +++ b/imp/lib/Ui/Search.php @@ -0,0 +1,164 @@ + + * @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/Views/Compose.php b/imp/lib/Views/Compose.php index ce8105e03..58cb717d0 100644 --- a/imp/lib/Views/Compose.php +++ b/imp/lib/Views/Compose.php @@ -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); } diff --git a/imp/lib/Views/ListMessages.php b/imp/lib/Views/ListMessages.php index 5bb7a4777..5cf732eef 100644 --- a/imp/lib/Views/ListMessages.php +++ b/imp/lib/Views/ListMessages.php @@ -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. */ diff --git a/imp/lib/Views/ShowMessage.php b/imp/lib/Views/ShowMessage.php index e42b7931b..c53b12515 100644 --- a/imp/lib/Views/ShowMessage.php +++ b/imp/lib/Views/ShowMessage.php @@ -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"); diff --git a/imp/mailbox-mimp.php b/imp/mailbox-mimp.php index 1521cf8bf..28052264b 100644 --- a/imp/mailbox-mimp.php +++ b/imp/mailbox-mimp.php @@ -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'))); diff --git a/imp/mailbox.php b/imp/mailbox.php index dd792e8a2..c162f672e 100644 --- a/imp/mailbox.php +++ b/imp/mailbox.php @@ -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(); diff --git a/imp/message-dimp.php b/imp/message-dimp.php index fac7d31ad..eaec9a0da 100644 --- a/imp/message-dimp.php +++ b/imp/message-dimp.php @@ -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')); diff --git a/imp/message-mimp.php b/imp/message-mimp.php index cc53f9f41..7f72f6a90 100644 --- a/imp/message-mimp.php +++ b/imp/message-mimp.php @@ -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']); diff --git a/imp/message.php b/imp/message.php index d70997092..49f8a69c7 100644 --- a/imp/message.php +++ b/imp/message.php @@ -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': diff --git a/imp/rss.php b/imp/rss.php index b719ef924..d3c082ca0 100644 --- a/imp/rss.php +++ b/imp/rss.php @@ -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'))); diff --git a/imp/search-basic.php b/imp/search-basic.php index 4a08e8679..343098ef3 100644 --- a/imp/search-basic.php +++ b/imp/search-basic.php @@ -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. */ diff --git a/imp/search.php b/imp/search.php index 8a5288b88..e4ae7a1ec 100644 --- a/imp/search.php +++ b/imp/search.php @@ -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(); diff --git a/imp/thread.php b/imp/thread.php index 20f238605..ddf048d91 100644 --- a/imp/thread.php +++ b/imp/thread.php @@ -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(