diff --git a/web/api.php b/web/api.php index 4b1839f..0237ed7 100644 --- a/web/api.php +++ b/web/api.php @@ -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']) diff --git a/web/css/opentrashmail.css b/web/css/opentrashmail.css index 549b7b0..dc39033 100644 --- a/web/css/opentrashmail.css +++ b/web/css/opentrashmail.css @@ -5,7 +5,3 @@ body { padding: 3rem 1.5rem; text-align: center; } - -.anemail{ - cursor: pointer; -} \ No newline at end of file diff --git a/web/js/opentrashmail.js b/web/js/opentrashmail.js index fb2aa05..95c924e 100644 --- a/web/js/opentrashmail.js +++ b/web/js/opentrashmail.js @@ -37,10 +37,13 @@ function renderEmail(email,id,data) btns+=''+filename+'' } $("#main").html('

'+email+'

\ - \ +
\ '+(data.parsed.body?'
'+data.parsed.body+'
':'')+' \ '+(data.parsed.htmlbody?'
'+data.parsed.htmlbody+'':'')+' \ '+(btns!==''?'

Attachments

'+btns:'')+'\ +
\ +

Raw Email

'+data.raw+'
\ +
\ ') } @@ -63,6 +66,7 @@ function loadAccount(email) Date\ From\ Subject\ + Action\ \ \ \ @@ -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('\ - \ + \ '+(index++)+'\ '+datestring+'\ '+(admin===true?''+email+'':'')+'\ '+ed.from.toHtmlEntities()+'\ '+ed.subject.toHtmlEntities()+'\ + \ '); } else if(lastid==0 && $("#nomailyet").length == 0){ $("#emailtable").append('\ \ -

No emails received on this address (yet..)

\ +

No emails received on this address (yet..)

\ '); } } @@ -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(); +}); \ No newline at end of file