Add getDirForEmail to perform realPath filtering in core

This commit is contained in:
Dan Q 2021-08-12 09:04:14 +01:00 committed by GitHub
parent cc7b18400a
commit 5f82811ab3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,5 +1,10 @@
<?php
function getDirForEmail($email)
{
return realpath(ROOT.DS.'..'.DS.'data'.DS.$email);
}
function startsWith($haystack, $needle)
{
$length = strlen($needle);
@ -18,22 +23,22 @@ function endsWith($haystack, $needle)
function getEmail($email,$id)
{
return json_decode(file_get_contents(ROOT.DS.'..'.DS.'data'.DS.$email.DS.$id.'.json'),true);
return json_decode(file_get_contents(getDirForEmail($email).DS.$id.'.json'),true);
}
function emailIDExists($email,$id)
{
return file_exists(ROOT.DS.'..'.DS.'data'.DS.$email.DS.$id.'.json');
return file_exists(getDirForEmail($email).DS.$id.'.json');
}
function getEmailsOfEmail($email)
{
$o = false;
if ($handle = opendir(ROOT.DS.'..'.DS.'data'.DS.$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(ROOT.DS.'..'.DS.'data'.DS.$email.DS.$entry),true);
$json = json_decode(file_get_contents(getDirForEmail($email).DS.$entry),true);
$o[$time] = array('from'=>$json['parsed']['from'],'subject'=>$json['parsed']['subject']);
}
}
@ -66,4 +71,4 @@ function loadSettings()
if(file_exists(ROOT.DS.'..'.DS.'config.ini'))
return parse_ini_file(ROOT.DS.'..'.DS.'config.ini');
return false;
}
}