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

@ -27,4 +27,4 @@ VOLUME /var/www/opentrashmail/data
EXPOSE 80 25
#CMD ["/bin/ash"]
ENTRYPOINT ["/etc/start.sh"]
ENTRYPOINT ["/etc/start.sh"]

View file

@ -1,102 +1,101 @@
<?php
<?php
define('DS', DIRECTORY_SEPARATOR);
define('ROOT', dirname(__FILE__));
define('DOMAIN',$_SERVER['HTTP_HOST']);
define('DOMAIN', $_SERVER['HTTP_HOST']);
error_reporting(E_ALL || ~E_NOTICE);
ini_set('display_errors', 1);
include_once(ROOT.DS.'inc'.DS.'core.php');
include_once(ROOT . DS . 'inc' . DS . 'core.php');
header("Content-Type: application/rss+xml; charset=UTF8");
if (PHP_SAPI === 'cli-server')
$_SERVER['SCRIPT_NAME'] = pathinfo(__FILE__, PATHINFO_BASENAME);
if($_GET['url'])
$url = explode('/',ltrim(parse_url($_GET['url'], PHP_URL_PATH),'/'));
else $url = array_filter(explode('/',ltrim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH),'/')));
if ($_GET['url'])
$url = explode('/', ltrim(parse_url($_GET['url'], PHP_URL_PATH), '/'));
else $url = array_filter(explode('/', ltrim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/')));
array_shift($url);
$email = $url[0];
if(!$email)
{
if (!$email) {
http_response_code(404);
exit('Error: Email not found');
}
if(!filter_var($email, FILTER_VALIDATE_EMAIL)) exit();
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) exit();
$rss = '<?xml version="1.0" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<atom:link href="https://'.DOMAIN.'/rss.php" rel="self" type="application/rss+xml" />
<title>RSS for '.$email.'</title>
<link>https://'.DOMAIN.'/#'.$email.'</link>
<description>RSS Feed for email address '.$email.'</description>
<lastBuildDate>'.date(DATE_RFC822,time()).'</lastBuildDate>
<atom:link href="https://' . DOMAIN . '/rss.php" rel="self" type="application/rss+xml" />
<title>RSS for ' . $email . '</title>
<link>https://' . DOMAIN . '/#' . $email . '</link>
<description>RSS Feed for email address ' . $email . '</description>
<lastBuildDate>' . date(DateTime::RFC2822, time()) . '</lastBuildDate>
<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>
<link>https://github.com/HaschekSolutions/opentrashmail</link>
</image>';
$emaildata = getEmailsOfEmail($email);
foreach($emaildata as $id=>$d)
{
$data = getEmail($email,$id);
foreach ($emaildata as $id => $d) {
$data = getEmail($email, $id);
//var_dump($data);
$time = substr($id,0,-3);
$date = date("Y-m-d H:i",$time);
$time = substr($id, 0, -3);
$date = date("Y-m-d H:i", $time);
$att_text = array();
$encl = array();
if(is_array($data['parsed']['attachments']))
foreach($data['parsed']['attachments'] as $filename)
{
$filepath = ROOT.DS.'..'.DS.'data'.DS.$email.DS.'attachments'.DS.$filename;
$parts = explode('-',$filename);
if (is_array($data['parsed']['attachments']))
foreach ($data['parsed']['attachments'] as $filename) {
$filepath = ROOT . DS . '..' . DS . 'data' . DS . $email . DS . 'attachments' . DS . $filename;
$parts = explode('-', $filename);
$fid = $parts[0];
$fn = $parts[1];
$url = 'https://'.DOMAIN.'/api.php?a=attachment&email='.$email.'&id='.$fid.'&filename='.$fn;
$url = 'https://' . DOMAIN . '/api.php?a=attachment&email=' . $email . '&id=' . $fid . '&filename=' . $fn;
//$encl[] = '<enclosure url="'.rawurlencode($url).'" length="'.filesize($filepath).'" type="'.mime_content_type($filepath).'" />';
$att_text[] = "<a href='$url' target='_blank'>$fn</a>";
}
$rss.='
$rss .= '
<item>
<title><![CDATA['.$data['parsed']['subject'].']]></title>
<pubDate>'.date(DATE_RFC822,$time).'</pubDate>
<link>https://'.DOMAIN.'/#'.$email.'</link>
<title><![CDATA[' . $data['parsed']['subject'] . ']]></title>
<pubDate>' . date(DateTime::RFC2822, $time) . '</pubDate>
<link>https://' . DOMAIN . '/#' . $email . '</link>
<guid>https://' . DOMAIN . '/api.php?a=load&email=' . $email . '&id=' . $id . '&raw=true</guid>
<description>
<![CDATA[
Email from: '.htmlentities($data['from']).'<br/>
Email to: '.(is_array($data['rcpts'])?htmlentities(implode(',',$data['rcpts'])):htmlentities($email)).'<br/>
'.((count($att_text)>0)?'Attachments:<br/>'.array2ul($att_text).'<br/>':'').'
<a href="https://'.DOMAIN.'/api.php?a=load&email='.$email.'&id='.$id.'&raw=true">View raw email</a> <br/>
Email from: ' . htmlentities($data['from']) . '<br/>
Email to: ' . (is_array($data['rcpts']) ? htmlentities(implode(',', $data['rcpts'])) : htmlentities($email)) . '<br/>
' . ((count($att_text) > 0) ? 'Attachments:<br/>' . array2ul($att_text) . '<br/>' : '') . '
<a href="https://' . DOMAIN . '/api.php?a=load&email=' . $email . '&id=' . $id . '&raw=true">View raw email</a> <br/>
<br/>---------<br/><br/>
'.($data['parsed']['htmlbody']?$data['parsed']['htmlbody']:nl2br(htmlentities($data['parsed']['body']))).'
' . ($data['parsed']['htmlbody'] ? $data['parsed']['htmlbody'] : nl2br(htmlentities($data['parsed']['body']))) . '
]]>
</description>
'./*((count($encl)>0)?implode('<br/>',$encl):'').*/'
' ./*((count($encl)>0)?implode('<br/>',$encl):'').*/ '
</item>';
if(++$i>5) break;
//if (++$i > 5) break;
}
$rss.='</channel>
$rss .= '</channel>
</rss> ';
echo $rss;
function array2ul($array) {
function array2ul($array)
{
$out = "<ul>";
foreach($array as $key => $elem){
foreach ($array as $key => $elem) {
$out .= "<li>$elem</li>";
}
$out .= "</ul>";
return $out;
}
return $out;
}