1<?php
2/**
3 * Copyright 2012-2017 Horde LLC (http://www.horde.org/)
4 *
5 * See the enclosed file COPYING for license information (GPL). If you
6 * did not receive this file, see http://www.horde.org/licenses/gpl.
7 *
8 * @category  Horde
9 * @copyright 2012-2017 Horde LLC
10 * @license   http://www.horde.org/licenses/gpl GPL
11 * @package   IMP
12 */
13
14/**
15 * Mailbox page for dynamic view.
16 *
17 * @author    Michael Slusarz <slusarz@horde.org>
18 * @category  Horde
19 * @copyright 2012-2017 Horde LLC
20 * @license   http://www.horde.org/licenses/gpl GPL
21 * @package   IMP
22 */
23class IMP_Dynamic_Mailbox extends IMP_Dynamic_Base
24{
25    /**
26     */
27    protected function _init()
28    {
29        global $injector, $page_output, $registry;
30
31        $page_output->addScriptFile('dimpbase.js');
32        $page_output->addScriptFile('passphrase.js');
33        $page_output->addScriptFile('viewport.js');
34        $page_output->addScriptFile('external/tinycon.js');
35        $page_output->addScriptFile('dragdrop2.js', 'horde');
36        $page_output->addScriptFile('form_ghost.js', 'horde');
37        $page_output->addScriptFile('jstorage.js', 'horde');
38        $page_output->addScriptFile('slider2.js', 'horde');
39        $page_output->addScriptFile('toggle_quotes.js', 'horde');
40        $page_output->addScriptPackage('Horde_Core_Script_Package_Dialog');
41        $page_output->addScriptPackage('IMP_Script_Package_Imp');
42
43        $imp_imap = $injector->getInstance('IMP_Factory_Imap')->create();
44
45        if ($imp_imap->access(IMP_Imap::ACCESS_FLAGS)) {
46            $page_output->addScriptFile('colorpicker.js', 'horde');
47            $this->view->picker_img = Horde_Themes_Image::tag('colorpicker.png', array('alt' => _("Color Picker")));
48        }
49
50        if ($imp_imap->access(IMP_Imap::ACCESS_REMOTE)) {
51            $page_output->addScriptFile('external/base64.js');
52        }
53
54        $this->_addMailboxVars();
55
56        $this->view->show_innocent = !empty($imp_imap->config->innocent_params);
57        $this->view->show_search = $imp_imap->access(IMP_Imap::ACCESS_SEARCH);
58        $this->view->show_spam = !empty($imp_imap->config->spam_params);
59
60        $impSubinfo = new Horde_View(array(
61            'templatePath' => IMP_TEMPLATES . '/dynamic'
62        ));
63        $impSubinfo->addHelper('Text');
64        $impSubinfo->quota = (bool)$imp_imap->config->quota;
65
66        $topbar = $injector->getInstance('Horde_View_Topbar');
67        $topbar->search = $this->view->show_search;
68        $topbar->searchMenu = true;
69        $topbar->subinfo = $impSubinfo->render('mailbox_subinfo');
70        $page_output->topbar = true;
71
72        $blank = new Horde_Url();
73        $impSidebar = new Horde_View(array(
74            'templatePath' => array(
75                $registry->get('templates', 'horde') . '/sidebar',
76                IMP_TEMPLATES . '/dynamic'
77            )
78        ));
79        $impSidebar->addHelper('Text');
80        $impSidebar->containers = array(
81            array(
82                'id' => 'imp-specialmboxes'
83            )
84        );
85        if ($imp_imap->isImap()) {
86            $impSidebar->containers[] = array(
87                'rows' => array(
88                    array(
89                        'id' => 'folderopts_link',
90                        'cssClass' => 'folderoptsImg',
91                        'link' => $blank->link() . _("Folder Actions") . '</a>'
92                    ),
93                    array(
94                        'id' => 'dropbase',
95                        'style' => 'display:none',
96                        'cssClass' => 'folderImg',
97                        'link' => $blank->link() . _("Move to Base Level") . '</a>'
98                    )
99                )
100            );
101            $impSidebar->containers[] = array(
102                'id' => 'imp-normalmboxes'
103            );
104        }
105
106        $sidebar = $injector->getInstance('Horde_View_Sidebar');
107        $sidebar->newLink = $blank->link(array('id' => 'composelink',
108                                               'class' => 'icon'));
109        $sidebar->newText = _("New Message");
110        $sidebar->content = $impSidebar->render('sidebar');
111
112        $this->view->sidebar = $sidebar->render();
113
114        $page_output->noDnsPrefetch();
115
116        $this->_pages[] = 'mailbox';
117    }
118
119    /**
120     */
121    static public function url(array $opts = array())
122    {
123        return Horde::url('dynamic.php')->add('page', 'mailbox');
124    }
125
126    /**
127     */
128    protected function _addMailboxVars()
129    {
130        global $conf, $injector, $prefs, $registry;
131
132        /* Does server support ACLs? */
133        $imp_imap = $injector->getInstance('IMP_Factory_Imap')->create();
134        $acl = $imp_imap->access(IMP_Imap::ACCESS_ACL);
135
136        $subscribe = $prefs->getValue('subscribe');
137
138        $this->js_conf += array_filter(array(
139            // URLs
140            'URI_LISTINFO' => strval(IMP_Basic_Listinfo::url()->setRaw(true)),
141            'URI_MESSAGE' => strval(IMP_Dynamic_Message::url()->setRaw(true)),
142            'URI_PORTAL' => strval($registry->getServiceLink('portal')->setRaw(true)),
143            'URI_PREFS_IMP' => strval($registry->getServiceLink('prefs', 'imp')->setRaw(true)),
144            'URI_SEARCH' => strval(IMP_Basic_Search::url()->setRaw(true)),
145            'URI_THREAD' => strval(IMP_Basic_Thread::url()->setRaw(true)),
146
147            // IMAP Flags
148            'FLAG_DELETED' => Horde_Imap_Client::FLAG_DELETED,
149            'FLAG_DRAFT' => Horde_Imap_Client::FLAG_DRAFT,
150            'FLAG_INNOCENT' => Horde_Imap_Client::FLAG_NOTJUNK,
151            'FLAG_SEEN' => Horde_Imap_Client::FLAG_SEEN,
152            'FLAG_SPAM' => Horde_Imap_Client::FLAG_JUNK,
153
154            // Message list templates
155            'msglist_template_horiz' => file_get_contents(IMP_TEMPLATES . '/dynamic/msglist_horiz.html'),
156            'msglist_template_vert' => file_get_contents(IMP_TEMPLATES . '/dynamic/msglist_vert.html'),
157
158            // Other variables
159            'acl' => $acl,
160            'download_types' => array(
161                'mbox' => _("Download into a MBOX file"),
162                'mboxzip' => _("Download into a MBOX file (ZIP compressed)")
163            ),
164            'filter_any' => intval($prefs->getValue('filter_any_mailbox')),
165            'from_link' => intval($prefs->getValue('from_link') == 0),
166            'fsearchid' => IMP_Mailbox::formTo(IMP_Search::MBOX_PREFIX . IMP_Search::DIMP_FILTERSEARCH),
167            'initial_page' => is_null($initial_page = IMP::getInitialPage()->mbox) ? null : $initial_page->form_to,
168            'mbox_expand' => intval($prefs->getValue('nav_expanded') == 2),
169            'name' => $registry->get('name', 'imp'),
170            'poll_alter' => intval(!$prefs->isLocked('nav_poll') && !$prefs->getValue('nav_poll_all')),
171            'qsearchid' => IMP_Mailbox::formTo(IMP_Search::MBOX_PREFIX . IMP_Search::DIMP_QUICKSEARCH),
172            'refresh_time' => intval($prefs->getValue('refresh_time')),
173            'sidebar_width' => max(intval($prefs->getValue('sidebar_width')), 150),
174            'sort' => array(
175                'from' => array(
176                    'c' => 'msgFrom',
177                    't' => _("From"),
178                    'v' => Horde_Imap_Client::SORT_FROM
179                ),
180                'to' => array(
181                    'c' => 'msgFrom',
182                    'ec' => 'msgFromTo',
183                    't' => _("To"),
184                    'v' => Horde_Imap_Client::SORT_TO
185                ),
186                'subject' => array(
187                    'c' => 'msgSubject',
188                    't' => _("Subject"),
189                    'v' => Horde_Imap_Client::SORT_SUBJECT
190                ),
191                'thread' => array(
192                    'c' => 'msgSubject',
193                    'v' => Horde_Imap_Client::SORT_THREAD
194                ),
195                'date' => array(
196                    'c' => 'msgDate',
197                    't' => _("Date"),
198                    'v' => IMP::IMAP_SORT_DATE
199                ),
200                'msgarrival' => array(
201                    'c' => 'msgDate',
202                    'v' => Horde_Imap_Client::SORT_ARRIVAL
203                ),
204                'msgdate' => array(
205                    'c' => 'msgDate',
206                    'v' => Horde_Imap_Client::SORT_DATE
207                ),
208                'sequence' => array(
209                    'v' => Horde_Imap_Client::SORT_SEQUENCE
210                ),
211                'size' => array(
212                    'c' => 'msgSize',
213                    't' => _("Size"),
214                    'v' => Horde_Imap_Client::SORT_SIZE
215                )
216            ),
217            'subscribe' => intval($subscribe)
218        ));
219
220        $context = array(
221            'ctx_container' => array(
222                '_mbox' => '',
223                '_sep1' => null,
224                'create' => _("Create subfolder"),
225                'rename' => _("Rename"),
226                'delete' => _("Delete subfolders"),
227                '_sep2' => null,
228                'search' => _("Search"),
229                '_sep3' => null,
230                'expand' => _("Expand All"),
231                'collapse' => _("Collapse All")
232            ),
233            'ctx_datesort' => array(
234                '*msgarrival' => _("Arrival Time"),
235                '*msgdate' => _("Message Date")
236            ),
237            'ctx_flag' => array(),
238            'ctx_flagunset' => array(),
239            'ctx_flag_search' => array(),
240            'ctx_mbox_flag' => array(
241                'seen' => _("Seen"),
242                'unseen' => _("Unseen")
243            ),
244            'ctx_noactions' => array(
245                '_mbox' => '',
246                '_sep1' => null,
247                'noaction' => _("No actions available")
248            ),
249            'ctx_remoteauth' => array(
250                '_mbox' => '',
251                '_sep1' => null,
252                'create' => _("Create Mailbox"),
253                'logout' => _("Log Out")
254            ),
255            'ctx_sortopts' => array(
256                'from' => _("From"),
257                'to' => _("To"),
258                'subject' => _("Subject"),
259                'thread' => _("Thread"),
260                'msgarrival' => _("Date (Arrival)"),
261                'msgdate' => _("Date (Message)"),
262                'size' => _("Size"),
263                '_sep1' => null,
264                'sequence' => _("No Sort")
265            ),
266            'ctx_subjectsort' => array(
267                'thread' => _("Thread Sort"),
268            ),
269            'ctx_template' => array(
270                'edit' => _("Edit Template"),
271                'new' => _("Create New Template")
272            ),
273            'ctx_vcontainer' => array(
274                '_mbox' => _("Virtual Folders"),
275                '_sep1' => null,
276                'edit' => _("Edit Virtual Folders")
277            ),
278            'ctx_vfolder' => array(
279                '_mbox' => '',
280                '_sep1' => null,
281                'edit' => _("Edit Virtual Folder"),
282                'delete' => _("Delete Virtual Folder")
283            )
284        );
285
286        /* Folder options context menu. */
287        if ($imp_imap->access(IMP_Imap::ACCESS_FOLDERS)) {
288            $context['ctx_folderopts'] = array(
289                'new' => _("Create Mailbox"),
290                'sub' => _("Hide Unsubscribed"),
291                'unsub' => _("Show All Mailboxes"),
292                'expand' => _("Expand All"),
293                'collapse' => _("Collapse All"),
294                '_sep1' => null,
295                'reload' => _("Rebuild Folder List")
296            );
297        }
298
299        if (!$subscribe) {
300            unset(
301                $context['ctx_folderopts']['sub'],
302                $context['ctx_folderopts']['unsub']
303            );
304        }
305
306        /* Message context menu. */
307        $context['ctx_message'] = array(
308            '_sub1' => array(
309                'resume' => _("Resume Draft"),
310                'template' => _("Use Template"),
311                'template_edit' => _("Edit Template"),
312                'view' => _("View Message")
313            ),
314            'reply' => _("Reply"),
315            'forward' => _("Forward"),
316            '_sub2' => array(
317                '_sep1' => null,
318                'setflag' => _("Mark as") . '...',
319                'unsetflag' => _("Unmark as") . '...',
320            ),
321            '_sep2' => null,
322            'spam' => _("Report as Spam"),
323            'innocent' => _("Report as Innocent"),
324            'blacklist' => _("Blacklist"),
325            'whitelist' => _("Whitelist"),
326            'addfilter' => _("Create Filter"),
327            'delete' => _("Delete"),
328            'undelete' => _("Undelete"),
329            '_sub3' => array(
330                '_sep3' => null,
331                'source' => _("View Source")
332            )
333        );
334
335        if (empty($imp_imap->config->spam_params)) {
336            unset($context['ctx_message']['spam']);
337        }
338        if (empty($imp_imap->config->innocent_params)) {
339            unset($context['ctx_message']['innocent']);
340        }
341        if (!$registry->hasLink('mail/newEmailFilter')) {
342            unset($context['ctx_message']['addfilter']);
343        }
344        if ($prefs->getValue('use_trash')) {
345            unset($context['ctx_message']['undelete']);
346        }
347        if (empty($conf['user']['allow_view_source'])) {
348            unset($context['ctx_message']['_sub3']);
349        }
350
351        /* Mailbox context menu. */
352        $context['ctx_mbox'] = array(
353            '_mbox' => '',
354            '_sep1' => null,
355            'create' => _("Create subfolder"),
356            'rename' => _("Rename"),
357            'empty' => _("Empty"),
358            'delete' => _("Delete"),
359            '_sep2' => null,
360            'setflag' => _("Mark all as"),
361            '_sep3' => null,
362            'poll' => _("Check for New Mail"),
363            'nopoll' => _("Do Not Check for New Mail"),
364            'sub' => _("Subscribe"),
365            'unsub' => _("Unsubscribe"),
366            '_sep4' => null,
367            'search' => _("Search"),
368            '_sub1' => array(
369                '_sep5' => null,
370                'expand' => _("Expand All"),
371                'collapse' => _("Collapse All")
372            ),
373            '_sep6' => null,
374            'export' => _("Export"),
375            'import' => _("Import"),
376            '_sep7' => null,
377            'size' => _("Mailbox Size"),
378            '_sub2' => array(
379                '_sep8' => null,
380                'acl' => _("Edit ACL")
381            ),
382        );
383
384        if (!$subscribe) {
385            unset(
386                $context['ctx_mbox']['sub'],
387                $context['ctx_mbox']['unsub']
388            );
389        }
390        if (!$imp_imap->access(IMP_Imap::ACCESS_IMPORT)) {
391            unset($context['ctx_mbox']['import']);
392        }
393        if (!$imp_imap->access(IMP_Imap::ACCESS_FLAGS)) {
394            unset(
395                $context['ctx_mbox']['_sep2'],
396                $context['ctx_mbox']['setflag'],
397                $context['ctx_mbox']['_sep3'],
398                $context['ctx_mbox']['poll'],
399                $context['ctx_mbox']['nopoll']
400            );
401        }
402        if (!$imp_imap->access(IMP_Imap::ACCESS_FOLDERS)) {
403            unset(
404                $context['ctx_mbox']['_sep7'],
405                $context['ctx_mbox']['size']
406            );
407        }
408        if (!$imp_imap->access(IMP_Imap::ACCESS_SEARCH)) {
409            unset(
410                $context['ctx_mbox']['_sep4'],
411                $context['ctx_mbox']['search']
412            );
413        }
414        if (!$imp_imap->access(IMP_Imap::ACCESS_FLAGS) ||
415            $prefs->isLocked('acl')) {
416            unset(
417                $context['ctx_mbox']['_sub2']
418            );
419        }
420
421        /* Other Actions context menu. */
422        $context['ctx_oa'] = array(
423            'preview_hide' => _("Hide Preview"),
424            'preview_show' => _("Show Preview"),
425            'layout_horiz' => _("Horizontal Layout"),
426            'layout_vert' => _("Vertical Layout"),
427            '_sub1' => array(
428                '_sep1' => null,
429                'setflag' => _("Mark as") . '...',
430                'unsetflag' => _("Unmark as") . '...',
431            ),
432            'blacklist' => _("Blacklist"),
433            'whitelist' => _("Whitelist"),
434            '_sub2' => array(
435                '_sep2' => null,
436                'purge_deleted' => _("Purge Deleted"),
437                'undelete' => _("Undelete")
438            ),
439            'show_deleted' => _("Show Deleted"),
440            'hide_deleted' => _("Hide Deleted"),
441            '_sub3' => array(
442                '_sep3' => null,
443                'clear_sort' => _("Clear Sort")
444            )
445        );
446        if ($prefs->getValue('use_trash')) {
447            unset($context['ctx_oa']['_sub2']);
448        }
449        if ($prefs->isLocked('delhide')) {
450            unset($context['ctx_oa']['hide_deleted']);
451        }
452
453        /* Shared between message and other actions menus. */
454        if (!$registry->hasMethod('mail/blacklistFrom')) {
455            unset(
456                $context['ctx_message']['blacklist'],
457                $context['ctx_oa']['blacklist']
458            );
459        }
460        if (!$registry->hasMethod('mail/whitelistFrom')) {
461            unset(
462                $context['ctx_message']['whitelist'],
463                $context['ctx_oa']['whitelist']
464            );
465        }
466
467        /* Preview context menu. */
468        $context['ctx_preview'] = array(
469            'save' => _("Save"),
470            'viewsource' => _("View Source"),
471            'allparts' => _("All Parts"),
472            'thread' => _("View Thread"),
473            'listinfo' => _("List Info")
474        );
475
476        if (empty($conf['user']['allow_view_source'])) {
477            unset($context['ctx_preview']['viewsource']);
478        }
479
480        /* Search related context menus. */
481        if ($imp_imap->access(IMP_Imap::ACCESS_SEARCH)) {
482            $context['ctx_filteropts'] = array(
483                '*filter' => _("Filter By"),
484                '*flag' => _("Show Only"),
485                '*flagnot' => _("Don't Show")
486            );
487            if (IMP_Filter::canApplyFilters()) {
488                $context['ctx_filteropts']['_sub1'] = array(
489                    '_sep1' => null,
490                    'applyfilters' => _("Apply Filters")
491                );
492            }
493
494            $context['ctx_qsearchopts'] = array(
495                '*all' => _("Entire Message"),
496                '*body' => _("Body"),
497                '*from' => _("From"),
498                '*recip' => _("Recipients (To/Cc/Bcc)"),
499                '*subject' => _("Subject"),
500                '_sep1' => null,
501                '*advanced' => _("Advanced Search...")
502            );
503            /* Generate filter array. */
504            $iterator = IMP_Search_IteratorFilter::create(
505                IMP_Search_IteratorFilter::FILTER
506            );
507
508            $context['ctx_filter'] = array();
509            foreach ($iterator as $val) {
510                if ($val->enabled) {
511                    $context['ctx_filter']['*' . $val->id] = $val->label;
512                }
513            }
514        }
515
516        /* Remote accounts context menu. */
517        if ($imp_imap->access(IMP_Imap::ACCESS_REMOTE)) {
518            $context['ctx_rcontainer'] = array(
519                '*prefs' => _("Manage Remote Accounts")
520            );
521        }
522
523        $this->js_context = array_merge($context, $this->js_context);
524
525        $this->js_text += array(
526            'badaddr' => _("Invalid Address"),
527            'badsubject' => _("Invalid Subject"),
528            'baselevel' => _("base level of the folder tree"),
529            'check' => _("Checking..."),
530            'copyto' => _("Copy %s to %s"),
531            'create_prompt' => _("Create mailbox:"),
532            'createsub_prompt' => _("Create subfolder of %s:"),
533            'delete_mbox' => _("Permanently delete %s?"),
534            'delete_mbox_subfolders' => _("Delete all subfolders of %s?"),
535            'download_mbox' => _("All messages in this mailbox will be downloaded into the format that you choose. Depending on the size of the mailbox, this action may take awhile."),
536            'editflag' => _("Edit Flags..."),
537            'empty_mbox' => _("Permanently delete all %d messages in %s?"),
538            'import_mbox' => _("Mbox or .eml file:"),
539            'import_mbox_loading' => _("Importing (this may take some time)..."),
540            'listmsg_wait' => _("The server is still generating the message list."),
541            'listmsg_timeout' => _("The server was unable to generate the message list."),
542            'message_0' => _("No messages"),
543            'message_1' => _("1 message"),
544            'message_2' => _("%d messages"),
545            'mboxsize' => _("%s is: %s."),
546            'moveto' => _("Move %s to %s"),
547            'newflag' => _("Create New Flag..."),
548            'newflag_name' => _("Flag Name:"),
549            'newflag_wait' => _("Creating New Flag..."),
550            'onlogout' => _("Logging Out..."),
551            'portal' => _("Portal"),
552            'prefs' => _("User Options"),
553            'remote_password' => _("Password for %s:"),
554            'rename_prompt' => _("Rename %s to:"),
555            'search' => _("Search"),
556            'search_input' => _("Search (%s)"),
557            'search_time' => _("Results are %d Minutes Old"),
558            'selected' => _("%s selected."),
559            'slidertext' => _("Messages %d - %d"),
560            'vfolder' => _("Virtual Folder: %s"),
561            'vp_empty' => _("There are no messages in this mailbox."),
562            'vp_empty_search' => _("No messages matched the search query.")
563        );
564
565        if ($subscribe) {
566            $this->js_text += array(
567                'subscribe_mbox' => _("Subscribe to %s?"),
568                'subscribe_mbox_subfolders' => _("Subscribe to all subfolders of %s?"),
569                'unsubscribe_mbox' => _("Unsubscribe to %s?"),
570                'unsubscribe_mbox_subfolders' => _("Unsubscribe to all subfolders of %s?"),
571            );
572        }
573    }
574
575}
576