2019-08-15 19:43:55 +00:00
|
|
|
<?php
|
|
|
|
|
2021-08-12 08:04:14 +00:00
|
|
|
function getDirForEmail($email)
|
|
|
|
{
|
|
|
|
return realpath(ROOT.DS.'..'.DS.'data'.DS.$email);
|
|
|
|
}
|
|
|
|
|
2019-08-15 19:43:55 +00:00
|
|
|
function startsWith($haystack, $needle)
|
|
|
|
{
|
|
|
|
$length = strlen($needle);
|
|
|
|
return (substr($haystack, 0, $length) === $needle);
|
|
|
|
}
|
|
|
|
|
|
|
|
function endsWith($haystack, $needle)
|
|
|
|
{
|
|
|
|
$length = strlen($needle);
|
|
|
|
if ($length == 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (substr($haystack, -$length) === $needle);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getEmail($email,$id)
|
|
|
|
{
|
2021-08-12 08:04:14 +00:00
|
|
|
return json_decode(file_get_contents(getDirForEmail($email).DS.$id.'.json'),true);
|
2019-08-15 19:43:55 +00:00
|
|
|
}
|
|
|
|
|
2022-02-08 23:17:55 +00:00
|
|
|
function getRawEmail($email,$id)
|
|
|
|
{
|
|
|
|
$data = json_decode(file_get_contents(getDirForEmail($email).DS.$id.'.json'),true);
|
|
|
|
|
|
|
|
return $data['raw'];
|
|
|
|
}
|
|
|
|
|
2019-08-15 19:43:55 +00:00
|
|
|
function emailIDExists($email,$id)
|
|
|
|
{
|
2021-08-12 08:04:14 +00:00
|
|
|
return file_exists(getDirForEmail($email).DS.$id.'.json');
|
2019-08-15 19:43:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getEmailsOfEmail($email)
|
|
|
|
{
|
2021-11-27 17:09:05 +00:00
|
|
|
$o = [];
|
2021-08-12 08:04:14 +00:00
|
|
|
if ($handle = opendir(getDirForEmail($email))) {
|
2019-08-15 19:43:55 +00:00
|
|
|
while (false !== ($entry = readdir($handle))) {
|
|
|
|
if (endsWith($entry,'.json')) {
|
|
|
|
$time = substr($entry,0,-5);
|
2021-08-12 08:04:14 +00:00
|
|
|
$json = json_decode(file_get_contents(getDirForEmail($email).DS.$entry),true);
|
2022-02-08 23:17:55 +00:00
|
|
|
$o[$time] = array('email'=>$email,'id'=>$time,'from'=>$json['parsed']['from'],'subject'=>$json['parsed']['subject'],'md5'=>md5($time.$json['raw']),'maillen'=>strlen($json['raw']));
|
2019-08-15 19:43:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir($handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(is_array($o))
|
|
|
|
ksort($o);
|
|
|
|
|
|
|
|
return $o;
|
|
|
|
}
|
|
|
|
|
2019-08-18 19:02:04 +00:00
|
|
|
function listEmailAdresses()
|
|
|
|
{
|
|
|
|
$o = array();
|
|
|
|
if ($handle = opendir(ROOT.DS.'..'.DS.'data'.DS)) {
|
|
|
|
while (false !== ($entry = readdir($handle))) {
|
|
|
|
if(filter_var($entry, FILTER_VALIDATE_EMAIL))
|
|
|
|
$o[] = $entry;
|
|
|
|
}
|
|
|
|
closedir($handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $o;
|
|
|
|
}
|
|
|
|
|
2022-01-23 23:04:45 +00:00
|
|
|
function listAttachmentsOfMailID($email,$id)
|
|
|
|
{
|
|
|
|
$o = array();
|
|
|
|
if ($handle = opendir(getDirForEmail($email).DS.'attachments')) {
|
|
|
|
while (false !== ($entry = readdir($handle))) {
|
|
|
|
if (startsWith($entry,$id.'-')) {
|
|
|
|
$o[] = $entry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir($handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $o;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-15 19:43:55 +00:00
|
|
|
function loadSettings()
|
|
|
|
{
|
|
|
|
if(file_exists(ROOT.DS.'..'.DS.'config.ini'))
|
|
|
|
return parse_ini_file(ROOT.DS.'..'.DS.'config.ini');
|
|
|
|
return false;
|
2021-08-12 08:04:14 +00:00
|
|
|
}
|