use QUERY_STRING and show reload icon

This commit is contained in:
Synox 2018-01-09 19:41:50 +01:00
parent ff2e437138
commit bfa4070c56
3 changed files with 211 additions and 212 deletions

View File

@ -51,8 +51,6 @@ function delete_email($mailid, $address) {
if (_load_one_email($mailid, $address) !== null) {
$mailbox->deleteMail($mailid);
$mailbox->expungeDeletedMails();
header('Content-type: application/json');
print(json_encode(array("success" => true)));
} else {
error(404, 'delete error: invalid username/mailid combination');
}
@ -140,8 +138,7 @@ function redirect_to_random($domains) {
$name = $word . $nr;
$domain = $domains[array_rand($domains)];
header("location: ?address=$name@$domain");
header("location: ?$name@$domain");
}
/**
@ -157,11 +154,6 @@ function delete_old_messages() {
$mailbox->expungeDeletedMails();
}
//
//// Never cache requests:
//header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
//header("Cache-Control: post-check=0, pre-check=0", false);
//header("Pragma: no-cache");
// run on every request
delete_old_messages();

BIN
src/if_sync-01_186384.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

View File

@ -1,55 +1,50 @@
<?php
require_once('backend.php');
if (isset($_GET['random'])) {
redirect_to_random($config['domains']);
die();
} elseif (isset($_GET['username']) && isset($_GET['domain'])) {
// simple router:
if (isset($_GET['username']) && isset($_GET['domain'])) {
$username = filter_input(INPUT_GET, 'username', FILTER_SANITIZE_EMAIL);
$domain = filter_input(INPUT_GET, 'domain', FILTER_SANITIZE_EMAIL);
header("location: ?address=$username@$domain");
die();
} elseif (!isset($_GET['address'])) {
redirect_to_random($config['domains']);
} else {
// perform common validation:
header("location: ?$username@$domain");
exit();
} elseif (isset($_GET['download_email_id'])) {
$address = filter_input(INPUT_GET, 'address', FILTER_SANITIZE_EMAIL);
$username = _clean_username($address);
$userDomain = _clean_domain($address);
if (strlen($address) === 0) {
error(400, 'invalid username');
}
if (strlen($userDomain) === 0 || !in_array($userDomain, $config['domains'])) {
error(400, 'invalid domain');
}
// simple router:
if (isset($_GET['download_email_id'])) {
download_email($_GET['download_email_id'], $address);
die();
}
if (isset($_GET['delete_email_id'])) {
exit();
} elseif (isset($_GET['delete_email_id'])) {
$address = filter_input(INPUT_GET, 'address', FILTER_SANITIZE_EMAIL);
$delete_email_id = filter_input(INPUT_GET, 'delete_email_id', FILTER_SANITIZE_NUMBER_INT);
delete_email($delete_email_id, $address);
header("location: ?$address");
exit();
} elseif (isset($_GET['random'])) {
redirect_to_random($config['domains']);
exit();
} else {
// validate & print emails:
$address = filter_var($_SERVER['QUERY_STRING'], FILTER_SANITIZE_EMAIL);
$username = _clean_username($address);
$userDomain = _clean_domain($address);
if (empty($username) || empty($userDomain)) {
redirect_to_random($config['domains']);
exit();
}
// print emails:
$emails = get_emails($address);
}
?>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Mailbox <?php echo $address ?></title>
<title><?php echo $address ?></title>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/css/bootstrap.min.css"
integrity="sha384-AysaV+vQoT3kOAXZkl02PThvDr8HYKPZhNT5h/CXfBThSRXQ6jW5DO2ekP5ViFdi" crossorigin="anonymous">
integrity="sha384-AysaV+vQoT3kOAXZkl02PThvDr8HYKPZhNT5h/CXfBThSRXQ6jW5DO2ekP5ViFdi"
crossorigin="anonymous">
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="spinner.css">
@ -62,10 +57,13 @@ if (isset($_GET['random'])) {
var scrollPosition;
function reload() {
scrollPosition = [window.scrollX, window.scrollY];
Turbolinks.visit(window.location.toString(), {action: 'replace'})
}
document.addEventListener('turbolinks:before-render', function () {
scrollPosition = [window.scrollX, window.scrollY];
});
document.addEventListener('turbolinks:load', function () {
if (scrollPosition) {
window.scrollTo.apply(window, scrollPosition);
@ -79,7 +77,7 @@ if (isset($_GET['random'])) {
setInterval(function () {
reloadWithTurbolinks();
}, 10000)
}, 15000)
</script>
</head>
@ -87,7 +85,7 @@ if (isset($_GET['random'])) {
<body data-turbolinks="false">
<header>
<header data-turbolinks-permanent id="header">
<div class="container">
<small class="form-text text-muted">
change username:
@ -97,11 +95,11 @@ if (isset($_GET['random'])) {
<div class="form-group row">
<div class="col-sm-4">
<input id="username" data-turbolinks-permanent class="form-control form-control-lg" name="username"
<input id="username" class="form-control form-control-lg" name="username"
value="<?php echo $username ?>">
</div>
<div class="col-sm-3">
<select id="domain" data-turbolinks-permanent class="form-control form-control-lg" name="domain">
<select id="domain" class="form-control form-control-lg" name="domain">
<?php
foreach ($config['domains'] as $domain) {
$selected = $domain === $userDomain ? ' selected ' : '';
@ -110,7 +108,11 @@ if (isset($_GET['random'])) {
?>
</select>
</div>
<div class="col-sm-1">
<button type="submit" class="btn" style="background-color:transparent">
<img src="if_sync-01_186384.png" width="32" height="32" alt="submit"/>
</button>
</div>
<div class="col-sm-3 random-column">
<span>or &nbsp;</span>
<a role="button" href="?random=true" class="btn btn-outline-primary">generate random
@ -173,9 +175,11 @@ if (isset($_GET['random'])) {
href="?download_email_id=<?php echo filter_var($email->id, FILTER_VALIDATE_INT); ?>&amp;address=<?php echo $address ?>">Download
</a>
<!-- <button class="btn btn-sm btn-outline-danger" type="button">-->
<!-- Delete-->
<!-- </button>-->
<a class="btn btn-sm btn-outline-danger"
role="button"
href="?delete_email_id=<?php echo filter_var($email->id, FILTER_VALIDATE_INT); ?>&amp;address=<?php echo $address ?>">Delete
</a>
</form>
</div>
</div>
@ -238,3 +242,6 @@ if (isset($_GET['random'])) {
</main>
</body>
</html>
<?php
}
?>