diff --git a/README.md b/README.md index 6bdec4a..ff197b0 100644 --- a/README.md +++ b/README.md @@ -29,16 +29,19 @@ - [x] Download attachments in a safe way - [x] Display Text/HTML - [x] API so all features from the site can also be automated and integrated - - [ ] Automatically check for new emails while on site + - [x] Automatically check for new emails while on site - [ ] Secure HTML so no malicious things can be loaded - [ ] Display embedded images inline using Content-ID - [ ] Admin overview for all available email addresses - [ ] Delete messages + - [ ] Make better theme - [ ] Configurable settings - [x] Choose domains for random generation - [ ] Choose if out-of-scope emails are discarded - [ ] Honeypot mode where all emails are also saved for a catchall account -- [ ] Docker files and config + - [ ] Optionally secure whole site with a password + - [ ] Optinally allow site to be seen only from specific IP Range +- [ ] Docker files and configs # Features - Python powered mail server that works out of the box for any domain diff --git a/web/api.php b/web/api.php index 0212fab..e62be31 100644 --- a/web/api.php +++ b/web/api.php @@ -60,6 +60,18 @@ switch($action) else { $data = getEmailsOfEmail($email); + + $lastid = $_REQUEST['lastid']; + if($lastid && is_numeric($lastid)) + { + foreach($data as $time=>$d) + { + if($time>$lastid) + $emails[$time]=$d; + } + $data = (is_array($emails)?$emails:array()); + } + $o = array('status'=>'ok','emails'=>$data); } break; diff --git a/web/js/opentrashmail.js b/web/js/opentrashmail.js index 59a5a2b..a5d2643 100644 --- a/web/js/opentrashmail.js +++ b/web/js/opentrashmail.js @@ -1,12 +1,17 @@ var domains = []; +var lastid = 0; +var activeemail = ''; +var timer; $( document ).ready(function() { + + $.ajaxSetup({ cache: false }); + var email = window.location.hash.substr(1); if(validateEmail(email)) loadAccount(email) $.get("api.php?a=getdoms",function(data){ - console.log(data) domains = data; },"json") }); @@ -14,7 +19,7 @@ $( document ).ready(function() { function loadMail(email,id) { $.get("api.php?a=load&email="+email+"&id="+id,function(data){ - //console.log(data); + // if(data.status=="ok") { renderEmail(email,id,data.data) @@ -24,16 +29,15 @@ function loadMail(email,id) function renderEmail(email,id,data) { - console.log("rendering") - console.log(data) + clearInterval(timer); var btns = '' for(att in data.parsed.attachments) { - console.log(data.parsed.attachments[att]) var filename=data.parsed.attachments[att].substr(14) btns+=''+filename+'' } $("#main").html('

'+email+'

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

Attachments

'+btns:'')+'\ @@ -44,9 +48,12 @@ function loadAccount(email) { if(validateEmail(email)) { - var index = 1; + activeemail = email; + + lastid = 0; changeHash(email) $("#main").html('

'+email+'

\ + \ \ \ \ @@ -61,33 +68,8 @@ function loadAccount(email)
\ ') - $.get("api.php?a=list&email="+email,function(data){ - console.log(data); - if(data.status=="ok") - { - if(Object.keys(data.emails).length>0) - for(em in data.emails) - { - var date = new Date(parseInt(em)) - var datestring = date.getDate()+"."+date.getMonth()+"."+date.getFullYear()+" "+date.getHours()+":"+date.getMinutes(); - var ed = data.emails[em] - $("#emailtable").append('\ - \ - '+(index++)+'\ - '+datestring+'\ - '+ed.from.toHtmlEntities()+'\ - '+ed.subject.toHtmlEntities()+'\ - '); - } - else{ - console.log("leider keine post") - $("#emailtable").append('\ - \ -

No emails received on this address (yet..)

\ - '); - } - } - },"json") + timer = setInterval(updateEmailTable, 5000); //check for new mail every 5 seconds + updateEmailTable(); //and check now } else { @@ -95,6 +77,42 @@ function loadAccount(email) } } +function updateEmailTable() +{ + var email = activeemail; + var index = 1; + console.log("Checking mail for "+email) + + $.get("api.php?a=list&email="+email+"&lastid="+lastid,function(data){ + + if(data.status=="ok") + { + if(Object.keys(data.emails).length>0) + for(em in data.emails) + { + if(em>lastid) lastid = em; + var date = new Date(parseInt(em)) + var datestring = date.getDate()+"."+date.getMonth()+"."+date.getFullYear()+" "+date.getHours()+":"+date.getMinutes(); + var ed = data.emails[em] + $("#emailtable").append('\ + \ + '+(index++)+'\ + '+datestring+'\ + '+ed.from.toHtmlEntities()+'\ + '+ed.subject.toHtmlEntities()+'\ + '); + } + else if(lastid==0){ + console.log("leider keine post") + $("#emailtable").append('\ + \ +

No emails received on this address (yet..)

\ + '); + } + } + },"json") +} + function accessAccount() { var email = $("#email").val()