1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: 15: 16: 17: 18: 19: 20: 21: 22: 23:
24: class IMP_Basic_Mailbox extends IMP_Basic_Base
25: {
26: const FLAG_FILTER_PREFIX = "flag\0";
27:
28: 29:
30: protected function _init()
31: {
32: global $injector, $notification, $page_output, $prefs, $registry, $session;
33:
34: $mailbox = $this->indices->mailbox;
35:
36:
37: try {
38: $redirect = $injector->getInstance('Horde_Core_Hooks')->callHook(
39: 'mbox_redirect',
40: 'imp',
41: array($mailbox)
42: );
43: if (!empty($redirect)) {
44: Horde::url($redirect, true)->redirect();
45: }
46: } catch (Horde_Exception_HookNotSet $e) {}
47:
48: $mailbox_url = Horde::url('basic.php')->add('page', 'mailbox');
49: $mailbox_imp_url = $mailbox->url('mailbox')->add('newmail', 1);
50:
51: $imp_flags = $injector->getInstance('IMP_Flags');
52: $imp_imap = $mailbox->imp_imap;
53: $imp_search = $injector->getInstance('IMP_Search');
54:
55:
56: if (($actionID = $this->vars->actionID) &&
57: ($actionID != 'message_missing')) {
58: try {
59: $session->checkToken($this->vars->token);
60: } catch (Horde_Exception $e) {
61: $notification->push($e);
62: $actionID = null;
63: }
64: }
65:
66: 67: 68: 69:
70: $imp_imap->openMailbox($mailbox, Horde_Imap_Client::OPEN_READWRITE);
71: $imp_mailbox = $mailbox->list_ob;
72:
73:
74: $readonly = $mailbox->readonly;
75:
76: switch ($actionID) {
77: case 'change_sort':
78: $mailbox->setSort($this->vars->sortby, $this->vars->sortdir);
79: break;
80:
81: case 'blacklist':
82: $injector->getInstance('IMP_Filter')->blacklistMessage($this->indices);
83: break;
84:
85: case 'whitelist':
86: $injector->getInstance('IMP_Filter')->whitelistMessage($this->indices);
87: break;
88:
89: case 'spam_report':
90: $injector->getInstance('IMP_Factory_Spam')->create(IMP_Spam::SPAM)->report($this->indices);
91: break;
92:
93: case 'innocent_report':
94: $injector->getInstance('IMP_Factory_Spam')->create(IMP_Spam::INNOCENT)->report($this->indices);
95: break;
96:
97: case 'message_missing':
98: $notification->push(_("Requested message not found."), 'horde.error');
99: break;
100:
101: case 'fwd_digest':
102: case 'redirect_messages':
103: case 'template_edit':
104: if (count($this->indices)) {
105: $compose_actions = array(
106: 'fwd_digest' => 'fwd_digest',
107: 'redirect_messages' => 'redirect_compose',
108: 'template_edit' => 'template_edit'
109: );
110:
111: $clink = new IMP_Compose_Link($this->vars);
112: $options = array_merge(array(
113: 'actionID' => $compose_actions[$actionID],
114: 'muid' => strval($this->indices)
115: ), $clink->args);
116:
117: if ($prefs->getValue('compose_popup')) {
118: $page_output->addInlineScript(array(
119: Horde::popupJs(IMP_Basic_Compose::url(), array('novoid' => true, 'params' => array_merge(array('popup' => 1), $options)))
120: ), true);
121: } else {
122: IMP_Basic_Compose::url()->add($options)->redirect();
123: }
124: }
125: break;
126:
127: case 'delete_messages':
128: $injector->getInstance('IMP_Message')->delete($this->indices, array(
129: 'mailboxob' => $imp_mailbox
130: ));
131: break;
132:
133: case 'undelete_messages':
134: $injector->getInstance('IMP_Message')->undelete($this->indices);
135: break;
136:
137: case 'move_messages':
138: case 'copy_messages':
139: if (isset($this->vars->targetMbox) &&
140: count($this->indices) &&
141: (!$readonly || $actionID == 'copy_messages')) {
142: $targetMbox = IMP_Mailbox::formFrom($this->vars->targetMbox);
143: if (!empty($this->vars->newMbox) && ($this->vars->newMbox == 1)) {
144: $targetMbox = IMP_Mailbox::get($this->vars->targetMbox)->namespace_append;
145: $newMbox = true;
146: } else {
147: $targetMbox = IMP_Mailbox::formFrom($this->vars->targetMbox);
148: $newMbox = false;
149: }
150: $injector->getInstance('IMP_Message')->copy($targetMbox, ($actionID == 'move_messages') ? 'move' : 'copy', $this->indices, array(
151: 'create' => $newMbox,
152: 'mailboxob' => $imp_mailbox
153: ));
154: }
155: break;
156:
157: case 'flag_messages':
158: if (!$readonly && $this->vars->flag && count($this->indices)) {
159: $flag = $imp_flags->parseFormId($this->vars->flag);
160: $injector->getInstance('IMP_Message')->flag(array(
161: ($flag['set'] ? 'add' : 'remove') => array($flag['flag'])
162: ), $this->indices);
163: }
164: break;
165:
166: case 'filter_messages':
167: if (!$readonly) {
168: $filter = IMP_Mailbox::formFrom($this->vars->filter);
169: $q_ob = null;
170:
171: if (strpos($filter, self::FLAG_FILTER_PREFIX) === 0) {
172:
173: $flag_filter = $imp_flags->parseFormId(substr($filter, strpos($filter, "\0") + 1));
174:
175: try {
176: $q_ob = $imp_search->createQuery(array(
177: new IMP_Search_Element_Flag(
178: $flag_filter['flag'],
179: $flag_filter['set']
180: )),
181: array(
182: 'mboxes' => array($mailbox),
183: 'type' => IMP_Search::CREATE_QUERY
184: )
185: );
186: } catch (InvalidArgumentException $e) {}
187: } else {
188:
189: try {
190: $q_ob = $imp_search->applyFilter($filter, array($mailbox));
191: } catch (InvalidArgumentException $e) {}
192: }
193:
194: if ($q_ob) {
195: IMP_Mailbox::get($q_ob)->url('mailbox')->redirect();
196: exit;
197: }
198: }
199: break;
200:
201: case 'hide_deleted':
202: $mailbox->setHideDeletedMsgs(!$prefs->getValue('delhide'));
203: break;
204:
205: case 'expunge_mailbox':
206: $injector->getInstance('IMP_Message')->expungeMailbox(array(strval($mailbox) => 1), array(
207: 'mailboxob' => $imp_mailbox
208: ));
209: break;
210:
211: case 'filter':
212: $mailbox->filter();
213: break;
214:
215: case 'empty_mailbox':
216: $injector->getInstance('IMP_Message')->emptyMailbox(array(strval($mailbox)));
217: break;
218:
219: case 'view_messages':
220: $mailbox->url(IMP_Basic_Thread::url(), null, false)->add(array(
221: 'mode' => 'msgview',
222: 'muid' => strval($this->indices)
223: ))->redirect();
224: break;
225: }
226:
227:
228: $token = $session->getToken();
229: $search_mbox = $mailbox->search;
230:
231:
232: if (!$readonly &&
233: IMP_Filter::canApplyFilters() &&
234: !$mailbox->filterOnDisplay() &&
235: ($mailbox->inbox ||
236: ($prefs->getValue('filter_any_mailbox') && !$search_mbox))) {
237: $filter_url = $mailbox_imp_url->copy()->add(array(
238: 'actionID' => 'filter',
239: 'token' => $token
240: ));
241: }
242:
243:
244: if ($imp_imap->access(IMP_Imap::ACCESS_FOLDERS)) {
245: $iterator = new IMP_Ftree_IteratorFilter(
246: $injector->getInstance('IMP_Ftree')
247: );
248: $iterator->add($iterator::NONIMAP);
249:
250: $folder_options = new IMP_Ftree_Select(array(
251: 'heading' => _("Messages to"),
252: 'inc_notepads' => true,
253: 'inc_tasklists' => true,
254: 'iterator' => $iterator,
255: 'new_mbox' => true
256: ));
257: }
258:
259:
260: $pageOb = $imp_mailbox->buildMailboxPage($this->vars->mpage, $this->vars->start);
261: $show_preview = $prefs->getValue('preview_enabled');
262:
263: $mbox_info = $imp_mailbox->getMailboxArray(range($pageOb['begin'], $pageOb['end']), array(
264: 'headers' => true,
265: 'preview' => (int)$show_preview,
266: 'type' => $prefs->getValue('atc_flag')
267: ));
268:
269:
270: $sortpref = $mailbox->getSort();
271: $thread_sort = ($sortpref->sortby == Horde_Imap_Client::SORT_THREAD);
272:
273: 274:
275: if (!($use_trash = $prefs->getValue('use_trash')) &&
276: !$mailbox->vinbox) {
277: $showdelete = array(
278: 'hide' => true,
279: 'purge' => $mailbox->access_expunge
280: );
281: } else {
282: $showdelete = array(
283: 'hide' => false,
284: 'purge' => false
285: );
286: }
287: if ($showdelete['hide'] && !$prefs->isLocked('delhide')) {
288: if ($prefs->getValue('delhide')) {
289: $deleted_prompt = _("Show Deleted");
290: } else {
291: $deleted_prompt = _("Hide Deleted");
292: }
293: }
294:
295:
296: if ($pageOb['pagecount']) {
297: if ($pageOb['page'] == 1) {
298: $url_first = $url_prev = null;
299: $pages_first = 'navfirstgreyImg';
300: $pages_prev = 'navleftgreyImg';
301: } else {
302: $url_first = $mailbox_imp_url->copy()->add('mpage', 1);
303: $pages_first = 'navfirstImg';
304: $url_prev = $mailbox_imp_url->copy()->add('mpage', $pageOb['page'] - 1);
305: $pages_prev = 'navleftImg';
306: }
307:
308: if ($pageOb['page'] == $pageOb['pagecount']) {
309: $url_last = $url_next = null;
310: $pages_last = 'navlastgreyImg';
311: $pages_next = 'navrightgreyImg';
312: } else {
313: $url_next = $mailbox_imp_url->copy()->add('mpage', $pageOb['page'] + 1);
314: $pages_next = 'navrightImg';
315: $url_last = $mailbox_imp_url->copy()->add('mpage', $pageOb['pagecount']);
316: $pages_last = 'navlastImg';
317: }
318: }
319:
320:
321: if ($mailbox->inbox) {
322: $rss_box = '';
323: } else {
324: $ns_info = $mailbox->namespace_info;
325: if (is_null($ns_info)) {
326: $rss_box = null;
327: } else {
328: $rss_box = str_replace(
329: rawurlencode($ns_info->delimiter),
330: '/',
331: rawurlencode($ns_info->delimiter . (($ns_info->type == $ns_info::NS_PERSONAL) ? $ns_info->stripNamespace($mailbox) : $mailbox))
332: );
333: }
334: }
335:
336: if (!is_null($rss_box)) {
337: $page_output->addLinkTag(array(
338: 'href' => Horde::url('rss.php', true, -1) . $rss_box
339: ));
340: }
341:
342:
343: $refresh_url = $mailbox_imp_url->copy()->add('mpage', $pageOb['page']);
344: if (isset($filter_url)) {
345: $filter_url->add('mpage', $pageOb['page']);
346: }
347:
348:
349: $preview_tooltip = $show_preview
350: ? $prefs->getValue('preview_show_tooltip')
351: : false;
352: if (!$preview_tooltip) {
353: $strip_preview = $prefs->getValue('preview_strip_nl');
354: }
355:
356: $unread = $imp_mailbox->unseenMessages(Horde_Imap_Client::SEARCH_RESULTS_COUNT);
357:
358: $page_output->addInlineJsVars(array(
359: 'ImpMailbox.pop3' => intval(!$mailbox->is_imap),
360: 'ImpMailbox.text' => array(
361: 'delete_messages' => _("Are you sure you wish to PERMANENTLY delete these messages?"),
362: 'delete_all' => _("Are you sure you wish to delete all mail in this mailbox?"),
363: 'delete_vfolder' => _("Are you sure you want to delete this Virtual Folder Definition?"),
364: 'innocent_report' => _("Are you sure you wish to report this message as innocent?"),
365: 'moveconfirm' => _("Are you sure you want to move the message(s)? (Some message information might get lost, like message headers, text formatting or attachments!)"),
366: 'newmbox' => _("You are copying/moving to a new mailbox.") . "\n" . _("Please enter a name for the new mailbox:") . "\n",
367: 'no' => _("No"),
368: 'selectone' => _("You must select at least one message first."),
369: 'selectonlyone' => _("You must select only one message for this action."),
370: 'spam_report' => _("Are you sure you wish to report this message as spam?"),
371: 'submit' => _("You must select at least one message first."),
372: 'target_mbox' => _("You must select a target mailbox first.")
373: ),
374: 'ImpMailbox.unread' => intval($unread)
375: ));
376:
377: $pagetitle = $this->title = $mailbox->label;
378:
379: if ($mailbox->editvfolder) {
380: $query_text = wordwrap($imp_search[$mailbox]->querytext);
381: $pagetitle .= ' [' . Horde::linkTooltip('#', $query_text, '', '', '', $query_text) . _("Virtual Folder") . '</a>]';
382: $this->title .= ' [' . _("Virtual Folder") . ']';
383: } elseif ($mailbox->editquery) {
384: $query_text = wordwrap($imp_search[$mailbox]->querytext);
385: $pagetitle = Horde::linkTooltip('#', $query_text, '', '', '', $query_text) . $pagetitle . '</a>';
386: } else {
387: $pagetitle = $this->title = htmlspecialchars($this->title);
388: }
389:
390:
391: $subinfo = new IMP_View_Subinfo(array('mailbox' => $mailbox));
392: $subinfo->value = $pagetitle . ' (';
393: if (empty($pageOb['end'])) {
394: $subinfo->value .= _("No Messages");
395: } else {
396: $subinfo->value .= ($pageOb['pagecount'] > 1)
397: ? sprintf(_("%d Messages"), $pageOb['msgcount']) . ' / ' . sprintf(_("Page %d of %d"), $pageOb['page'], $pageOb['pagecount'])
398: : sprintf(_("%d Messages"), $pageOb['msgcount']);
399: }
400: $subinfo->value .= ')';
401: $injector->getInstance('Horde_View_Topbar')->subinfo = $subinfo->render();
402:
403: $page_output->addScriptFile('hordecore.js', 'horde');
404: $page_output->addScriptFile('mailbox.js');
405: $page_output->addScriptPackage('Horde_Core_Script_Package_Dialog');
406:
407: $page_output->metaRefresh($prefs->getValue('refresh_time'), $refresh_url);
408:
409:
410: $view = new Horde_View(array(
411: 'templatePath' => IMP_TEMPLATES . '/basic/mailbox'
412: ));
413: $view->addHelper('FormTag');
414: $view->addHelper('Horde_Core_View_Helper_Accesskey');
415: $view->addHelper('Tag');
416:
417: $hdr_view = clone $view;
418: $hdr_view->readonly = $readonly;
419: $hdr_view->refresh_url = $refresh_url;
420: if (isset($filter_url)) {
421: $hdr_view->filter_url = $filter_url;
422: }
423: if ($mailbox->access_search) {
424: if (!$search_mbox) {
425: $hdr_view->search_url = $mailbox->url(IMP_Basic_Searchbasic::url());
426: } else {
427: if ($mailbox->editvfolder) {
428: $edit_search = _("Edit Virtual Folder");
429: } elseif ($mailbox->query) {
430: if ($mailbox->editquery) {
431: $edit_search = _("Edit Search Query");
432: } else {
433:
434: $search_mailbox = IMP_Mailbox::get($imp_search[$mailbox]->mboxes[0]);
435: $hdr_view->search_url = $search_mailbox->url(IMP_Basic_Searchbasic::url());
436: $hdr_view->searchclose = $search_mailbox->url('mailbox');
437: }
438: }
439:
440: if (isset($edit_search)) {
441: $hdr_view->edit_search_url = $imp_search->editUrl($mailbox);
442: $hdr_view->edit_search_title = $edit_search;
443: }
444: }
445: }
446:
447: if ($mailbox->access_empty) {
448: $hdr_view->empty = $mailbox_imp_url->copy()->add(array(
449: 'actionID' => 'empty_mailbox',
450: 'token' => $token
451: ));
452: }
453:
454: $this->output = $hdr_view->render('header');
455:
456:
457: if (empty($pageOb['end'])) {
458: if ($pageOb['anymsg'] && isset($deleted_prompt)) {
459: 460:
461: $del_view = clone $view;
462: $del_view->hide = Horde::widget(array(
463: 'url' => $refresh_url->copy()->add(array(
464: 'actionID' => 'hide_deleted',
465: 'token' => $token
466: )),
467: 'class' => 'hideAction',
468: 'title' => $deleted_prompt
469: ));
470: if ($mailbox->access_expunge) {
471: $del_view->purge = Horde::widget(array(
472: 'url' => $refresh_url->copy()->add(array(
473: 'actionID' => 'expunge_mailbox',
474: 'token' => $token
475: )),
476: 'class' => 'purgeAction',
477: 'title' => _("Pur_ge Deleted")
478: ));
479: }
480:
481: $this->output .= $del_view->render('actions_deleted');
482: }
483:
484: $empty_view = clone $view;
485: $empty_view->search_mbox = $search_mbox;
486:
487: $this->output .= $empty_view->render('empty_mailbox');
488: return;
489: }
490:
491: $clink_ob = new IMP_Compose_Link();
492: $clink = $clink_ob->link();
493:
494: 495:
496: if ($pageOb['msgcount']) {
497:
498: $n_view = clone $view;
499: $n_view->id = 1;
500: $n_view->readonly = $readonly;
501:
502: $filtermsg = false;
503: if ($mailbox->access_flags) {
504: $args = array(
505: 'imap' => true,
506: 'mailbox' => $search_mbox ? null : $mailbox
507: );
508:
509: $form_set = $form_unset = array();
510: foreach ($imp_flags->getList($args) as $val) {
511: if ($val->canset) {
512: $form_set[] = array(
513: 'f' => $val->form_set,
514: 'l' => $val->label,
515: 'v' => IMP_Mailbox::formTo(self::FLAG_FILTER_PREFIX . $val->form_set)
516: );
517: $form_unset[] = array(
518: 'f' => $val->form_unset,
519: 'l' => $val->label,
520: 'v' => IMP_Mailbox::formTo(self::FLAG_FILTER_PREFIX . $val->form_unset)
521: );
522: }
523: }
524:
525: $n_view->flaglist_set = $form_set;
526: $n_view->flaglist_unset = $form_unset;
527:
528: if (!$search_mbox && $mailbox->access_search) {
529: $filtermsg = $n_view->flag_filter = true;
530: }
531: }
532:
533: if (!$search_mbox && $mailbox->access_filters) {
534: $filters = array();
535: $iterator = IMP_Search_IteratorFilter::create(
536: IMP_Search_IteratorFilter::FILTER
537: );
538:
539: foreach ($iterator as $val) {
540: $filters[] = array(
541: 'l' => $val->label,
542: 'v' => IMP_Mailbox::formTo($val)
543: );
544: }
545:
546: if (!empty($filters)) {
547: $filtermsg = true;
548: $n_view->filters = $filters;
549: }
550: }
551:
552: $n_view->filtermsg = $filtermsg;
553:
554: if ($imp_imap->access(IMP_Imap::ACCESS_FOLDERS)) {
555: $n_view->move = Horde::widget(array(
556: 'url' => '#',
557: 'class' => 'moveAction',
558: 'title' => _("Move"),
559: 'nocheck' => true
560: ));
561: $n_view->copy = Horde::widget(array(
562: 'url' => '#',
563: 'class' => 'copyAction',
564: 'title' => _("Copy"),
565: 'nocheck' => true
566: ));
567: $n_view->folder_options = $folder_options;
568: }
569:
570: $n_view->mailbox_url = $mailbox_url;
571: $n_view->mailbox = $mailbox->form_to;
572: if ($pageOb['pagecount'] > 1) {
573: $n_view->multiple_page = true;
574: $n_view->pages_first = $pages_first;
575: $n_view->url_first = $url_first;
576: $n_view->pages_prev = $pages_prev;
577: $n_view->url_prev = $url_prev;
578: $n_view->pages_next = $pages_next;
579: $n_view->url_next = $url_next;
580: $n_view->pages_last = $pages_last;
581: $n_view->url_last = $url_last;
582: $n_view->page_val = $pageOb['page'];
583: $n_view->page_size = Horde_String::length($pageOb['pagecount']);
584: }
585:
586: $this->output .= $n_view->render('navbar');
587:
588:
589: $a_view = clone $view;
590: if ($mailbox->access_deletemsgs) {
591: $del_class = ($use_trash && $mailbox->trash)
592: ? 'permdeleteAction'
593: : 'deleteAction';
594: $a_view->delete = Horde::widget(array(
595: 'url' => '#',
596: 'class' => $del_class,
597: 'title' => _("_Delete")
598: ));
599: }
600:
601: if ($showdelete['purge'] || $mailbox->vtrash) {
602: $a_view->undelete = Horde::widget(array(
603: 'url' => '#',
604: 'class' => 'undeleteAction',
605: 'title' => _("_Undelete")
606: ));
607: }
608:
609: $mboxactions = array();
610: if ($showdelete['purge']) {
611: $mailbox_link = $mailbox_imp_url->copy()->add('mpage', $pageOb['page']);
612: if (isset($deleted_prompt)) {
613: $mboxactions[] = Horde::widget(array(
614: 'url' => $mailbox_link->copy()->add(array(
615: 'actionID' => 'hide_deleted',
616: 'token' => $token
617: )),
618: 'class' => 'hideAction',
619: 'title' => $deleted_prompt
620: ));
621: }
622: $mboxactions[] = Horde::widget(array(
623: 'url' => $mailbox_link->copy()->add(array(
624: 'actionID' => 'expunge_mailbox',
625: 'token' => $token
626: )),
627: 'class' => 'purgeAction',
628: 'title' => _("Pur_ge Deleted")
629: ));
630: }
631:
632: if (!$sortpref->sortby_locked &&
633: ($sortpref->sortby != Horde_Imap_Client::SORT_SEQUENCE)) {
634: $mboxactions[] = Horde::widget(array(
635: 'url' => $mailbox_imp_url->copy()->add(array(
636: 'sortby' => Horde_Imap_Client::SORT_SEQUENCE,
637: 'actionID' => 'change_sort',
638: 'token' => $token
639: )),
640: 'title' => _("Clear Sort")
641: ));
642: }
643:
644: if ($mailbox->templates) {
645: $a_view->templateedit = Horde::widget(array(
646: 'url' => '#',
647: 'class' => 'templateeditAction',
648: 'title' => _("Edit Template")
649: ));
650: $mboxactions[] = Horde::widget(array(
651: 'url' => $clink->copy()->add(array(
652: 'actionID' => 'template_new'
653: )),
654: 'title' => _("Create New Template")
655: ));
656: }
657:
658: $a_view->mboxactions = $mboxactions;
659:
660: if ($registry->hasMethod('mail/blacklistFrom')) {
661: $a_view->blacklist = Horde::widget(array(
662: 'url' => '#',
663: 'class' => 'blacklistAction',
664: 'title' => _("_Blacklist")
665: ));
666: }
667:
668: if ($registry->hasMethod('mail/whitelistFrom')) {
669: $a_view->whitelist = Horde::widget(array(
670: 'url' => '#',
671: 'class' => 'whitelistAction',
672: 'title' => _("_Whitelist")
673: ));
674: }
675:
676: if (IMP_Compose::canCompose()) {
677: $a_view->forward = Horde::widget(array(
678: 'url' => '#',
679: 'class' => 'forwardAction',
680: 'title' => _("Fo_rward")
681: ));
682: $a_view->redirect = Horde::widget(array(
683: 'url' => '#',
684: 'class' => 'redirectAction',
685: 'title' => _("Redirect")
686: ));
687: }
688:
689: if ($mailbox->spam_show) {
690: $a_view->spam = Horde::widget(array(
691: 'url' => '#',
692: 'class' => 'spamAction',
693: 'title' => _("Report as Spam")
694: ));
695: }
696:
697: if ($mailbox->innocent_show) {
698: $a_view->innocent = Horde::widget(array(
699: 'url' => '#',
700: 'class' => 'innocentAction',
701: 'title' => _("Report as Innocent")
702: ));
703: }
704:
705: $a_view->view_messages = Horde::widget(array(
706: 'url' => '#',
707: 'class' => 'viewAction',
708: 'title' => _("View Messages")
709: ));
710:
711: $this->output .= $a_view->render('actions');
712: }
713:
714: 715:
716: $lastMbox = '';
717: $mh_count = 0;
718: $sortImg = $sortpref->sortdir
719: ? 'sortup'
720: : 'sortdown';
721: $headers = array(
722: Horde_Imap_Client::SORT_TO => array(
723: 'id' => 'mboxto',
724: 'stext' => _("Sort by To Address"),
725: 'text' => _("To")
726: ),
727: Horde_Imap_Client::SORT_FROM => array(
728: 'id' => 'mboxfrom',
729: 'stext' => _("Sort by From Address"),
730: 'text' => _("Fro_m")
731: ),
732: Horde_Imap_Client::SORT_THREAD => array(
733: 'id' => 'mboxthread',
734: 'stext' => _("Sort by Thread"),
735: 'text' => _("_Thread")
736: ),
737: Horde_Imap_Client::SORT_SUBJECT => array(
738: 'id' => 'mboxsubject',
739: 'stext' => _("Sort by Subject"),
740: 'text' => _("Sub_ject")
741: ),
742: IMP::IMAP_SORT_DATE => array(
743: 'id' => 'mboxdate',
744: 'stext' => _("Sort by Date"),
745: 'text' => _("Dat_e")
746: ),
747: Horde_Imap_Client::SORT_SIZE => array(
748: 'id' => 'mboxsize',
749: 'stext' => _("Sort by Message Size"),
750: 'text' => _("Si_ze")
751: )
752: );
753:
754: 755:
756: if ($mailbox->special_outgoing) {
757: unset($headers[Horde_Imap_Client::SORT_FROM]);
758: } else {
759: unset($headers[Horde_Imap_Client::SORT_TO]);
760: }
761:
762:
763: if (!$mailbox->access_sortthread || $sortpref->sortby_locked) {
764: unset($headers[Horde_Imap_Client::SORT_THREAD]);
765: if ($sortpref->sortby_locked && $thread_sort) {
766: $sortpref->sortby = Horde_Imap_Client::SORT_SUBJECT;
767: }
768: } else {
769: if ($thread_sort) {
770: $extra = Horde_Imap_Client::SORT_SUBJECT;
771: $standard = Horde_Imap_Client::SORT_THREAD;
772: } else {
773: $extra = Horde_Imap_Client::SORT_THREAD;
774: $standard = Horde_Imap_Client::SORT_SUBJECT;
775: }
776: $headers[$standard]['altsort'] = Horde::widget(array(
777: 'url' => $mailbox_imp_url->copy()->add(array(
778: 'actionID' => 'change_sort',
779: 'token' => $token,
780: 'sortby' => $extra
781: )),
782: 'title' => $headers[$extra]['text']
783: ));
784: unset($headers[$extra]);
785: }
786:
787: foreach ($headers as $key => $val) {
788: $ptr = &$headers[$key];
789: if ($sortpref->sortby == $key) {
790: $csl_icon = '<span class="iconImg ' . $sortImg . '"></span>';
791: if ($sortpref->sortdir_locked) {
792: $ptr['change_sort_link'] = $csl_icon;
793: $ptr['change_sort_widget'] = Horde::stripAccessKey($val['text']);
794: } else {
795: $tmp = $mailbox_imp_url->copy()->add(array(
796: 'sortby' => $key,
797: 'sortdir' => intval(!$sortpref->sortdir),
798: 'actionID' => 'change_sort',
799: 'token' => $token
800: ));
801: $ptr['change_sort_link'] = Horde::link($tmp, $val['stext'], null, null, null, $val['stext']) . $csl_icon . '</a>';
802: $ptr['change_sort_widget'] = Horde::widget(array('url' => $tmp, 'title' => $val['text']));
803: }
804: } else {
805: $ptr['change_sort_link'] = null;
806: $ptr['change_sort_widget'] = $sortpref->sortby_locked
807: ? Horde::stripAccessKey($val['text'])
808: : Horde::widget(array(
809: 'url' => $mailbox_imp_url->copy()->add(array(
810: 'actionID' => 'change_sort',
811: 'token' => $token,
812: 'sortby' => $key
813: )),
814: 'title' => $val['text']
815: ));
816: }
817: $ptr['class'] = 'horde-split-left';
818: }
819:
820:
821: $f_view = clone $view;
822: $f_view->mailbox = $mailbox->form_to;
823: $f_view->mailbox_url = $mailbox_url;
824: $f_view->page = $pageOb['page'];
825: $f_view->token = $token;
826: $this->output .= $f_view->render('form_start');
827:
828:
829: $mh_view = clone $view;
830: $mh_view->headers = $headers;
831:
832: if (!$search_mbox) {
833: $mh_view->show_checkbox = !$mh_count++;
834: $this->output .= $mh_view->render('message_headers');
835: }
836:
837:
838: $fromlinkstyle = $prefs->getValue('from_link');
839: $imp_ui = new IMP_Mailbox_Ui($mailbox);
840:
841:
842: $msgs = array();
843: $search_view = clone $view;
844: $summary_view = clone $view;
845:
846: while (list(,$ob) = each($mbox_info['overview'])) {
847: if ($search_mbox) {
848: if (empty($lastMbox) || ($ob['mailbox'] != $lastMbox)) {
849: if (!empty($lastMbox)) {
850: $this->_outputSummaries($msgs, $summary_view);
851: $msgs = array();
852: }
853:
854: $mbox = IMP_Mailbox::get($ob['mailbox']);
855: $search_view->mbox_link = Horde::link($mbox->url($mailbox_url), sprintf(_("View messages in %s"), $mbox->display), 'smallheader') . $mbox->display_html . '</a>';
856: $this->output .= $search_view->render('searchmbox');
857:
858: $mh_view->show_checkbox = !$mh_count++;
859: $this->output .= $mh_view->render('message_headers');
860: }
861: }
862:
863: $lastMbox = $ob['mailbox'];
864:
865:
866: $msg = array(
867: 'bg' => '',
868: 'buid' => $imp_mailbox->getBuid($ob['mailbox'], $ob['uid']),
869: 'class' => '',
870: 'date' => strval(new IMP_Message_Date($ob['envelope']->date)),
871: 'preview' => '',
872: 'status' => '',
873: 'size' => IMP::sizeFormat($ob['size'])
874: );
875:
876:
877: if ($mailbox->drafts || $mailbox->templates) {
878: $clink_copy = clone $clink_ob;
879: $clink_copy->args['buid'] = $msg['buid'];
880: $clink_copy->args['mailbox'] = $mailbox;
881: $target = $clink_copy->link()->add(array(
882: 'actionID' => ($mailbox->drafts ? 'draft' : 'template')
883: ));
884: } else {
885: $target = $mailbox->url('message', $msg['buid']);
886: }
887:
888:
889: $flag_parse = $imp_flags->parse(array(
890: 'flags' => $ob['flags'],
891: 'headers' => $ob['headers'],
892: 'runhook' => $ob,
893: 'personal' => $ob['envelope']->to
894: ));
895:
896: $css_class = $subject_flags = array();
897: foreach ($flag_parse as $val) {
898: if ($val instanceof IMP_Flag_User) {
899: $subject_flags[] = $val;
900: } else {
901: if (!$val->bgdefault) {
902: $msg['bg'] = $val->bgcolor;
903: }
904: $css_class[] = $val->css;
905: $msg['status'] .= $val->span;
906: }
907: }
908: $msg['class'] = implode(' ', $css_class);
909:
910:
911: if ($show_preview && isset($ob['preview'])) {
912: if (empty($ob['preview'])) {
913: $ptext = '[[' . _("No Preview Text") . ']]';
914: } else {
915: $ptext = empty($strip_preview)
916: ? str_replace("\r", '', $ob['preview'])
917: : preg_replace(array('/\n/', '/(\s)+/'), array(' ', '$1'), str_replace("\r", "\n", $ob['preview']));
918:
919: if (!$preview_tooltip) {
920: $ptext = $injector->getInstance('Horde_Core_Factory_TextFilter')->filter($ptext, 'text2html', array(
921: 'parselevel' => Horde_Text_Filter_Text2html::NOHTML
922: ));
923: }
924:
925: $maxlen = $prefs->getValue('preview_maxlen');
926: if (Horde_String::length($ptext) > $maxlen) {
927: $ptext = Horde_String::truncate($ptext, $maxlen);
928: } elseif (empty($ob['previewcut'])) {
929: $ptext .= '[[' . _("END") . ']]';
930: }
931: }
932: $msg['preview'] = $ptext;
933: }
934:
935:
936: $getfrom = $imp_ui->getFrom($ob['envelope']);
937: $msg['from'] = htmlspecialchars($getfrom['from'], ENT_QUOTES, 'UTF-8');
938: switch ($fromlinkstyle) {
939: case 0:
940: $from_tmp = array();
941: foreach ($getfrom['from_list']->base_addresses as $from_ob) {
942: $from_tmp[] = call_user_func_array(array('Horde', $preview_tooltip ? 'linkTooltip' : 'link'), array($clink->copy()->add(array('actionID' => 'mailto_link', 'to' => strval($from_ob))), sprintf(_("New Message to %s"), $from_ob->label))) . htmlspecialchars($from_ob->label, ENT_QUOTES, 'UTF-8') . '</a>';
943: }
944:
945: if (!empty($from_tmp)) {
946: $msg['from'] = implode(', ', $from_tmp);
947: }
948: break;
949:
950: default:
951: $from_uri = $mailbox->url('message', $msg['buid']);
952: $msg['from'] = Horde::link($from_uri) . $msg['from'] . '</a>';
953: break;
954: }
955:
956:
957: $msg['subject'] = $imp_ui->getSubject($ob['envelope']->subject, true);
958: $msg['subject'] = $preview_tooltip
959: ? substr(Horde::linkTooltip($target, $msg['preview'], '', '', '', $msg['preview']), 0, -1) . ' class="mboxSubject">' . $msg['subject'] . '</a>'
960: : substr(Horde::link($target, $imp_ui->getSubject($ob['envelope']->subject)), 0, -1) . ' class="mboxSubject">' . $msg['subject'] . '</a>' . (!empty($msg['preview']) ? '<br /><small>' . $msg['preview'] . '</small>' : '');
961:
962:
963: foreach ($subject_flags as $val) {
964: $flag_label = Horde_String::truncate($val->label, 12);
965:
966: $msg['subject'] = '<span class="' . $val->css . '" style="' . ($val->bgdefault ? '' : 'background:' . htmlspecialchars($val->bgcolor) . ';') . 'color:' . htmlspecialchars($val->fgcolor) . '" title="' . htmlspecialchars($val->label) . '">' . htmlspecialchars($flag_label) . '</span>' . $msg['subject'];
967: }
968:
969:
970: if ($thread_sort) {
971: $t_ob = $imp_mailbox->getThreadOb($ob['idx']);
972: $msg['subject'] = ($sortpref->sortdir ? $t_ob->reverse_img : $t_ob->img) . ' ' . $msg['subject'];
973: }
974:
975: $msgs[$msg['buid']] = $msg;
976: }
977:
978: $this->_outputSummaries($msgs, $summary_view);
979:
980: $this->output .= '</form>';
981:
982: 983:
984: if (($pageOb['end'] - $pageOb['begin']) >= 20) {
985: $this->output .= $a_view->render('actions');
986: $n_view->id = 2;
987: $this->output .= $n_view->render('navbar');
988: }
989: }
990:
991: 992: 993: 994:
995: public static function url(array $opts = array())
996: {
997: $opts = array_merge(array('mailbox' => 'INBOX'), $opts);
998:
999: return IMP_Mailbox::get($opts['mailbox'])->url('basic')->add('page', 'mailbox');
1000: }
1001:
1002: 1003:
1004: protected function _outputSummaries($msgs, Horde_View $view)
1005: {
1006:
1007: try {
1008: $msgs = $GLOBALS['injector']->getInstance('Horde_Core_Hooks')->callHook(
1009: 'mailboxarray',
1010: 'imp',
1011: array($msgs)
1012: );
1013: } catch (Horde_Exception_HookNotSet $e) {}
1014:
1015: $view->messages = $msgs;
1016: $this->output .= $view->render('mailbox');
1017: }
1018:
1019: }
1020: