From 742c251fd60323de0562b2b359fe0181b49cae61 Mon Sep 17 00:00:00 2001 From: Christian Haschek Date: Wed, 9 Feb 2022 19:05:20 +0100 Subject: [PATCH] integrating admin email into "getEmailsOfEmail" --- web/api.php | 3 ++- web/inc/core.php | 39 ++++++++++++++++++++++++++++++++------- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/web/api.php b/web/api.php index 0de20b0..4c4f7c2 100644 --- a/web/api.php +++ b/web/api.php @@ -93,6 +93,7 @@ switch($action) break; case 'list': + /* $settings = loadSettings(); if($settings['ADMIN'] && $settings['ADMIN']==$admincheck) { @@ -117,7 +118,7 @@ switch($action) $o['emails']=$data; } - else if(!is_dir($dir)) + else */if(!is_dir($dir)) $o = array('status'=>'ok','emails'=>[]); else { diff --git a/web/inc/core.php b/web/inc/core.php index 814f4d4..6a82d89 100644 --- a/web/inc/core.php +++ b/web/inc/core.php @@ -41,15 +41,40 @@ function emailIDExists($email,$id) function getEmailsOfEmail($email) { $o = []; - if ($handle = opendir(getDirForEmail($email))) { - while (false !== ($entry = readdir($handle))) { - if (endsWith($entry,'.json')) { - $time = substr($entry,0,-5); - $json = json_decode(file_get_contents(getDirForEmail($email).DS.$entry),true); - $o[$time] = array('email'=>$email,'id'=>$time,'from'=>$json['parsed']['from'],'subject'=>$json['parsed']['subject'],'md5'=>md5($time.$json['raw']),'maillen'=>strlen($json['raw'])); + $settings = loadSettings(); + + if($settings['ADMIN'] && $settings['ADMIN']==$email) + { + $emails = listEmailAdresses(); + if(count($emails)>0) + { + foreach($emails as $email) + { + if ($handle = opendir(getDirForEmail($email))) { + while (false !== ($entry = readdir($handle))) { + if (endsWith($entry,'.json')) { + $time = substr($entry,0,-5); + $json = json_decode(file_get_contents(getDirForEmail($email).DS.$entry),true); + $o[$time] = array('email'=>$email,'id'=>$time,'from'=>$json['parsed']['from'],'subject'=>$json['parsed']['subject'],'md5'=>md5($time.$json['raw']),'maillen'=>strlen($json['raw'])); + } + } + closedir($handle); + } } } - closedir($handle); + } + else + { + if ($handle = opendir(getDirForEmail($email))) { + while (false !== ($entry = readdir($handle))) { + if (endsWith($entry,'.json')) { + $time = substr($entry,0,-5); + $json = json_decode(file_get_contents(getDirForEmail($email).DS.$entry),true); + $o[$time] = array('email'=>$email,'id'=>$time,'from'=>$json['parsed']['from'],'subject'=>$json['parsed']['subject'],'md5'=>md5($time.$json['raw']),'maillen'=>strlen($json['raw'])); + } + } + closedir($handle); + } } if(is_array($o))