1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15: class IMP_Views_ShowMessage
16: {
17: 18: 19: 20: 21: 22: 23: 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: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 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:
97: $GLOBALS['registry']->setTimeZone();
98:
99: 100:
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:
124: if (!$preview) {
125: $imp_hdr_ui = new IMP_Ui_Headers();
126: }
127: $imp_ui = new IMP_Ui_Message();
128:
129: 130: 131:
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:
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:
156: foreach ($headers_list as $head => $str) {
157: if ($val = $mime_headers->getValue($head)) {
158: if ($head == 'date') {
159:
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:
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:
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:
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:
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:
219: if (!$preview) {
220: $result['priority'] = $imp_hdr_ui->getPriority($mime_headers);
221: }
222:
223:
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:
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:
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: 256:
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:
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:
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:
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: