added delete button for emails

This commit is contained in:
Christian Haschek 2021-11-10 23:50:42 +01:00
parent a34d40bb9f
commit cf86029533
3 changed files with 50 additions and 7 deletions

View file

@ -21,6 +21,20 @@ if(!empty($email)){
switch($action)
{
case 'del':
$id = intval($_REQUEST['mid']);
if(!is_dir($dir))
$o = array('status'=>'err','reason'=>'No emails received on this address');
else if(!is_numeric($id) || !emailIDExists($email,$id))
$o = array('status'=>'err','reason'=>'Invalid Email ID');
else
{
if(unlink($dir.DS.$id.'.json'))
$o = array('status'=>'ok');
else
$o = array('status'=>'err','reason'=>'Could not delete email');
}
break;
case 'getdoms':
$settings = loadSettings();
if($settings['DOMAINS'])

View file

@ -5,7 +5,3 @@ body {
padding: 3rem 1.5rem;
text-align: center;
}
.anemail{
cursor: pointer;
}

View file

@ -37,10 +37,13 @@ function renderEmail(email,id,data)
btns+='<a class="btn btn-primary" target="_blank" href="api.php?a=attachment&email='+email+'&id='+id+'&filename='+filename+'" role="button">'+filename+'</a>'
}
$("#main").html('<h2 class="text-center">'+email+'</h2>\
<button onClick="loadAccount(\''+activeemail+'\')" class="btn btn-primary my-2 my-sm-0"><i class="fas fa-backward"></i> Back</button>\
<button onClick="loadAccount(\''+activeemail+'\')" class="btn btn-primary my-2 my-sm-0"><i class="fas fa-backward"></i> Back</button><br/>\
'+(data.parsed.body?'<pre>'+data.parsed.body+'</pre>':'')+' \
'+(data.parsed.htmlbody?'<div class="card card-body bg-light">'+data.parsed.htmlbody+'</pre>':'')+' \
'+(btns!==''?'<h4>Attachments</h4>'+btns:'')+'\
<div class="card card-body bg-light">\
<h4>Raw Email</h4><pre><code>'+data.raw+'</code></pre>\
</div>\
')
}
@ -63,6 +66,7 @@ function loadAccount(email)
<th scope="col">Date</th>\
<th scope="col">From</th>\
<th scope="col">Subject</th>\
<th scope="col">Action</th>\
</tr>\
</thead>\
<tbody id="emailtable">\
@ -119,18 +123,19 @@ function updateEmailTable()
var datestring = moment.unix(parseInt(dateofemail/1000)).format(data.dateformat); // Use moment.js formatting
var ed = data.emails[em]
$("#emailtable").append('\
<tr class="anemail" onClick="loadMail(\''+email+'\','+dateofemail+');">\
<tr class="anemail" email="'+email+'" messageid="'+dateofemail+'">\
<th scope="row">'+(index++)+'</th>\
<td >'+datestring+'</td>\
'+(admin===true?'<td>'+email+'</td>':'')+'\
<td>'+ed.from.toHtmlEntities()+'</td>\
<td>'+ed.subject.toHtmlEntities()+'</td>\
<td><button class="btn btn-success openmailbtn">Open Email</button> <button class="btn btn-danger deletemailbtn">Delete</button></td>\
</tr>');
}
else if(lastid==0 && $("#nomailyet").length == 0){
$("#emailtable").append('\
<tr id="nomailyet">\
<td colspan="4" class="text-center" ><h4>No emails received on this address (yet..)</h4></td>\
<td colspan="5" class="text-center" ><h4>No emails received on this address (yet..)</h4></td>\
</tr>');
}
}
@ -188,3 +193,31 @@ String.fromHtmlEntities = function(string) {
return String.fromCharCode(s.match(/\d+/gm)[0]);
})
};
$(document).on("click",".deletemailbtn",function(e) {
var btn = $(this);
var email = $(this).parent().parent().attr("email");
var messageid = $(this).parent().parent().attr("messageid");
if(confirm("Do you really want to delete this email?"))
{
$.get( "api.php?a=del&email="+email+"&mid="+messageid, function( data ) {
console.log(data);
if(data.status=="ok")
btn.parent().parent().fadeOut();
else alert("Error deleting email: "+data.reason)
},'json');
}
e.preventDefault();
});
$(document).on("click",".openmailbtn",function(e) {
var email = $(this).parent().parent().attr("email");
var messageid = $(this).parent().parent().attr("messageid");
loadMail(email,messageid);
e.preventDefault();
});