opentrashmail/web/inc/core.php

97 lines
2.2 KiB
PHP
Raw Normal View History

2019-08-15 19:43:55 +00:00
<?php
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)
{
return json_decode(file_get_contents(getDirForEmail($email).DS.$id.'.json'),true);
2019-08-15 19:43: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)
{
return file_exists(getDirForEmail($email).DS.$id.'.json');
2019-08-15 19:43:55 +00:00
}
function getEmailsOfEmail($email)
{
$o = [];
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);
$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
}
}
closedir($handle);
}
if(is_array($o))
ksort($o);
return $o;
}
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;
}
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;
}