1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: 15: 16: 17: 18: 19: 20: 21: 22:
23: class IMP_Ajax_Application_ShowMessage
24: {
25: 26: 27: 28: 29:
30: protected $_contents;
31:
32: 33: 34: 35: 36:
37: protected $_envelope;
38:
39: 40: 41: 42: 43:
44: protected $_indices;
45:
46: 47: 48: 49: 50:
51: protected $_peek;
52:
53: 54: 55: 56: 57: 58:
59: public function __construct(IMP_Indices $indices, $peek = false)
60: {
61: global $injector;
62:
63: 64:
65: try {
66: list($mbox, $uid) = $indices->getSingle();
67: if (!$uid) {
68: throw new Exception();
69: }
70:
71: $query = new Horde_Imap_Client_Fetch_Query();
72: $query->envelope();
73:
74: $imp_imap = $mbox->imp_imap;
75: $imp_imap->openMailbox($mbox, Horde_Imap_Client::OPEN_READWRITE);
76:
77: $ret = $imp_imap->fetch($mbox, $query, array(
78: 'ids' => $imp_imap->getIdsOb($uid)
79: ));
80:
81: if (!($ob = $ret->first())) {
82: throw new Exception();
83: }
84:
85: $imp_contents = $injector->getInstance('IMP_Factory_Contents')->create($indices);
86: } catch (Exception $e) {
87: throw new IMP_Exception(_("Requested message not found."));
88: }
89:
90: $this->_contents = $imp_contents;
91: $this->_envelope = $ob->getEnvelope();
92: $this->_indices = $indices;
93: $this->_peek = $peek;
94: }
95:
96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128:
129: public function showMessage($args)
130: {
131: global $injector, $page_output, $prefs, $registry, $session;
132:
133: $preview = !empty($args['preview']);
134: $result = array();
135:
136: $mime_headers = $this->_peek
137: ? $this->_contents->getHeader()
138: : $this->_contents->getHeaderAndMarkAsSeen();
139:
140: $headers = array();
141: $imp_ui = $injector->getInstance('IMP_Message_Ui');
142:
143: 144: 145:
146: $basic_headers = $imp_ui->basicHeaders();
147: if (empty($args['headers'])) {
148: $args['headers'] = array('from', 'date', 'to', 'cc', 'bcc');
149: }
150:
151: $headers_list = array_intersect_key($basic_headers, array_flip($args['headers']));
152:
153:
154: foreach (array('from', 'to', 'cc', 'bcc', 'reply-to') as $val) {
155: if (isset($headers_list[$val]) &&
156: (!$preview || ($val != 'reply-to'))) {
157: if ($tmp = $this->getAddressHeader($val)) {
158: $result[$val] = $tmp;
159: }
160: if ($preview) {
161: unset($headers_list[$val]);
162: }
163: }
164: }
165:
166:
167: foreach ($headers_list as $head => $str) {
168: if ($val = $mime_headers->getValue($head)) {
169: if ($head == 'date') {
170:
171: $date_ob = new IMP_Message_Date($this->_envelope->date);
172: $val = htmlspecialchars($date_ob->format($date_ob::DATE_LOCAL));
173: if ($preview) {
174: $result['localdate'] = $val;
175: } else {
176: $result['fulldate'] = $date_ob->format($date_ob::DATE_FORCE);
177: }
178: } elseif (!$preview) {
179: $val = htmlspecialchars($val);
180: }
181:
182: if (!$preview) {
183: $headers[$head] = array(
184: 'id' => Horde_String::ucfirst($head),
185: 'name' => $str,
186: 'value' => $val
187: );
188: }
189: }
190: }
191:
192: if (empty($result['reply-to']) ||
193: ($result['from']['addr'][0]->b == $result['reply-to']['addr'][0]->b)) {
194: unset($result['reply-to'], $headers['reply-to']);
195: }
196:
197:
198: if (!$preview && isset($headers['reply-to'])) {
199: $result['replyTo'] = $result['reply-to'];
200: $headers['reply-to']['id'] = 'ReplyTo';
201: unset($result['reply-to']);
202: }
203:
204:
205: $ajax_queue = $injector->getInstance('IMP_Ajax_Queue');
206: $ajax_queue->maillog($this->_indices);
207:
208: if (!$preview) {
209:
210: $user_hdrs = $imp_ui->getUserHeaders();
211: foreach ($user_hdrs as $user_hdr) {
212: $user_val = $mime_headers->getValue($user_hdr);
213: if (!empty($user_val)) {
214: if (!is_array($user_val)) {
215: $user_val = array($user_val);
216: }
217: foreach ($user_val as $val) {
218: $headers[] = array(
219: 'name' => $user_hdr,
220: 'value' => htmlspecialchars($val)
221: );
222: }
223: }
224: }
225: $result['headers'] = array_values($headers);
226: }
227:
228:
229: $subject = $mime_headers->getValue('subject');
230: if ($subject) {
231: $text_filter = $injector->getInstance('Horde_Core_Factory_TextFilter');
232: $filtered_subject = preg_replace("/\b\s+\b/", ' ', IMP::filterText($subject));
233:
234: $result['subject'] = $text_filter->filter($filtered_subject, 'text2html', array(
235: 'parselevel' => Horde_Text_Filter_Text2html::NOHTML
236: ));
237: $subjectlink = $text_filter->filter($filtered_subject, 'text2html', array(
238: 'parselevel' => Horde_Text_Filter_Text2html::MICRO
239: ));
240:
241: if ($subjectlink != $result['subject']) {
242: $result['subjectlink'] = $subjectlink;
243: }
244: if (!$preview) {
245: $result['title'] = $subject;
246: }
247: } else {
248: $result['subject'] = _("[No Subject]");
249: if (!$preview) {
250: $result['title'] = _("[No Subject]");
251: }
252: }
253:
254:
255: $result['msgtext'] = '';
256: $show_parts = $prefs->getValue('parts_display');
257:
258: switch ($registry->getView()) {
259: case $registry::VIEW_SMARTMOBILE:
260: $contents_mask = 0;
261: break;
262:
263: default:
264: $contents_mask = IMP_Contents::SUMMARY_BYTES |
265: IMP_Contents::SUMMARY_SIZE |
266: IMP_Contents::SUMMARY_ICON |
267: IMP_Contents::SUMMARY_DESCRIP_LINK |
268: IMP_Contents::SUMMARY_DOWNLOAD |
269: IMP_Contents::SUMMARY_DOWNLOAD_ZIP |
270: IMP_Contents::SUMMARY_PRINT_STUB;
271: break;
272: }
273:
274: $part_info = $part_info_display = array('icon', 'description', 'size', 'download', 'download_zip');
275: $part_info_display[] = 'print';
276:
277: list($mbox, $uid) = $this->_indices->getSingle();
278:
279:
280: switch ($registry->getView()) {
281: case $registry::VIEW_DYNAMIC:
282: if ($imp_ui->MDNCheck(new IMP_Indices($mbox, $uid), $mime_headers)) {
283: $status = new IMP_Mime_Status(array(
284: _("The sender of this message is requesting notification from you when you have read this message."),
285: sprintf(_("Click %s to send the notification message."), Horde::link('#', '', '', '', '', '', '', array('id' => 'send_mdn_link')) . _("HERE") . '</a>')
286: ));
287: $status->domid('sendMdnMessage');
288: $result['msgtext'] .= strval($status);
289: }
290: }
291:
292: 293:
294: $session->close();
295: $inline_ob = new IMP_Contents_InlineOutput();
296: $inlineout = $inline_ob->getInlineOutput($this->_contents, array(
297: 'mask' => $contents_mask,
298: 'part_info_display' => $part_info_display,
299: 'show_parts' => $show_parts
300: ));
301: $session->start();
302:
303: $result['md'] = $inlineout['metadata'];
304: $result['msgtext'] .= $inlineout['msgtext'];
305: if ($inlineout['one_part']) {
306: $result['onepart'] = true;
307: }
308:
309: if (count($inlineout['atc_parts']) ||
310: (($show_parts == 'all') && count($inlineout['display_ids']) > 2)) {
311: $result['atc_label'] = ($show_parts == 'all')
312: ? _("Parts")
313: : sprintf(ngettext("%d Attachment", "%d Attachments", count($inlineout['atc_parts'])), count($inlineout['atc_parts']));
314: if (count($inlineout['atc_parts']) > 2) {
315: $result['atc_download'] = Horde::link($this->_contents->urlView($this->_contents->getMIMEMessage(), 'download_all')) . '[' . _("Save All") . ']</a>';
316: }
317: }
318:
319:
320: if (!empty($inlineout['atc_parts'])) {
321: $partlist = array();
322:
323: if ($show_parts == 'all') {
324: array_unshift($part_info, 'id');
325: }
326:
327: foreach ($inlineout['atc_parts'] as $id) {
328: $contents_mask |= IMP_Contents::SUMMARY_DESCRIP |
329: IMP_Contents::SUMMARY_DOWNLOAD |
330: IMP_Contents::SUMMARY_ICON |
331: IMP_Contents::SUMMARY_SIZE;
332: $part_info[] = 'description_raw';
333: $part_info[] = 'download_url';
334:
335: $summary = $this->_contents->getSummary($id, $contents_mask);
336: $tmp = array();
337: foreach ($part_info as $val) {
338: if (isset($summary[$val])) {
339: $tmp[$val] = ($summary[$val] instanceof Horde_Url)
340: ? strval($summary[$val]->setRaw(true))
341: : $summary[$val];
342: }
343: }
344: $partlist[] = array_filter($tmp);
345: }
346:
347: $result['atc_list'] = $partlist;
348: }
349:
350: $result['save_as'] = IMP_Contents_View::downloadUrl(
351: htmlspecialchars_decode($result['subject']),
352: array_merge(
353: array('actionID' => 'save_message'),
354: $mbox->urlParams($uid)
355: )
356: );
357:
358: if ($preview) {
359:
360: Horde::startBuffer();
361: $page_output->outputInlineScript(true);
362: if ($js_inline = Horde::endBuffer()) {
363: $result['js'] = array($js_inline);
364: }
365:
366: $result['save_as'] = strval($result['save_as']->setRaw(true));
367: } else {
368: $list_info = $imp_ui->getListInformation($mime_headers);
369: if (!empty($list_info['exists'])) {
370: $result['list_info'] = $list_info;
371: }
372: }
373:
374:
375: if (!$this->_peek && $mbox->is_imap) {
376: $status = $mbox->imp_imap->status($mbox, Horde_Imap_Client::STATUS_PERMFLAGS);
377: if (in_array(Horde_Imap_Client::FLAG_SEEN, $status['permflags'])) {
378: $ajax_queue->flag(array(Horde_Imap_Client::FLAG_SEEN), true, $this->_indices);
379: }
380: }
381:
382: return array_filter($result);
383: }
384:
385: 386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399:
400: public function ($header, $limit = 50)
401: {
402: $addrlist = ($header == 'reply-to')
403: ? $this->_envelope->reply_to
404: : $this->_envelope->$header;
405: $addrlist->unique();
406:
407: $addr_ob = new IMP_Ajax_Addresses($addrlist);
408: $addr_array = $addr_ob->toArray($limit);
409:
410: $out = array();
411: if ($addr_array->limit) {
412: $out['limit'] = $addr_array->total;
413: }
414:
415: if (!empty($addr_array->addr)) {
416: $out['addr'] = $addr_array->addr;
417: } elseif ($header == 'to') {
418: $out['raw'] = _("Undisclosed Recipients");
419: }
420:
421: return $out;
422: }
423:
424: }
425: