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:  * Dynamic (dimp) message display logic.
  4:  *
  5:  * Copyright 2005-2012 Horde LLC (http://www.horde.org/)
  6:  *
  7:  * See the enclosed file COPYING for license information (GPL). If you
  8:  * did not receive this file, see http://www.horde.org/licenses/gpl.
  9:  *
 10:  * @author   Michael Slusarz <slusarz@horde.org>
 11:  * @category Horde
 12:  * @license  http://www.horde.org/licenses/gpl GPL
 13:  * @package  IMP
 14:  */
 15: class IMP_Views_ShowMessage
 16: {
 17:     /**
 18:      * Builds a list of addresses from header information.
 19:      *
 20:      * @param array $addrlist  The list of addresses from
 21:      *                         Horde_Mime_Address::parseAddressList().
 22:      *
 23:      * @return array  Array with the following keys: inner, personal, raw.
 24:      */
 25:     private function _buildAddressList($addrlist)
 26:     {
 27:         if (empty($addrlist) || !is_array($addrlist)) {
 28:             return;
 29:         }
 30: 
 31:         $addr_array = array();
 32: 
 33:         foreach (Horde_Mime_Address::getAddressesFromObject($addrlist, array('charset' => 'UTF-8')) as $ob) {
 34:             if (!empty($ob['inner'])) {
 35:                 try {
 36:                     $tmp = array('raw' => Horde::callHook('dimp_addressformatting', array($ob), 'imp'));
 37:                 } catch (Horde_Exception_HookNotSet $e) {
 38:                     $tmp = array('inner' => $ob['inner']);
 39:                     if (!empty($ob['personal'])) {
 40:                         $tmp['personal'] = $ob['personal'];
 41:                     }
 42:                 }
 43:                 $addr_array[] = $tmp;
 44:             }
 45:         }
 46: 
 47:         return $addr_array;
 48:     }
 49: 
 50:     /**
 51:      * Create the object used to display the message.
 52:      *
 53:      * @param array $args  Configuration parameters:
 54:      *   - headers: (array) The headers desired in the returned headers array
 55:      *              (only used with non-preview view).
 56:      *   - mailbox: (IMP_Mailbox) The mailbox of the message.
 57:      *   - preview: (boolean) Is this the preview view?
 58:      *   - uid: (integer) The UID of the message.
 59:      *
 60:      * @return array  Array with the following keys:
 61:      *   - atc_download: The download all link
 62:      *   - atc_label: The label to use for Attachments
 63:      *   - atc_list: The list (HTML code) of attachments
 64:      *   - bcc (FULL): The Bcc addresses
 65:      *   - cc: The CC addresses
 66:      *   - from: The From addresses
 67:      *   - headers (FULL): An array of headers (not including basic headers)
 68:      *   - js: Javascript code to run on display
 69:      *   - list_info (FULL): List information.
 70:      *   - localdate (PREVIEW): The date formatted to the user's timezone
 71:      *   - log: Log information
 72:      *   - mbox: The mailbox (base64url encoded)
 73:      *   - msgtext: The text of the message
 74:      *   - priority (FULL): The priority of the message (low, high, normal)
 75:      *   - replyTo (FULL): The Reply-to addresses
 76:      *   - save_as: The save link
 77:      *   - subject: The subject
 78:      *   - title (FULL): The title of the page
 79:      *   - to: The To addresses
 80:      *   - uid: The message UID
 81:      *
 82:      * @throws IMP_Exception
 83:      */
 84:     public function showMessage($args)
 85:     {
 86:         $preview = !empty($args['preview']);
 87:         $mailbox = $args['mailbox'];
 88:         $uid = $args['uid'];
 89: 
 90:         $result = array(
 91:             'js' => array(),
 92:             'mbox' => $mailbox->form_to,
 93:             'uid' => $uid
 94:         );
 95: 
 96:         /* Set the current time zone. */
 97:         $GLOBALS['registry']->setTimeZone();
 98: 
 99:         /* Get envelope/header information. We don't use flags in this
100:          * view. */
101:         try {
102:             $query = new Horde_Imap_Client_Fetch_Query();
103:             $query->envelope();
104: 
105:             $imp_imap = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create();
106:             $fetch_ret = $imp_imap->fetch($mailbox, $query, array(
107:                 'ids' => $imp_imap->getIdsOb($uid)
108:             ));
109: 
110:             if (!isset($fetch_ret[$uid])) {
111:                 throw new Exception();
112:             }
113: 
114:             $imp_contents = $GLOBALS['injector']->getInstance('IMP_Factory_Contents')->create($mailbox->getIndicesOb($uid));
115:         } catch (Exception $e) {
116:             throw new IMP_Exception(_("Requested message not found."));
117:         }
118: 
119:         $envelope = $fetch_ret[$uid]->getEnvelope();
120:         $mime_headers = $imp_contents->getHeaderAndMarkAsSeen();
121:         $headers = array();
122: 
123:         /* Initialize variables. */
124:         if (!$preview) {
125:             $imp_hdr_ui = new IMP_Ui_Headers();
126:         }
127:         $imp_ui = new IMP_Ui_Message();
128: 
129:         /* Develop the list of Headers to display now. Deal with the 'basic'
130:          * header information first since there are various manipulations
131:          * done to them. */
132:         $basic_headers = $imp_ui->basicHeaders();
133:         if (empty($args['headers'])) {
134:             $args['headers'] = array('from', 'date', 'to', 'cc', 'bcc');
135:         }
136: 
137:         $headers_list = array_intersect_key($basic_headers, array_flip($args['headers']));
138: 
139:         /* Build From/To/Cc/Bcc/Reply-To links. */
140:         foreach (array('from', 'to', 'cc', 'bcc', 'reply-to') as $val) {
141:             if (isset($headers_list[$val]) &&
142:                 (!$preview || ($val != 'reply-to'))) {
143:                 $tmp = $this->_buildAddressList(($val == 'reply-to') ? $envelope->reply_to : $envelope->$val);
144:                 if (!empty($tmp)) {
145:                     $result[$val] = $tmp;
146:                 } elseif ($val == 'to') {
147:                     $result[$val] = array(array('raw' => _("Undisclosed Recipients")));
148:                 }
149:                 if ($preview) {
150:                     unset($headers_list[$val]);
151:                 }
152:             }
153:         }
154: 
155:         /* Build the rest of the headers. */
156:         foreach ($headers_list as $head => $str) {
157:             if ($val = $mime_headers->getValue($head)) {
158:                 if ($head == 'date') {
159:                     /* Add local time to date header. */
160:                     $val = htmlspecialchars($imp_ui->getLocalTime($envelope->date));
161:                     if ($preview) {
162:                         $result['localdate'] = $val;
163:                     }
164:                 } elseif (!$preview) {
165:                     $val = htmlspecialchars($val);
166:                 }
167: 
168:                 if (!$preview) {
169:                     $headers[$head] = array('id' => Horde_String::ucfirst($head), 'name' => $str, 'value' => $val);
170:                 }
171:             }
172:         }
173: 
174:         if (empty($result['reply-to']) ||
175:             (Horde_Mime_Address::bareAddress($result['from'][0]['inner']) == Horde_Mime_Address::bareAddress($result['reply-to'][0]['inner']))) {
176:             unset($result['reply-to'], $headers['reply-to']);
177:         }
178: 
179:         /* JS requires camelized name for reply-to. */
180:         if (!$preview && isset($headers['reply-to'])) {
181:             $result['replyTo'] = $result['reply-to'];
182:             $headers['reply-to']['id'] = 'ReplyTo';
183:             unset($result['reply-to']);
184:         }
185: 
186:         /* Grab maillog information. */
187:         if (!empty($GLOBALS['conf']['maillog']['use_maillog']) &&
188:             ($tmp = IMP_Dimp::getMsgLogInfo($envelope->message_id))) {
189:             $result['log'] = $tmp;
190:         }
191: 
192:         if (!$preview) {
193:             /* Display the user-specified headers for the current identity. */
194:             $user_hdrs = $imp_ui->getUserHeaders();
195:             foreach ($user_hdrs as $user_hdr) {
196:                 $user_val = $mime_headers->getValue($user_hdr);
197:                 if (!empty($user_val)) {
198:                     $headers[] = array('name' => $user_hdr, 'value' => htmlspecialchars($user_val));
199:                 }
200:             }
201:             $result['headers'] = array_values($headers);
202:         }
203: 
204:         /* Process the subject. */
205:         $subject = $mime_headers->getValue('subject');
206:         if ($subject) {
207:             $result['subject'] = $imp_ui->getDisplaySubject($subject);
208:             if (!$preview) {
209:                 $result['title'] = htmlspecialchars($subject);
210:             }
211:         } else {
212:             $result['subject'] = htmlspecialchars(_("[No Subject]"));
213:             if (!$preview) {
214:                 $result['title'] = htmlspecialchars(_("[No Subject]"));
215:             }
216:         }
217: 
218:         /* Get message priority. */
219:         if (!$preview) {
220:             $result['priority'] = $imp_hdr_ui->getPriority($mime_headers);
221:         }
222: 
223:         // Create message text and attachment list.
224:         $result['msgtext'] = '';
225:         $show_parts = $GLOBALS['prefs']->getValue('parts_display');
226: 
227:         $contents_mask = IMP_Contents::SUMMARY_BYTES |
228:             IMP_Contents::SUMMARY_SIZE |
229:             IMP_Contents::SUMMARY_ICON |
230:             IMP_Contents::SUMMARY_DESCRIP_LINK |
231:             IMP_Contents::SUMMARY_DOWNLOAD |
232:             IMP_Contents::SUMMARY_DOWNLOAD_ZIP |
233:             IMP_Contents::SUMMARY_PRINT_STUB;
234: 
235:         $part_info = $part_info_display = array('icon', 'description', 'size', 'download', 'download_zip');
236:         $part_info_display[] = 'print';
237: 
238:         /* Allow stripping of attachments? */
239:         if ($GLOBALS['prefs']->getValue('strip_attachments')) {
240:             $contents_mask |= IMP_Contents::SUMMARY_STRIP_STUB;
241:             $part_info[] = 'strip';
242:             $part_info_display[] = 'strip';
243:         }
244: 
245:         /* Do MDN processing now. */
246:         if ($imp_ui->MDNCheck($mailbox, $uid, $mime_headers)) {
247:             $status = new IMP_Mime_Status(array(
248:                 _("The sender of this message is requesting notification from you when you have read this message."),
249:                 sprintf(_("Click %s to send the notification message."), Horde::link('#', '', '', '', '', '', '', array('id' => 'send_mdn_link')) . _("HERE") . '</a>')
250:             ));
251:             $status->domid('sendMdnMessage');
252:             $result['msgtext'] .= strval($status);
253:         }
254: 
255:         /* Build body text. This needs to be done before we build the
256:          * attachment list. */
257:         $inlineout = $imp_contents->getInlineOutput(array(
258:             'mask' => $contents_mask,
259:             'part_info_display' => $part_info_display,
260:             'show_parts' => $show_parts
261:         ));
262: 
263:         $result['js'] = array_merge($result['js'], $inlineout['js_onload']);
264:         $result['msgtext'] .= $inlineout['msgtext'];
265: 
266:         if (count($inlineout['atc_parts']) ||
267:             (($show_parts == 'all') && count($inlineout['display_ids']) > 2)) {
268:             $result['atc_label'] = ($show_parts == 'all')
269:                 ? _("Parts")
270:                 : sprintf(ngettext("%d Attachment", "%d Attachments", count($inlineout['atc_parts'])), count($inlineout['atc_parts']));
271:             if (count($inlineout['atc_parts']) > 2) {
272:                 $result['atc_download'] = Horde::link($imp_contents->urlView($imp_contents->getMIMEMessage(), 'download_all')) . '[' . _("Save All") . ']</a>';
273:             }
274:         }
275: 
276:         /* Show attachment information in headers? */
277:         if (!empty($inlineout['atc_parts'])) {
278:             $tmp = '';
279: 
280:             if ($show_parts == 'all') {
281:                 array_unshift($part_info, 'id');
282:             }
283: 
284:             foreach ($inlineout['atc_parts'] as $id) {
285:                 $summary = $imp_contents->getSummary($id, $contents_mask);
286:                 $tmp .= '<tr>';
287:                 foreach ($part_info as $val) {
288:                     $tmp .= '<td' .
289:                         (strlen($summary[$val]) ? '' : ' class="partlistempty"') .
290:                         '>' . $summary[$val] . '</td>';
291:                 }
292:                 $tmp .= '</tr>';
293:             }
294: 
295:             $result['atc_list'] = $tmp;
296:         }
297: 
298:         $result['save_as'] = Horde::downloadUrl(htmlspecialchars_decode($result['subject']), array_merge(array('actionID' => 'save_message'), $mailbox->urlParams($uid)));
299: 
300:         if ($preview) {
301:             try {
302:                 $res = Horde::callHook('dimp_previewview', array($result), 'imp');
303:                 if (!empty($res)) {
304:                     $result = $res[0];
305:                     $result['js'] = array_merge($result['js'], $res[1]);
306:                 }
307:             } catch (Horde_Exception_HookNotSet $e) {}
308: 
309:             /* Need to grab cached inline scripts. */
310:             Horde::startBuffer();
311:             Horde::outputInlineScript(true);
312:             if ($js_inline = Horde::endBuffer()) {
313:                 $result['js'][] = $js_inline;
314:             }
315: 
316:             $result['save_as'] = strval($result['save_as']->setRaw(true));
317:         } else {
318:             try {
319:                 $result = Horde::callHook('dimp_messageview', array($result), 'imp');
320:             } catch (Horde_Exception_HookNotSet $e) {}
321: 
322:             $result['list_info'] = $imp_ui->getListInformation($mime_headers);
323:         }
324: 
325:         if (empty($result['js'])) {
326:             unset($result['js']);
327:         }
328: 
329:         /* Add changed flag information. */
330:         if ($imp_imap->imap) {
331:             $status = $imp_imap->status($mailbox, Horde_Imap_Client::STATUS_PERMFLAGS);
332:             if (in_array(Horde_Imap_Client::FLAG_SEEN, $status['permflags'])) {
333:                 $GLOBALS['injector']->getInstance('IMP_Ajax_Queue')->flag(array(Horde_Imap_Client::FLAG_SEEN), true, $mailbox->getIndicesOb($uid));
334:             }
335:         }
336: 
337:         return $result;
338:     }
339: 
340: }
341: 
API documentation generated by ApiGen