* * See the enclosed file COPYING for license information (GPL). If you * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. * * @author Eric Garrido */ @define('IMP_BASE', dirname(__FILE__)); require_once IMP_BASE . '/lib/base.php'; require_once IMP_BASE . '/lib/Mailbox.php'; require_once IMP_BASE . '/lib/Template.php'; $items = array(); $mailbox = 'INBOX'; $new_mail = $request = $searchid = false; $unseen_num = 0; /* Determine the mailbox that was requested and if only new mail should be * displayed. Default to new mail in INBOX. */ if (!empty($_SERVER['PATH_INFO'])) { $request = $_SERVER['PATH_INFO']; } elseif (!empty($_SERVER['REQUEST_URI'])) { $request = substr($_SERVER['REQUEST_URI'], strlen(Horde::applicationUrl('rss.php', false, -1))); } if (!empty($request)) { $request_parts = explode('/-/', $request); if (!empty($request_parts[0])) { $ns_info = IMP::getNamespace(); $mailbox = IMP::appendNamespace(preg_replace('/\//', $ns_info['delimiter'], trim($request_parts[0], '/'))); /* Make sure mailbox exists or else exit immediately. */ require_once IMP_BASE . '/lib/Folder.php'; $imp_folder = &IMP_Folder::singleton(); if (!$imp_folder->exists($mailbox)) { exit; } } $new_mail = (isset($request_parts[1]) && ($request_parts[1] === 'new')); } /* Obtain some information describing the mailbox state. */ $imp_mailbox = &IMP_Mailbox::singleton($mailbox); $total_num = $imp_mailbox->getMessageCount(); $unseen_num = ($imp_search->isVINBOXFolder($mailbox)) ? $imp_mailbox->getMessageCount() : $imp_mailbox->unseenMessages(true); /* Create a search to find unseen mail in the specified folder, if needed. */ if ($new_mail) { require_once IMP_BASE . '/lib/IMAP/Search.php'; $query = new IMP_IMAP_Search_Query(); $query->seen(false); $searchid = $imp_search->createSearchQuery($query, array($mailbox), null, ''); $imp_mailbox = &IMP_Mailbox::singleton($searchid); } /* Temporarily sort by date as this is the expected behavior for RSS. */ $oldsort = IMP::getSort(); IMP::setSort(SORTDATE, 1, $mailbox); $msgs = $imp_mailbox->buildMailboxArray(0, 20, 2); foreach ($msgs as $msg) { $items[] = array_map('htmlspecialchars', array( 'title' => isset($msg->subject) ? MIME::decode($msg->subject) : _("[No Subject]"), 'pubDate' => isset($msg->date) ? date('r', strtotime($msg->date)) : 0, 'description' => isset($msg->preview) ? $msg->preview : '', 'url' => Horde::applicationURL(IMP::generateIMPUrl('message.php', $mailbox, $msg->uid, $mailbox), true, -1) )); } $description = ($total_num == 0) ? _("No Messages") : sprintf(_("%u of %u messages in %s unread."), $unseen_num, $total_num, IMP::getLabel($mailbox)); /* Clean up state. */ IMP::setSort($oldsort['by'], $oldsort['dir'], $mailbox); if ($searchid) { $imp_search->deleteSearchQuery($searchid); } $t = new IMP_Template(); $t->set('charset', NLS::getCharset()); $t->set('xsl', $registry->get('themesuri') . '/feed-rss.xsl'); $t->set('pubDate', htmlspecialchars(date('r'))); $t->set('desc', htmlspecialchars($description)); $t->set('title', htmlspecialchars($registry->get('name') . ' - ' . IMP::getLabel($mailbox))); $t->set('items', $items, true); $t->set('url', htmlspecialchars(Horde::applicationURL(IMP::generateIMPUrl('message.php', $mailbox), true, -1))); $t->set('rss_url', htmlspecialchars(Horde::applicationUrl('rss.php', true, -1))); $browser->downloadHeaders('mailbox' . '.rss', 'text/xml', true); echo $t->fetch(IMP_TEMPLATES . '/rss/mailbox.rss');