| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | /* |
|---|
| 4 | +-----------------------------------------------------------------------+ |
|---|
| 5 | | program/steps/mail/rss.inc | |
|---|
| 6 | | | |
|---|
| 7 | | This file is part of the RoundCube Webmail client | |
|---|
| 8 | | Copyright (C) 2005-2007, RoundCube Dev. - Switzerland | |
|---|
| 9 | | Licensed under the GNU GPL | |
|---|
| 10 | | | |
|---|
| 11 | | PURPOSE: | |
|---|
| 12 | | Send mailboxcontents as RSS feed | |
|---|
| 13 | | | |
|---|
| 14 | +-----------------------------------------------------------------------+ |
|---|
| 15 | | Author: Sjon Hortensius <sjon@hortensius.net> | |
|---|
| 16 | +-----------------------------------------------------------------------+ |
|---|
| 17 | |
|---|
| 18 | $Id$ |
|---|
| 19 | |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | require_once('Mail/mimeDecode.php'); |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | function rss_encode($string){ |
|---|
| 26 | $string = rep_specialchars_output($string, 'xml'); |
|---|
| 27 | return $string; |
|---|
| 28 | } |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | $REMOTE_REQUEST = TRUE; |
|---|
| 33 | $OUTPUT_TYPE = 'rss'; |
|---|
| 34 | |
|---|
| 35 | $webmail_url = 'http'; |
|---|
| 36 | if (strstr('HTTPS', $_SERVER['SERVER_PROTOCOL'] )!== FALSE) |
|---|
| 37 | $webmail_url .= 's'; |
|---|
| 38 | $webmail_url .= '://'.$_SERVER['SERVER_NAME']; |
|---|
| 39 | if ($_SERVER['SERVER_PORT'] != '80') |
|---|
| 40 | $webmail_url .= ':'.$_SERVER['SERVER_PORT']; |
|---|
| 41 | $webmail_url .= '/'; |
|---|
| 42 | if (dirname($_SERVER['SCRIPT_NAME']) != '/') |
|---|
| 43 | $webmail_url .= dirname($_SERVER['SCRIPT_NAME']).'/'; |
|---|
| 44 | |
|---|
| 45 | $webmail_url .= '?_task=mail'; |
|---|
| 46 | |
|---|
| 47 | $messagecount_unread = $IMAP->messagecount('INBOX', 'UNSEEN', TRUE); |
|---|
| 48 | $messagecount = $IMAP->messagecount(); |
|---|
| 49 | |
|---|
| 50 | $sort_col = 'date'; |
|---|
| 51 | $sort_order = 'DESC'; |
|---|
| 52 | |
|---|
| 53 | // Send global XML output |
|---|
| 54 | header('Content-type: text/xml'); |
|---|
| 55 | echo '<?xml version="1.0" encoding="UTF-8"?> |
|---|
| 56 | <rss version="2.0" |
|---|
| 57 | xmlns:dc="http://purl.org/dc/elements/1.1/" |
|---|
| 58 | xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" |
|---|
| 59 | xmlns:admin="http://webns.net/mvcb/" |
|---|
| 60 | xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" |
|---|
| 61 | xmlns:content="http://purl.org/rss/1.0/modules/content/">'; |
|---|
| 62 | |
|---|
| 63 | // Send channel-specific output |
|---|
| 64 | echo ' |
|---|
| 65 | <channel> |
|---|
| 66 | <pubDate>'.date('r').'</pubDate> |
|---|
| 67 | <lastBuildDate>'.date('r').'</lastBuildDate> |
|---|
| 68 | <ttl>5</ttl> |
|---|
| 69 | <docs>http://blogs.law.harvard.edu/tech/rss</docs> |
|---|
| 70 | <description>INBOX contains '.$messagecount.' messages, of which '.$messagecount_unread.' unread</description> |
|---|
| 71 | <link>'.rss_encode($webmail_url, 'xml') .'</link> |
|---|
| 72 | <title>webmail for '.rss_encode($_SESSION['username'].' @ '.$_SESSION['imap_host']).'</title> |
|---|
| 73 | <generator>'.rss_encode($CONFIG['useragent'], 'xml').' (RSS extension by Sjon Hortensius)</generator> |
|---|
| 74 | <image> |
|---|
| 75 | <link>http://www.roundcube.net/</link> |
|---|
| 76 | <title>'.rss_encode($CONFIG['product_name']).' logo</title> |
|---|
| 77 | <url>'.rss_encode($webmail_url.'skins/default/images/roundcube_logo.png').'</url> |
|---|
| 78 | </image>'; |
|---|
| 79 | |
|---|
| 80 | // Check if the user wants to override the default sortingmethode |
|---|
| 81 | if (isset($_GET['_sort'])) |
|---|
| 82 | list($sort_col, $sort_order) = explode('_', $_GET['_sort']); |
|---|
| 83 | |
|---|
| 84 | // Add message to output |
|---|
| 85 | if ($messagecount > 0) |
|---|
| 86 | { |
|---|
| 87 | $items = $IMAP->list_headers('INBOX', null, $sort_col, $sort_order); |
|---|
| 88 | foreach ($items as $item) |
|---|
| 89 | { |
|---|
| 90 | |
|---|
| 91 | // Convert '"name" <email>' to 'email (name)' |
|---|
| 92 | if (strstr($item->from, '<')) |
|---|
| 93 | $item->from = preg_replace('~"?([^"]*)"? <([^>]*)>~', '\2 (\1)', $item->from); |
|---|
| 94 | |
|---|
| 95 | $item->link = $webmail_url.'&_task=mail&_action=show&_uid='.$item->uid.'&_mbox=INBOX'; |
|---|
| 96 | |
|---|
| 97 | $item->body = $IMAP->get_body($item->uid); |
|---|
| 98 | |
|---|
| 99 | // Print the actual messages |
|---|
| 100 | echo ' |
|---|
| 101 | <item> |
|---|
| 102 | <title>'.rss_encode($item->subject).'</title> |
|---|
| 103 | <link>'.rss_encode($item->link).'</link> |
|---|
| 104 | <description><![CDATA['."\n".nl2br(rss_encode($item->body))."\n".']]></description> |
|---|
| 105 | <author>'.rss_encode($item->from).'</author> |
|---|
| 106 | <category></category> |
|---|
| 107 | <guid>'.rss_encode($item->link).'</guid> |
|---|
| 108 | <pubDate>'.date('r', $item->timestamp).'</pubDate> |
|---|
| 109 | </item>'; |
|---|
| 110 | } |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | echo '</channel> |
|---|
| 114 | </rss>'; |
|---|
| 115 | |
|---|
| 116 | exit; |
|---|
| 117 | ?> |
|---|