\
')
timer = setInterval(updateEmailTable, 5000); //check for new mail every 5 seconds
updateEmailTable(); //and check now
}
else
{
changeHash("")
}
}
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()
if(email)
loadAccount(email)
else alert("Enter an email you want to access")
}
function generateAccount()
{
var email = makeName()+'@'+domains[Math.floor(Math.random()*domains.length)];
loadAccount(email)
}
function changeHash(val)
{
if(history.pushState) {
history.pushState(null, null, '#'+val);
}
else {
location.hash = '#'+val;
}
}
function validateEmail(email) {
var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(String(email).toLowerCase());
}
/**
* Convert a string to HTML entities
*/
String.prototype.toHtmlEntities = function() {
return this.replace(/./gm, function(s) {
return "" + s.charCodeAt(0) + ";";
});
};
/**
* Create string from HTML entities
*/
String.fromHtmlEntities = function(string) {
return (string+"").replace(/\d+;/gm,function(s) {
return String.fromCharCode(s.match(/\d+/gm)[0]);
})
};