Overview

Packages

  • IMP
  • None

Classes

  • IMP
  • IMP_Ajax_Application
  • IMP_Ajax_Imple_ContactAutoCompleter
  • IMP_Ajax_Imple_PassphraseDialog
  • IMP_Ajax_Queue
  • IMP_Api
  • IMP_Auth
  • IMP_Block_Newmail
  • IMP_Block_Summary
  • IMP_Compose
  • IMP_Compose_Exception
  • IMP_Compose_Stationery
  • IMP_Contents
  • IMP_Crypt_Pgp
  • IMP_Crypt_Smime
  • IMP_Dimp
  • IMP_Exception
  • IMP_Factory_AuthImap
  • IMP_Factory_Compose
  • IMP_Factory_Contents
  • IMP_Factory_Flags
  • IMP_Factory_Identity
  • IMP_Factory_Imap
  • IMP_Factory_Imaptree
  • IMP_Factory_Mail
  • IMP_Factory_Mailbox
  • IMP_Factory_MailboxList
  • IMP_Factory_MimeViewer
  • IMP_Factory_Pgp
  • IMP_Factory_Quota
  • IMP_Factory_Search
  • IMP_Factory_Sentmail
  • IMP_Factory_Smime
  • IMP_Filter
  • IMP_Flag_Base
  • IMP_Flag_Imap
  • IMP_Flag_Imap_Answered
  • IMP_Flag_Imap_Deleted
  • IMP_Flag_Imap_Draft
  • IMP_Flag_Imap_Flagged
  • IMP_Flag_Imap_Forwarded
  • IMP_Flag_Imap_Junk
  • IMP_Flag_Imap_NotJunk
  • IMP_Flag_Imap_Seen
  • IMP_Flag_System_Attachment
  • IMP_Flag_System_Encrypted
  • IMP_Flag_System_HighPriority
  • IMP_Flag_System_List
  • IMP_Flag_System_LowPriority
  • IMP_Flag_System_Match_Address
  • IMP_Flag_System_Match_Flag
  • IMP_Flag_System_Match_Header
  • IMP_Flag_System_Personal
  • IMP_Flag_System_Signed
  • IMP_Flag_System_Unseen
  • IMP_Flag_User
  • IMP_Flags
  • IMP_Imap
  • IMP_Imap_Acl
  • IMP_Imap_Exception
  • IMP_Imap_PermanentFlags
  • IMP_Imap_Thread
  • IMP_Imap_Tree
  • IMP_Indices
  • IMP_Indices_Form
  • IMP_LoginTasks_SystemTask_GarbageCollection
  • IMP_LoginTasks_SystemTask_Upgrade
  • IMP_LoginTasks_SystemTask_UpgradeAuth
  • IMP_LoginTasks_Task_Autocreate
  • IMP_LoginTasks_Task_DeleteAttachmentsMonthly
  • IMP_LoginTasks_Task_DeleteSentmailMonthly
  • IMP_LoginTasks_Task_FilterOnLogin
  • IMP_LoginTasks_Task_PurgeSentmail
  • IMP_LoginTasks_Task_PurgeSpam
  • IMP_LoginTasks_Task_PurgeTrash
  • IMP_LoginTasks_Task_RecoverDraft
  • IMP_LoginTasks_Task_RenameSentmailMonthly
  • IMP_Mailbox
  • IMP_Mailbox_List
  • IMP_Mailbox_List_Track
  • IMP_Maillog
  • IMP_Menu_Dimp
  • IMP_Message
  • IMP_Mime_Status
  • IMP_Mime_Viewer_Alternative
  • IMP_Mime_Viewer_Appledouble
  • IMP_Mime_Viewer_Audio
  • IMP_Mime_Viewer_Enriched
  • IMP_Mime_Viewer_Externalbody
  • IMP_Mime_Viewer_Html
  • IMP_Mime_Viewer_Images
  • IMP_Mime_Viewer_Itip
  • IMP_Mime_Viewer_Mdn
  • IMP_Mime_Viewer_Partial
  • IMP_Mime_Viewer_Pdf
  • IMP_Mime_Viewer_Pgp
  • IMP_Mime_Viewer_Plain
  • IMP_Mime_Viewer_Related
  • IMP_Mime_Viewer_Rfc822
  • IMP_Mime_Viewer_Smil
  • IMP_Mime_Viewer_Smime
  • IMP_Mime_Viewer_Status
  • IMP_Mime_Viewer_Vcard
  • IMP_Mime_Viewer_Video
  • IMP_Mime_Viewer_Zip
  • IMP_Notification_Event_Status
  • IMP_Notification_Handler_Decorator_ImapAlerts
  • IMP_Notification_Handler_Decorator_NewmailNotify
  • IMP_Notification_Listener_AjaxStatus
  • Imp_Prefs_Identity
  • IMP_Prefs_Ui
  • IMP_Quota
  • IMP_Quota_Base
  • IMP_Quota_Command
  • IMP_Quota_Hook
  • IMP_Quota_Imap
  • IMP_Quota_Maildir
  • IMP_Quota_Mdaemon
  • IMP_Quota_Mercury32
  • IMP_Quota_Null
  • IMP_Quota_Sql
  • IMP_Search
  • IMP_Search_Element
  • IMP_Search_Element_Attachment
  • IMP_Search_Element_Autogenerated
  • IMP_Search_Element_Bulk
  • IMP_Search_Element_Contacts
  • IMP_Search_Element_Date
  • IMP_Search_Element_Flag
  • IMP_Search_Element_Header
  • IMP_Search_Element_Mailinglist
  • IMP_Search_Element_Or
  • IMP_Search_Element_Personal
  • IMP_Search_Element_Recipient
  • IMP_Search_Element_Size
  • IMP_Search_Element_Text
  • IMP_Search_Element_Within
  • IMP_Search_Filter
  • IMP_Search_Filter_Attachment
  • IMP_Search_Filter_Autogenerated
  • IMP_Search_Filter_Builtin
  • IMP_Search_Filter_Bulk
  • IMP_Search_Filter_Contacts
  • IMP_Search_Filter_Mailinglist
  • IMP_Search_Filter_Personal
  • IMP_Search_Query
  • IMP_Search_Vfolder
  • IMP_Search_Vfolder_Builtin
  • IMP_Search_Vfolder_Vinbox
  • IMP_Search_Vfolder_Vtrash
  • IMP_Sentmail
  • IMP_Sentmail_Base
  • IMP_Sentmail_Null
  • IMP_Sentmail_Sql
  • IMP_Spam
  • IMP_Test
  • IMP_Tree_Flist
  • IMP_Tree_Jquerymobile
  • IMP_Tree_Simplehtml
  • IMP_Ui_Compose
  • IMP_Ui_Editor
  • IMP_Ui_Folder
  • IMP_Ui_Headers
  • IMP_Ui_Imageview
  • IMP_Ui_Mailbox
  • IMP_Ui_Message
  • IMP_Ui_Mimp
  • IMP_Ui_Search
  • IMP_Views_Compose
  • IMP_Views_ListMessages
  • IMP_Views_ShowMessage
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * The IMP_Mime_Viewer_Alternative class renders out messages from
  4:  * multipart/alternative content types (RFC 2046 [5.1.4]).
  5:  *
  6:  * Copyright 2002-2012 Horde LLC (http://www.horde.org/)
  7:  *
  8:  * See the enclosed file COPYING for license information (GPL). If you
  9:  * did not receive this file, see http://www.horde.org/licenses/gpl.
 10:  *
 11:  * @author   Michael Slusarz <slusarz@horde.org>
 12:  * @category Horde
 13:  * @license  http://www.horde.org/licenses/gpl GPL
 14:  * @package  IMP
 15:  */
 16: class IMP_Mime_Viewer_Alternative extends Horde_Mime_Viewer_Base
 17: {
 18:     /**
 19:      * This driver's display capabilities.
 20:      *
 21:      * @var array
 22:      */
 23:     protected $_capability = array(
 24:         'full' => true,
 25:         'info' => false,
 26:         'inline' => true,
 27:         'raw' => false
 28:     );
 29: 
 30:     /**
 31:      * Return the full rendered version of the Horde_Mime_Part object.
 32:      *
 33:      * @return array  See parent::render().
 34:      */
 35:     protected function _render()
 36:     {
 37:         return $this->_IMPrender(false);
 38:     }
 39: 
 40:     /**
 41:      * Return the rendered inline version of the Horde_Mime_Part object.
 42:      *
 43:      * @return array  See parent::render().
 44:      */
 45:     protected function _renderInline()
 46:     {
 47:         return $this->_IMPrender(true);
 48:     }
 49: 
 50:     /**
 51:      * Render out the currently set contents.
 52:      *
 53:      * @param boolean $inline        Are we viewing inline?
 54:      * @param boolean $prefer_plain  Prefer text/plain part over all others.
 55:      *
 56:      * @return array  See parent::render().
 57:      */
 58:     protected function _IMPrender($inline, $prefer_plain = null)
 59:     {
 60:         $base_id = $this->_mimepart->getMimeId();
 61:         $subparts = $this->_mimepart->contentTypeMap();
 62: 
 63:         $base_ids = $display_ids = $ret = array();
 64: 
 65:         if (is_null($prefer_plain) &&
 66:             ($GLOBALS['prefs']->getValue('alternative_display') == 'text')) {
 67:             $prefer_plain = true;
 68:         }
 69: 
 70:         /* Look for a displayable part. RFC: show the LAST choice that can be
 71:          * displayed inline. If an alternative is itself a multipart, the user
 72:          * agent is allowed to show that alternative, an earlier alternative,
 73:          * or both. If we find a multipart alternative that contains at least
 74:          * one viewable part, we will display all viewable subparts of that
 75:          * alternative. */
 76:         $imp_contents = $this->getConfigParam('imp_contents');
 77:         foreach ($subparts as $mime_id => $type) {
 78:             $ret[$mime_id] = null;
 79:             if ((strcmp($base_id, $mime_id) !== 0) &&
 80:                 $imp_contents->canDisplay($mime_id, $inline ? IMP_Contents::RENDER_INLINE : IMP_Contents::RENDER_FULL) &&
 81:                 /* Show HTML if $prefer_plain is false-y or if
 82:                  * alternative_display is not 'html'. */
 83:                 (!$prefer_plain ||
 84:                  (($type != 'text/html') &&
 85:                   (strpos($type, 'text/') === 0)))) {
 86:                 $display_ids[strval($mime_id)] = true;
 87:             }
 88:         }
 89: 
 90:         /* If we found no IDs, return now. */
 91:         if (empty($display_ids)) {
 92:             if ($prefer_plain && (IMP::getViewMode() == 'mimp')) {
 93:                 return $this->_IMPRender($inline, false);
 94:             }
 95: 
 96:             $ret[$base_id] = array(
 97:                 'data' => '',
 98:                 'status' => new IMP_Mime_Status(
 99:                     _("There are no alternative parts that can be displayed inline.")
100:                 ),
101:                 'type' => 'text/html; charset=' . $this->getConfigParam('charset')
102:             );
103:             return $ret;
104:         }
105: 
106:         /* If the last viewable message exists in a subpart, back up to the
107:          * base multipart and display all viewable parts in that multipart.
108:          * Else, display the single part. */
109:         end($display_ids);
110:         $curr_id = key($display_ids);
111:         while (!is_null($curr_id) && (strcmp($base_id, $curr_id) !== 0)) {
112:             if (isset($subparts[$curr_id])) {
113:                 $disp_id = $curr_id;
114:             }
115:             $curr_id = Horde_Mime::mimeIdArithmetic($curr_id, 'up');
116:         }
117: 
118:         /* At this point, $ret contains stubs for all parts living in the base
119:          * alternative part.
120:          * Go through all subparts of displayable part and make sure all parts
121:          * are rendered.  Parts not rendered will be marked as not being
122:          * handled by this viewer (Bug #9365). */
123:         $render_part = $this->_mimepart->getPart($disp_id);
124:         $need_render = $subparts = $render_part->contentTypeMap();
125: 
126:         foreach (array_keys($subparts) as $val) {
127:             if (isset($display_ids[$val]) && isset($need_render[$val])) {
128:                 $render = $this->getConfigParam('imp_contents')->renderMIMEPart($val, $inline ? IMP_Contents::RENDER_INLINE : IMP_Contents::RENDER_FULL);
129: 
130:                 foreach (array_keys($render) as $id) {
131:                     unset($need_render[$id]);
132: 
133:                     if (!$inline) {
134:                         if (!is_null($render[$id])) {
135:                             return array($base_id => $render[$id]);
136:                         }
137:                     } else {
138:                         $ret[$id] = $render[$id];
139:                     }
140:                 }
141:             }
142:         }
143: 
144:         unset($need_render[$disp_id]);
145:         foreach (array_keys($need_render) as $val) {
146:             unset($ret[$val]);
147:         }
148: 
149:         return $inline
150:             ? $ret
151:             : null;
152:     }
153: 
154: }
155: 
API documentation generated by ApiGen