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 = [];
|
2022-02-09 18:05:20 +00:00
|
|
|
$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);
|
2022-02-09 19:04:49 +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'])
|
|
|
|
);
|
2022-02-09 18:05:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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']));
|
|
|
|
}
|
2019-08-15 19:43:55 +00:00
|
|
|
}
|
2022-02-09 18:05:20 +00:00
|
|
|
closedir($handle);
|
2019-08-15 19:43:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-02-08 23:38:45 +00:00
|
|
|
function deleteEmail($email,$id)
|
|
|
|
{
|
|
|
|
$dir = getDirForEmail($email);
|
|
|
|
$attachments = listAttachmentsOfMailID($email,$id);
|
|
|
|
foreach($attachments as $attachment)
|
|
|
|
unlink($dir.DS.'attachments'.DS.$attachment);
|
2022-05-15 16:54:43 +00:00
|
|
|
return unlink($dir.DS.$id.'.json');
|
2022-02-08 23:38:45 +00:00
|
|
|
}
|
|
|
|
|
2022-01-23 23:04:45 +00:00
|
|
|
|
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
|
|
|
}
|