1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15: class IMP_Block_Newmail extends Horde_Core_Block
16: {
17: 18:
19: public $updateable = true;
20:
21: 22:
23: public function __construct($app, $params = array())
24: {
25: parent::__construct($app, $params);
26:
27: $this->_name = _("Newest Unseen Messages");
28: }
29:
30: 31:
32: protected function _params()
33: {
34: return array(
35: 'msgs_shown' => array(
36: 'type' => 'int',
37: 'name' => _("The number of unseen messages to show"),
38: 'default' => 3
39: )
40: );
41: }
42:
43: 44:
45: protected function _content()
46: {
47: $inbox = IMP_Mailbox::get('INBOX');
48:
49:
50: $inbox->filterOnDisplay();
51:
52: $query = new Horde_Imap_Client_Search_Query();
53: $query->flag(Horde_Imap_Client::FLAG_SEEN, false);
54: $ids = $inbox->runSearchQuery($query, Horde_Imap_Client::SORT_SEQUENCE, 1);
55: $indices = $ids['INBOX'];
56:
57: $html = '<table cellspacing="0" width="100%">';
58: $text = _("Go to your Inbox...");
59: if (empty($indices)) {
60: $html .= '<tr><td><em>' . _("No unread messages") . '</em></td></tr>';
61: } else {
62: $charset = 'UTF-8';
63: $imp_ui = new IMP_Ui_Mailbox($inbox);
64: $shown = empty($this->_params['msgs_shown'])
65: ? 3
66: : $this->_params['msgs_shown'];
67:
68: $query = new Horde_Imap_Client_Fetch_Query();
69: $query->envelope();
70:
71: try {
72: $imp_imap = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create();
73: $fetch_ret = $imp_imap->fetch($inbox, $query, array(
74: 'ids' => $imp_imap->getIdsOb(array_slice($indices, 0, $shown))
75: ));
76: } catch (IMP_Imap_Exception $e) {
77: $fetch_ret = array();
78: }
79:
80: reset($fetch_ret);
81: while (list($uid, $ob) = each($fetch_ret)) {
82: $envelope = $ob->getEnvelope();
83:
84: $date = $imp_ui->getDate($envelope->date);
85: $from = $imp_ui->getFrom($envelope, array('specialchars' => $charset));
86: $subject = $imp_ui->getSubject($envelope->subject, true);
87:
88: $html .= '<tr style="cursor:pointer" class="text"><td>' .
89: $inbox->url('message.php', $uid)->link() .
90: '<strong>' . $from['from'] . '</strong><br />' .
91: $subject . '</a></td>' .
92: '<td>' . htmlspecialchars($date, ENT_QUOTES, $charset) . '</td></tr>';
93: }
94:
95: $more_msgs = count($indices) - $shown;
96: if ($more_msgs > 0) {
97: $text = sprintf(ngettext("%d more unseen message...", "%d more unseen messages...", $more_msgs), $more_msgs);
98: }
99: }
100:
101: return $html .
102: '<tr><td colspan="2" style="cursor:pointer" align="right">' . $inbox->url('mailbox.php')->link() . $text . '</a></td></tr>' .
103: '</table>';
104: }
105:
106: }
107: