From 57bc6a32ed2d68cfe4a6cd7c2790421df43e5089 Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 11 Mar 2020 02:25:11 +0100 Subject: [PATCH] added experimental support for rss --- docker/rootfs/nginx.conf | 7 +++ web/api.php | 5 +++ web/js/opentrashmail.js | 2 +- web/rss.php | 96 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 web/rss.php diff --git a/docker/rootfs/nginx.conf b/docker/rootfs/nginx.conf index e4a592d..825743e 100644 --- a/docker/rootfs/nginx.conf +++ b/docker/rootfs/nginx.conf @@ -12,6 +12,13 @@ server { try_files $uri $uri/ =404; } + location /rss { + index rss.php; + if (!-e $request_filename){ + rewrite ^(.*)$ /rss.php?url=$1 last; + } + } + # logging access_log /var/log/nginx/opentrashmail/web.access.log; error_log /var/log/nginx/opentrashmail/web.error.log warn; diff --git a/web/api.php b/web/api.php index aa9657c..9ce78bb 100644 --- a/web/api.php +++ b/web/api.php @@ -48,6 +48,11 @@ switch($action) else { $data = getEmail($email,$id); + if($_REQUEST['raw']=='true') + { + header('Content-Type: text/plain'); + exit($data['raw']); + } $o = array('status'=>'ok','data'=>$data); } break; diff --git a/web/js/opentrashmail.js b/web/js/opentrashmail.js index 0236c57..55c4e90 100644 --- a/web/js/opentrashmail.js +++ b/web/js/opentrashmail.js @@ -98,7 +98,7 @@ function updateEmailTable() } } - $("#emailtable tr").remove(); // Empty all from the table so we don't stack + //$("#emailtable tr").remove(); // Empty all from the table so we don't stack if(Object.keys(data.emails).length>0) for(em in data.emails) { diff --git a/web/rss.php b/web/rss.php new file mode 100644 index 0000000..22a9579 --- /dev/null +++ b/web/rss.php @@ -0,0 +1,96 @@ + + + + + RSS for '.$email.' + https://'.DOMAIN.'/#'.$email.' + RSS Feed for email address '.$email.' + '.date(DATE_RFC822,time()).' + + RSS for '.$email.' + https://raw.githubusercontent.com/HaschekSolutions/opentrashmail/master/web/imgs/logo_300.png + https://github.com/HaschekSolutions/opentrashmail + '; + +$emaildata = getEmailsOfEmail($email); +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); + $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); + $fid = $parts[0]; + $fn = $parts[1]; + $url = 'https://'.DOMAIN.'/api.php?a=attachment&email='.$email.'&id='.$fid.'&filename='.$fn; + //$encl[] = ''; + $att_text[] = "$fn"; + } + $rss.=' + + <![CDATA['.$data['parsed']['subject'].']]> + '.date(DATE_RFC822,$time).' + https://'.DOMAIN.'/#'.$email.' + + + Email to: '.(is_array($data['rcpts'])?htmlentities(implode(',',$data['rcpts'])):htmlentities($email)).'
+ '.((count($att_text)>0)?'Attachments:
'.array2ul($att_text).'
':'').' + View raw email
+
---------

+ '.($data['parsed']['htmlbody']?$data['parsed']['htmlbody']:nl2br(htmlentities($data['parsed']['body']))).' + ]]> +
+ './*((count($encl)>0)?implode('
',$encl):'').*/' +
'; + + if(++$i>5) break; +} + + + + +$rss.='
+
'; + +echo $rss; + + +function array2ul($array) { + $out = ""; + return $out; +} \ No newline at end of file