deletion of email now also deletes attachments of that email

This commit is contained in:
Christian Haschek 2022-01-24 00:04:45 +01:00
parent 6c28e6626b
commit 61a55423d2
2 changed files with 22 additions and 1 deletions

View file

@ -42,9 +42,14 @@ switch($action)
else else
{ {
if(unlink($dir.DS.$id.'.json')) if(unlink($dir.DS.$id.'.json'))
{
$attachments = listAttachmentsOfMailID($email,$id);
foreach($attachments as $attachment)
unlink($dir.DS.'attachments'.DS.$attachment);
$o = array('status'=>'ok'); $o = array('status'=>'ok');
}
else else
$o = array('status'=>'err','reason'=>'Could not delete email'); $o = array('status'=>'err','reason'=>'Could not delete email. Permission problem?');
} }
break; break;
case 'getdoms': case 'getdoms':

View file

@ -65,6 +65,22 @@ function listEmailAdresses()
return $o; 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;
}
function loadSettings() function loadSettings()
{ {
if(file_exists(ROOT.DS.'..'.DS.'config.ini')) if(file_exists(ROOT.DS.'..'.DS.'config.ini'))