1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15: class IMP_Notification_Handler_Decorator_NewmailNotify
16: extends Horde_Core_Notification_Handler_Decorator_Base
17: {
18: 19:
20: protected $_app = 'imp';
21:
22: 23: 24: 25: 26: 27: 28:
29: public function notify(Horde_Notification_Handler $handler,
30: Horde_Notification_Listener $listener)
31: {
32: global $injector, $prefs, $session;
33:
34: $imp_imap = $injector->getInstance('IMP_Factory_Imap')->create();
35:
36: if (!$prefs->getValue('newmail_notify') ||
37: !($listener instanceof Horde_Notification_Listener_Status) ||
38: !$imp_imap->imap ||
39: !$imp_imap->ob) {
40: return;
41: }
42:
43: $ns = $imp_imap->getNamespace();
44: $recent = array();
45:
46: foreach ($imp_imap->statusMultiple($injector->getInstance('IMP_Imap_Tree')->getPollList(), Horde_Imap_Client::STATUS_RECENT, array('sort' => true, 'sort_delimiter' => $ns['delimiter'])) as $key => $val) {
47: if (!empty($val['recent'])) {
48: 49:
50: $imp_imap->openMailbox($key, Horde_Imap_Client::OPEN_READWRITE);
51:
52: $recent[IMP_Mailbox::get($key)->display] = $val['recent'];
53: }
54: }
55:
56:
57: if (empty($recent) ||
58: !$session->get('imp', 'newmail_init')) {
59: $session->set('imp', 'newmail_init', true);
60: return;
61: }
62:
63: $recent_sum = array_sum($recent);
64: reset($recent);
65:
66: switch (count($recent)) {
67: case 1:
68: $mbox_list = key($recent);
69: break;
70:
71: case 2:
72: $mbox_list = implode(_(" and "), array_keys($recent));
73: break;
74:
75: default:
76: $akeys = array_keys($recent);
77: $mbox_list = $akeys[0] . ', ' . $akeys[1] . ', ' . _("and") . ' ' . $akeys[2];
78: if ($addl_mbox = count($recent) - 3) {
79: $mbox_list .= ' (' . sprintf(ngettext("and %d more mailbox", "and %d more mailboxes", $addl_mbox), $addl_mbox) . ')';
80: }
81: break;
82: }
83:
84: $handler->push(sprintf(ngettext("You have %d new mail message in %s.", "You have %d new mail messages in %s.", $recent_sum), $recent_sum, $mbox_list), 'horde.message');
85:
86: if ($audio = $prefs->getValue('newmail_audio')) {
87: $handler->attach('audio');
88: $handler->push(Horde_Themes::sound($audio), 'audio');
89: }
90: }
91:
92: }
93: