diff --git a/web/api.php b/web/api.php index 0ca9c69..34b0085 100644 --- a/web/api.php +++ b/web/api.php @@ -42,9 +42,14 @@ switch($action) else { if(unlink($dir.DS.$id.'.json')) + { + $attachments = listAttachmentsOfMailID($email,$id); + foreach($attachments as $attachment) + unlink($dir.DS.'attachments'.DS.$attachment); $o = array('status'=>'ok'); + } else - $o = array('status'=>'err','reason'=>'Could not delete email'); + $o = array('status'=>'err','reason'=>'Could not delete email. Permission problem?'); } break; case 'getdoms': diff --git a/web/inc/core.php b/web/inc/core.php index befd8b8..4689644 100644 --- a/web/inc/core.php +++ b/web/inc/core.php @@ -65,6 +65,22 @@ function listEmailAdresses() 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() { if(file_exists(ROOT.DS.'..'.DS.'config.ini'))