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_Thread extends IMP_Basic_Base
25: {
26: 27:
28: protected function _init()
29: {
30: global $injector, $notification, $page_output, $registry, $session;
31:
32: $imp_mailbox = $this->indices->mailbox->list_ob;
33:
34: switch ($mode = $this->vars->get('mode', 'thread')) {
35: case 'thread':
36:
37: list($m, $u) = $this->indices->getSingle();
38: $imp_indices = $imp_mailbox->getFullThread($u, $m);
39: break;
40:
41: default:
42:
43: $imp_indices = $this->indices;
44: break;
45: }
46:
47: if (!count($imp_indices)) {
48: $notification->push(_("Could not load message."), 'horde.error');
49: $this->indices->mailbox->url('mailbox')->redirect();
50: }
51:
52:
53: switch ($this->vars->actionID) {
54: case 'add_address':
55: try {
56: $contact_link = $injector->getInstance('IMP_Contacts')->addAddress($this->vars->address, $this->vars->name);
57: $notification->push(sprintf(_("Entry \"%s\" was successfully added to the address book"), $contact_link), 'horde.success', array('content.raw'));
58: } catch (Horde_Exception $e) {
59: $notification->push($e);
60: }
61: break;
62: }
63:
64: $msgs = $tree = array();
65: $subject = '';
66: $page_label = $this->indices->mailbox->label;
67:
68: $imp_ui = $injector->getInstance('IMP_Message_Ui');
69:
70: $query = new Horde_Imap_Client_Fetch_Query();
71: $query->envelope();
72:
73:
74: $injector->getInstance('IMP_Images')->alwaysShow = true;
75:
76: $multiple = (count($imp_indices) > 1);
77:
78: foreach ($imp_indices as $ob) {
79: $imp_imap = $ob->mbox->imp_imap;
80: $fetch_res = $imp_imap->fetch($ob->mbox, $query, array(
81: 'ids' => $imp_imap->getIdsOb($ob->uids)
82: ));
83:
84: foreach ($ob->uids as $idx) {
85: $envelope = $fetch_res[$idx]->getEnvelope();
86:
87:
88: $curr_msg = $curr_tree = array();
89: $contents = $injector->getInstance('IMP_Factory_Contents')->create($ob->mbox->getIndicesOb($idx));
90: $mime_id = $contents->findBody();
91: if ($contents->canDisplay($mime_id, IMP_Contents::RENDER_INLINE)) {
92: $ret = $contents->renderMIMEPart($mime_id, IMP_Contents::RENDER_INLINE);
93: $ret = reset($ret);
94: $curr_msg['body'] = $ret['data'];
95:
96: if (!empty($ret['js'])) {
97: $page_output->addInlineScript($ret['js'], true);
98: }
99: } else {
100: $curr_msg['body'] = '<em>' . _("There is no text that can be displayed inline.") . '</em>';
101: }
102: $curr_msg['idx'] = $idx;
103:
104:
105: $date_ob = new IMP_Message_Date($envelope->date);
106: $curr_msg['date'] = $date_ob->format($date_ob::DATE_LOCAL);
107:
108: if ($this->indices->mailbox->special_outgoing) {
109: $curr_msg['addr_to'] = true;
110: $curr_msg['addr'] = _("To:") . ' ' . $imp_ui->buildAddressLinks($envelope->to, Horde::selfUrlParams());
111: $addr = _("To:") . ' ' . htmlspecialchars($envelope->to[0]->label, ENT_COMPAT, 'UTF-8');
112: } else {
113: $from = $envelope->from;
114: $curr_msg['addr_to'] = false;
115: $curr_msg['addr'] = $imp_ui->buildAddressLinks($from, Horde::selfUrlParams());
116: $addr = htmlspecialchars($from[0]->label, ENT_COMPAT, 'UTF-8');
117: }
118:
119: $subject_header = htmlspecialchars($envelope->subject, ENT_COMPAT, 'UTF-8');
120:
121: switch ($mode) {
122: case 'thread':
123: if (empty($subject)) {
124: $subject = preg_replace('/^re:\s*/i', '', $subject_header);
125: }
126: $curr_msg['link'] = $multiple
127: ? Horde::widget(array('url' => '#display', 'title' => _("Thread List"), 'nocheck' => true))
128: : '';
129: $curr_tree['subject'] = $imp_mailbox->getThreadOb($imp_mailbox->getArrayIndex($fetch_res[$idx]->getUid(), $ob->mbox) + 1)->img;
130: break;
131:
132: default:
133: $curr_msg['link'] = Horde::widget(array('url' => '#display', 'title' => _("Back to Multiple Message View Index"), 'nocheck' => true));
134: $curr_tree['subject'] = '';
135: break;
136: }
137:
138: switch ($registry->getView()) {
139: case $registry::VIEW_BASIC:
140: $curr_msg['link'] .= ' | ' . Horde::widget(array('url' => $this->indices->mailbox->url('message', $idx), 'title' => _("Go to Message"), 'nocheck' => true)) .
141: ' | ' . Horde::widget(array('url' => $this->indices->mailbox->url('mailbox')->add(array('start' => $imp_mailbox->getArrayIndex($idx))), 'title' => sprintf(_("Bac_k to %s"), $page_label)));
142: break;
143: }
144:
145: $curr_tree['subject'] .= Horde::link('#i' . $idx) . Horde_String::truncate($subject_header, 60) . '</a> (' . $addr . ')';
146:
147: $msgs[] = $curr_msg;
148: $tree[] = $curr_tree;
149: }
150: }
151:
152:
153: $injector->getInstance('IMP_Message')->flag(array(
154: 'add' => array(Horde_Imap_Client::FLAG_SEEN)
155: ), $imp_indices);
156:
157: $view = new Horde_View(array(
158: 'templatePath' => IMP_TEMPLATES . '/thread'
159: ));
160:
161: if ($mode == 'thread') {
162: $view->subject = $subject;
163: $view->thread = true;
164:
165: switch ($registry->getView()) {
166: case $registry::VIEW_BASIC:
167: $uid_list = $imp_indices[strval($this->indices->mailbox)];
168: $delete_link = $this->indices->mailbox->url('mailbox')->add(array(
169: 'actionID' => 'delete_messages',
170: 'indices' => strval($imp_indices),
171: 'token' => $session->getToken(),
172: 'start' => $imp_mailbox->getArrayIndex(end($uid_list))
173: ));
174: $view->delete = Horde::link($delete_link, _("Delete Thread"), null, null, null, null, null, array('id' => 'threaddelete'));
175: $page_output->addInlineScript(array(
176: '$("threaddelete").observe("click", function(e) { if (!window.confirm(' . json_encode(_("Are you sure you want to delete all messages in this thread?")) . ')) { e.stop(); } })'
177: ), true);
178: break;
179: }
180: } else {
181: $view->subject = sprintf(_("%d Messages"), count($msgs));
182: }
183: $view->messages = $msgs;
184: $view->tree = $tree;
185:
186: $page_output->addScriptFile('stripe.js', 'horde');
187: $page_output->addScriptFile('toggle_quotes.js', 'horde');
188: $page_output->noDnsPrefetch();
189:
190: $this->output = $view->render('thread');
191:
192: switch ($registry->getView()) {
193: case $registry::VIEW_DYNAMIC:
194: $page_output->topbar = $page_output->sidebar = false;
195: $this->header_params = array(
196: 'html_id' => 'htmlAllowScroll'
197: );
198: break;
199: }
200:
201: $this->title = ($mode == 'thread')
202: ? _("Thread View")
203: : _("Multiple Message View");
204: }
205:
206: 207:
208: public function status()
209: {
210: global $registry;
211:
212: return ($registry->getView() == $registry::VIEW_DYNAMIC)
213: ? ''
214: : parent::status();
215: }
216:
217: 218:
219: public static function url(array $opts = array())
220: {
221: return Horde::url('basic.php')
222: ->add('page', 'thread')
223: ->unique()
224: ->setRaw(!empty($opts['full']));
225: }
226:
227: }
228: