Merge pull request #51 from adamklaff/feedreader

Improved RSS Reader Support
This commit is contained in:
Christian Haschek 2023-08-22 08:20:45 +02:00 committed by GitHub
commit 2cc5156742
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 43 deletions

View file

@ -20,8 +20,7 @@ else $url = array_filter(explode('/',ltrim(parse_url($_SERVER['REQUEST_URI'], PH
array_shift($url); array_shift($url);
$email = $url[0]; $email = $url[0];
if(!$email) if (!$email) {
{
http_response_code(404); http_response_code(404);
exit('Error: Email not found'); exit('Error: Email not found');
} }
@ -35,7 +34,7 @@ $rss = '<?xml version="1.0" ?>
<title>RSS for ' . $email . '</title> <title>RSS for ' . $email . '</title>
<link>https://' . DOMAIN . '/#' . $email . '</link> <link>https://' . DOMAIN . '/#' . $email . '</link>
<description>RSS Feed for email address ' . $email . '</description> <description>RSS Feed for email address ' . $email . '</description>
<lastBuildDate>'.date(DATE_RFC822,time()).'</lastBuildDate> <lastBuildDate>' . date(DateTime::RFC2822, time()) . '</lastBuildDate>
<image> <image>
<title>RSS for ' . $email . '</title> <title>RSS for ' . $email . '</title>
<url>https://raw.githubusercontent.com/HaschekSolutions/opentrashmail/master/web/imgs/logo_300.png</url> <url>https://raw.githubusercontent.com/HaschekSolutions/opentrashmail/master/web/imgs/logo_300.png</url>
@ -43,8 +42,7 @@ $rss = '<?xml version="1.0" ?>
</image>'; </image>';
$emaildata = getEmailsOfEmail($email); $emaildata = getEmailsOfEmail($email);
foreach($emaildata as $id=>$d) foreach ($emaildata as $id => $d) {
{
$data = getEmail($email, $id); $data = getEmail($email, $id);
//var_dump($data); //var_dump($data);
$time = substr($id, 0, -3); $time = substr($id, 0, -3);
@ -52,8 +50,7 @@ foreach($emaildata as $id=>$d)
$att_text = array(); $att_text = array();
$encl = array(); $encl = array();
if (is_array($data['parsed']['attachments'])) if (is_array($data['parsed']['attachments']))
foreach($data['parsed']['attachments'] as $filename) foreach ($data['parsed']['attachments'] as $filename) {
{
$filepath = ROOT . DS . '..' . DS . 'data' . DS . $email . DS . 'attachments' . DS . $filename; $filepath = ROOT . DS . '..' . DS . 'data' . DS . $email . DS . 'attachments' . DS . $filename;
$parts = explode('-', $filename); $parts = explode('-', $filename);
$fid = $parts[0]; $fid = $parts[0];
@ -65,8 +62,9 @@ foreach($emaildata as $id=>$d)
$rss .= ' $rss .= '
<item> <item>
<title><![CDATA[' . $data['parsed']['subject'] . ']]></title> <title><![CDATA[' . $data['parsed']['subject'] . ']]></title>
<pubDate>'.date(DATE_RFC822,$time).'</pubDate> <pubDate>' . date(DateTime::RFC2822, $time) . '</pubDate>
<link>https://' . DOMAIN . '/#' . $email . '</link> <link>https://' . DOMAIN . '/#' . $email . '</link>
<guid>https://' . DOMAIN . '/api.php?a=load&email=' . $email . '&id=' . $id . '&raw=true</guid>
<description> <description>
<![CDATA[ <![CDATA[
Email from: ' . htmlentities($data['from']) . '<br/> Email from: ' . htmlentities($data['from']) . '<br/>
@ -80,7 +78,7 @@ foreach($emaildata as $id=>$d)
' ./*((count($encl)>0)?implode('<br/>',$encl):'').*/ ' ' ./*((count($encl)>0)?implode('<br/>',$encl):'').*/ '
</item>'; </item>';
if(++$i>5) break; //if (++$i > 5) break;
} }
@ -92,7 +90,8 @@ $rss.='</channel>
echo $rss; echo $rss;
function array2ul($array) { function array2ul($array)
{
$out = "<ul>"; $out = "<ul>";
foreach ($array as $key => $elem) { foreach ($array as $key => $elem) {
$out .= "<li>$elem</li>"; $out .= "<li>$elem</li>";