1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15: class IMP_Minimal_Mailbox extends IMP_Minimal_Base
16: {
17: 18: 19: 20: 21: 22: 23: 24: 25:
26: protected function _init()
27: {
28: global $injector, $notification, $prefs, $session;
29:
30: $imp_imap = $this->indices->mailbox->imp_imap;
31: $imp_search = $injector->getInstance('IMP_Search');
32:
33:
34: $readonly = $this->indices->mailbox->readonly;
35:
36:
37: $mailbox_url = self::url(array('mailbox' => $this->indices->mailbox));
38:
39:
40: switch ($this->vars->checkbox) {
41:
42:
43: case 'd':
44: case 'u':
45: $imp_message = $injector->getInstance('IMP_Message');
46:
47: if ($this->vars->checkbox == 'd') {
48: try {
49: $session->checkToken($this->vars->t);
50: $imp_message->delete($this->indices);
51: } catch (Horde_Exception $e) {
52: $notification->push($e);
53: }
54: } else {
55: $imp_message->undelete($this->indices);
56: }
57: break;
58:
59:
60:
61: case 'rs':
62: case 'ri':
63: $injector->getInstance('IMP_Factory_Spam')->create($this->vars->checkbox == 'rs' ? IMP_Spam::SPAM : IMP_Spam::INNOCENT)->report($this->indices);
64: break;
65: }
66:
67:
68: switch ($this->vars->a) {
69:
70: case 'm':
71: $notification->push(_("There was an error viewing the requested message."), 'horde.error');
72: break;
73:
74:
75: case 'e':
76: $injector->getInstance('IMP_Message')->expungeMailbox(array(strval($this->indices->mailbox) => 1));
77: break;
78:
79:
80: case 'ds':
81: if (!empty($this->vars->search) &&
82: $this->indices->mailbox->access_search) {
83: 84:
85: $q_ob = $imp_search->createQuery(array(new IMP_Search_Element_Text($this->vars->search, false)), array(
86: 'mboxes' => array($this->indices->mailbox)
87: ));
88:
89:
90: $this->indices->mailbox = IMP_Mailbox::get($q_ob);
91: $readonly = $this->indices->mailbox->readonly;
92: $mailbox_url = self::url(array('mailbox' => $this->indices->mailbox));
93: }
94: break;
95: }
96:
97:
98: $imp_mailbox = $this->indices->mailbox->list_ob;
99: $pageOb = $imp_mailbox->buildMailboxPage($this->vars->p, $this->vars->start);
100:
101:
102: $this->title = $this->indices->mailbox->display;
103:
104:
105: if ($pageOb['msgcount']) {
106: $this->title .= ' (';
107: if ($imp_imap->access(IMP_Imap::ACCESS_UNSEEN)) {
108: $unseen = $imp_mailbox->unseenMessages(Horde_Imap_Client::SEARCH_RESULTS_COUNT);
109: $this->title .= sprintf(_("%d unseen"), $unseen) . '/';
110: }
111: $this->title .= sprintf(_("%d total"), $pageOb['msgcount']) . ')';
112: }
113: if ($pageOb['pagecount'] > 1) {
114: $this->title .= ' - ' . sprintf(_("%d of %d"), $pageOb['page'], $pageOb['pagecount']);
115: }
116: if ($readonly) {
117: $this->title .= ' [' . _("Read-Only") . ']';
118: }
119: $this->view->title = $this->title;
120:
121:
122: $imp_ui = new IMP_Mailbox_Ui($this->indices->mailbox);
123: $mbox_info = $imp_mailbox->getMailboxArray(range($pageOb['begin'], $pageOb['end']), array('headers' => true));
124: $msgs = array();
125:
126: while (list(,$ob) = each($mbox_info['overview'])) {
127:
128: $msg = array(
129: 'buid' => $imp_mailbox->getBuid($ob['mailbox'], $ob['uid']),
130: 'status' => '',
131: 'subject' => trim($imp_ui->getSubject($ob['envelope']->subject))
132: );
133:
134:
135: $getfrom = $imp_ui->getFrom($ob['envelope']);
136: $msg['from'] = $getfrom['from'];
137:
138:
139: $flag_parse = $injector->getInstance('IMP_Flags')->parse(array(
140: 'flags' => $ob['flags'],
141: 'headers' => $ob['headers'],
142: 'personal' => $ob['envelope']->to
143: ));
144:
145: foreach ($flag_parse as $val) {
146: if ($abbrev = $val->abbreviation) {
147: $msg['status'] .= $abbrev;
148: } elseif ($val instanceof IMP_Flag_User) {
149: $msg['subject'] = '*' . Horde_String::truncate($val->label, 8) . '* ' . $msg['subject'];
150: }
151: }
152:
153:
154: if ($this->indices->mailbox->templates) {
155: $compose = 't';
156: } elseif ($this->indices->mailbox->draft ||
157: in_array(Horde_Imap_Client::FLAG_DRAFT, $ob['flags'])) {
158: $compose = 'd';
159: } else {
160: $msg['target'] = IMP_Minimal_Message::url(array(
161: 'buid' => $msg['buid'],
162: 'mailbox' => $this->indices->mailbox
163: ));
164: }
165:
166: if (!isset($msg['target'])) {
167: $clink = new IMP_Compose_Link();
168: $msg['target'] = $clink->link()->add(array(
169: 'a' => $compose,
170: 'buid' => $msg['buid'],
171: 'bodypart' => 1,
172: 'mailbox' => $this->indices->mailbox
173: ));
174: }
175:
176: $msgs[] = $msg;
177: }
178: $this->view->msgs = $msgs;
179:
180: $mailbox = $mailbox_url->copy()->add('p', $pageOb['page']);
181: $menu = array(array(_("Refresh"), $mailbox));
182: $search_mbox = $this->indices->mailbox->search;
183:
184:
185: if (!$prefs->getValue('use_trash') &&
186: !$this->indices->mailbox->vinbox &&
187: $this->indices->mailbox->access_expunge) {
188: $menu[] = array(_("Purge Deleted"), $mailbox->copy()->add('a', 'e'));
189: }
190:
191:
192: if ($this->indices->mailbox->access_search) {
193: if ($search_mbox) {
194: $mboxes = $imp_search[strval($this->indices->mailbox)]->mboxes;
195: $orig_mbox = IMP_Mailbox::get(reset($mboxes));
196: $menu[] = array(sprintf(_("New Search in %s"), $orig_mbox->label), IMP_Minimal_Search::url(array('mailbox' => $orig_mbox)));
197: } else {
198: $menu[] = array(_("Search"), IMP_Minimal_Search::url(array('mailbox' => $this->indices->mailbox)));
199: }
200: }
201:
202:
203: if ($pageOb['page'] != 1) {
204: $menu[] = array(_("First Page"), $mailbox_url->copy()->add('p', 1));
205: $menu[] = array(_("Previous Page"), $mailbox_url->copy()->add('p', $pageOb['page'] - 1));
206: }
207: if ($pageOb['page'] != $pageOb['pagecount']) {
208: $menu[] = array(_("Next Page"), $mailbox_url->copy()->add('p', $pageOb['page'] + 1));
209: $menu[] = array(_("Last Page"), $mailbox_url->copy()->add('p', $pageOb['pagecount']));
210: }
211:
212: $this->view->menu = $this->getMenu('mailbox', $menu);
213:
214: $this->view->checkbox = $mailbox_url->copy()->add('p', $pageOb['page']);
215: $this->view->delete = $this->indices->mailbox->access_deletemsgs;
216: $this->view->t = $session->getToken();
217:
218: $this->_pages[] = 'mailbox';
219: $this->_pages[] = 'menu';
220: }
221:
222: 223: 224: 225:
226: public static function url(array $opts = array())
227: {
228: $opts = array_merge(array('mailbox' => 'INBOX'), $opts);
229:
230: return IMP_Mailbox::get($opts['mailbox'])->url('minimal')->add('page', 'mailbox');
231: }
232:
233: }
234: