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