1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15:
16: class IMP_Ui_Message
17: {
18: 19: 20: 21: 22:
23: public function ()
24: {
25: return array(
26: 'date' => _("Date"),
27: 'from' => _("From"),
28: 'to' => _("To"),
29: 'cc' => _("Cc"),
30: 'bcc' => _("Bcc"),
31: 'reply-to' => _("Reply-To"),
32: 'subject' => _("Subject")
33: );
34: }
35:
36: 37: 38: 39: 40:
41: public function ()
42: {
43: $user_hdrs = $GLOBALS['prefs']->getValue('mail_hdr');
44:
45: 46:
47: if (is_array($user_hdrs)) {
48: $user_hdrs = implode("\n", $user_hdrs);
49: }
50: $user_hdrs = trim($user_hdrs);
51: if (empty($user_hdrs)) {
52: return array();
53: }
54:
55: $user_hdrs = array_filter(array_keys(array_flip(array_map('trim', preg_split("/[\n\r]+/", str_replace(':', '', $user_hdrs))))));
56: natcasesort($user_hdrs);
57:
58: return $user_hdrs;
59: }
60:
61: 62: 63: 64: 65: 66: 67: 68: 69: 70:
71: public function MDNCheck(IMP_Mailbox $mailbox, $uid, $headers,
72: $confirmed = false)
73: {
74: $imp_imap = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create();
75: $pref_val = $GLOBALS['prefs']->getValue('send_mdn');
76:
77: if (!$pref_val || $mailbox->readonly) {
78: return false;
79: }
80:
81:
82: $mdn = new Horde_Mime_Mdn($headers);
83: $return_addr = $mdn->getMdnReturnAddr();
84: if (!$return_addr) {
85: return false;
86: }
87:
88: $msg_id = $headers->getValue('message-id');
89: $mdn_flag = $mdn_sent = false;
90:
91:
92:
93: if ($mailbox->permflags->allowed('$mdnsent')) {
94: $mdn_flag = true;
95:
96: $query = new Horde_Imap_Client_Fetch_Query();
97: $query->flags();
98:
99: try {
100: $res = $imp_imap->fetch($mailbox, $query, array(
101: 'ids' => $imp_imap->getIdsOb($uid)
102: ));
103: $mdn_sent = in_array('$mdnsent', $res[$uid]->getFlags());
104: } catch (IMP_Imap_Exception $e) {}
105: } else {
106:
107: $mdn_sent = IMP_Maillog::sentMDN($msg_id, 'displayed');
108: }
109:
110: if ($mdn_sent) {
111: return false;
112: }
113:
114:
115: if (!$confirmed &&
116: ((intval($pref_val) == 1) ||
117: $mdn->userConfirmationNeeded())) {
118: try {
119: if (Horde::callHook('mdn_check', array($headers), 'imp')) {
120: return true;
121: }
122: } catch (Horde_Exception_HookNotSet $e) {
123: return true;
124: }
125: }
126:
127:
128: try {
129: $mdn->generate(
130: false,
131: $confirmed,
132: 'displayed',
133: $GLOBALS['conf']['server']['name'],
134: $GLOBALS['injector']->getInstance('IMP_Mail'),
135: array(
136: 'charset' => 'UTF-8',
137: 'from_addr' => $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create()->getDefaultFromAddress()
138: )
139: );
140: IMP_Maillog::log(IMP_Maillog::MDN, $msg_id, 'displayed');
141: $success = true;
142:
143: if ($mdn_flag) {
144: $GLOBALS['injector']->getInstance('IMP_Message')->flag(array(Horde_Imap_Client::FLAG_MDNSENT), $mailbox->getIndicesOb($uid), true);
145: }
146: } catch (Exception $e) {
147: $success = false;
148: }
149:
150: $GLOBALS['injector']->getInstance('IMP_Sentmail')->log(IMP_Sentmail::MDN, '', $return_addr, $success);
151:
152: return false;
153: }
154:
155: 156: 157: 158: 159: 160: 161:
162: public function getLocalTime(Horde_Imap_Client_DateTime $date)
163: {
164: $time_str = strftime($GLOBALS['prefs']->getValue('time_format'), strval($date));
165: $tz = strftime('%Z');
166:
167: if ((date('Y') != $date->format('Y')) ||
168: (date('M') != $date->format('M')) ||
169: (date('d') != $date->format('d'))) {
170:
171: $date_str = strftime($GLOBALS['prefs']->getValue('date_format'), strval($date));
172: return sprintf('%s (%s %s)', $date_str, $time_str, $tz);
173: }
174:
175:
176: return sprintf(_("Today, %s %s"), $time_str, $tz);
177: }
178:
179: 180: 181: 182: 183: 184: 185: 186:
187: public function ($headers)
188: {
189: $ret = array();
190:
191: foreach (array_keys($headers->listHeaders()) as $val) {
192: if (($data = $headers->getValue($val))) {
193: $ret[$val] = $this->parseListHeaders($data);
194: }
195: }
196:
197: return $ret;
198: }
199:
200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214:
215: public function ($data, $opts = array())
216: {
217: $output = '';
218:
219:
220: foreach (explode(',', $data) as $orig_entry) {
221: $entry = Horde_Mime_Address::trimAddress($orig_entry);
222:
223: 224:
225: if (trim($orig_entry) == $entry) {
226: return $entry;
227: }
228:
229:
230: $match = preg_replace("/\s+/", '', $entry);
231:
232:
233: preg_match("/(\(.+\))/", $entry, $comments);
234:
235: 236:
237: if (stristr($match, 'mailto:') !== false) {
238: $match = substr($match, strpos($match, ':') + 1);
239: if (!empty($opts['raw'])) {
240: return $match;
241: }
242: $output = Horde::link(IMP::composeLink($match)) . $match . '</a>';
243: if (!empty($comments[1])) {
244: $output .= ' ' . $comments[1];
245: }
246:
247: return $output;
248: } elseif ($url = $GLOBALS['injector']->getInstance('Horde_Core_Factory_TextFilter')->filter($match, 'linkurls')) {
249: if (!empty($opts['email'])) {
250: continue;
251: }
252:
253: if (!empty($opts['raw'])) {
254: return $match;
255: }
256:
257: $output = $url;
258: if (!empty($comments[1])) {
259: $output .= ' ' . $comments[1];
260: }
261:
262: return $output;
263: } else {
264:
265: $output = $match;
266: }
267: }
268:
269: return $output;
270: }
271:
272: 273: 274: 275: 276: 277: 278:
279: public function getListInformation($headers)
280: {
281: $ret = array('exists' => false, 'reply_list' => null);
282:
283: if ($headers->listHeadersExist()) {
284: $ret['exists'] = true;
285:
286: 287:
288: if (($val = $headers->getValue('list-post')) &&
289: ($val != 'NO')) {
290: $ret['reply_list'] = $this->parseListHeaders($val, array('email' => true, 'raw' => true));
291: }
292: }
293:
294: return $ret;
295: }
296:
297: 298: 299: 300: 301: 302: 303: 304: 305: 306:
307: public function buildAddressLinks($addrlist, $addURL = null, $link = true)
308: {
309: global $prefs, $registry;
310:
311:
312: if (empty($addrlist) || !is_array($addrlist)) {
313: return null;
314: }
315:
316: $add_link = null;
317: $addr_array = array();
318: $mimp_view = IMP::getViewMode() == 'mimp';
319:
320: 321:
322: if (!is_null($addURL) && $link && $prefs->getValue('add_source')) {
323: try {
324: $add_link = $registry->hasMethod('contacts/import')
325: ? $addURL->copy()->add('actionID', 'add_address')
326: : null;
327: } catch (Horde_Exception $e) {}
328: }
329:
330: foreach (Horde_Mime_Address::getAddressesFromObject($addrlist, array('charset' => 'UTF-8')) as $ob) {
331: if (isset($ob['groupname'])) {
332: $group_array = array();
333: foreach ($ob['addresses'] as $ad) {
334: if (empty($ad['address']) || empty($ad['inner'])) {
335: continue;
336: }
337:
338: $ret = $mimp_view
339: ? $ad['display']
340: : htmlspecialchars($ad['display']);
341:
342: if ($link) {
343: $ret = Horde::link(IMP::composeLink(array('to' => $ad['address'])), sprintf(_("New Message to %s"), $ad['inner'])) . htmlspecialchars($ad['display']) . '</a>';
344: }
345:
346: 347:
348: if ($add_link) {
349: $curr_link = $add_link->copy()->add(array('name' => $ad['personal'], 'address' => $ad['inner']));
350: $ret .= Horde::link($curr_link, sprintf(_("Add %s to my Address Book"), $ad['inner'])) .
351: '<span class="iconImg addrbookaddImg"></span></a>';
352: }
353:
354: $group_array[] = $ret;
355: }
356:
357: if (!$mimp_view) {
358: $ob['groupname'] = htmlspecialchars($ob['groupname']);
359: }
360:
361: $addr_array[] = $ob['groupname'] . ':' . (count($group_array) ? ' ' . implode(', ', $group_array) : '');
362: } elseif (!empty($ob['address']) && !empty($ob['inner'])) {
363: $ret = $mimp_view
364: ? $ob['display']
365: : htmlspecialchars($ob['display']);
366:
367: 368:
369: if (stristr($ob['host'], 'UNKNOWN') === false) {
370: if ($link) {
371: $ret = Horde::link(IMP::composeLink(array('to' => $ob['address'])), sprintf(_("New Message to %s"), $ob['inner'])) . htmlspecialchars($ob['display']) . '</a>';
372: }
373:
374: 375:
376: if ($add_link) {
377: $curr_link = $add_link->copy()->add(array('name' => $ob['personal'], 'address' => $ob['inner']));
378: $ret .= Horde::link($curr_link, sprintf(_("Add %s to my Address Book"), $ob['inner'])) .
379: '<span class="iconImg addrbookaddImg"></span></a>';
380: }
381: }
382:
383: $addr_array[] = $ret;
384: }
385: }
386:
387: if (IMP::getViewMode() == 'mimp') {
388: return implode(', ', $addr_array);
389: }
390:
391: 392:
393: if (empty($addr_array)) {
394: $ret = _("Undisclosed Recipients");
395: } else {
396:
397: $addr_count = count($addr_array);
398: $ret = '<span class="nowrap">' . implode(',</span> <span class="nowrap">', $addr_array) . '</span>';
399: if ($link && $addr_count > 15) {
400: $ret = '<span>' .
401: '<span onclick="[ this, this.next(), this.next(1) ].invoke(\'toggle\')" class="widget largeaddrlist">' . sprintf(_("[Show Addresses - %d recipients]"), $addr_count) . '</span>' .
402: '<span onclick="[ this, this.previous(), this.next() ].invoke(\'toggle\')" class="widget largeaddrlist" style="display:none">' . _("[Hide Addresses]") . '</span>' .
403: '<span style="display:none">' .
404: $ret . '</span></span>';
405: }
406: }
407:
408: return $ret;
409: }
410:
411: 412: 413: 414: 415: 416: 417:
418: public function getDisplaySubject($subject)
419: {
420: return $GLOBALS['injector']->getInstance('Horde_Core_Factory_TextFilter')->filter(preg_replace("/\b\s+\b/", ' ', IMP::filterText($subject)), 'text2html', array(
421: 'parselevel' => Horde_Text_Filter_Text2html::MICRO
422: ));
423: }
424:
425: 426: 427: 428: 429:
430: public function moveAfterAction()
431: {
432: return (!IMP::$mailbox->hideDeletedMsgs() &&
433: !$GLOBALS['prefs']->getValue('use_trash'));
434: }
435:
436: }
437: