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