-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrontend.template.php
334 lines (276 loc) · 13.2 KB
/
frontend.template.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
<?php
/*
input:
User $user - User object
array $config - config array
array $emails - array of emails
*/
require_once './autolink.php';
// Load HTML Purifier
$purifier_config = HTMLPurifier_Config::createDefault();
$purifier_config->set('HTML.Nofollow', true);
$purifier_config->set('HTML.ForbiddenElements', array("img"));
$purifier = new HTMLPurifier($purifier_config);
\Moment\Moment::setLocale($config['locale']);
$mailIds = array_map(function ($mail) {
return $mail['id'];
}, $emails);
$mailIdsJoinedString = filter_var(join('|', $mailIds), FILTER_SANITIZE_SPECIAL_CHARS);
// define bigger renderings here to keep the php sections within the html short.
function niceDate($date)
{
$m = new \Moment\Moment($date, date_default_timezone_get());
return $m->calendar();
}
function printMessageBody($email, $purifier)
{
global $config;
// To avoid showing empty mails, first purify the html and plaintext
// before checking if they are empty.
$safeHtml = $purifier->purify($email->textHtml);
$safeText = htmlspecialchars($email->textPlain);
$safeText = nl2br($safeText);
$safeText = \AutoLinkExtension::auto_link_text($safeText);
$hasHtml = strlen(trim($safeHtml)) > 0;
$hasText = strlen(trim($safeText)) > 0;
if ($config['prefer_plaintext']) {
if ($hasText) {
echo $safeText;
} else {
echo $safeHtml;
}
} else {
if ($hasHtml) {
echo $safeHtml;
} else {
echo $safeText;
}
}
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="assets/bootstrap/4.1.1/bootstrap.min.css">
<link rel="stylesheet" href="assets/fontawesome/v5.0.13/all.css">
<title><?php
echo $emails ? "(" . count($emails) . ") " : "";
echo $user->address ?></title>
<link rel="stylesheet" href="assets/spinner.css">
<link rel="stylesheet" href="assets/custom.css">
<script>
var mailCount = <?php echo count($emails) ?>;
setInterval(function() {
var r = new XMLHttpRequest();
r.open("GET", "?action=has_new_messages&address=<?php echo $user->address ?>&email_ids=<?php echo $mailIdsJoinedString ?>", true);
r.onreadystatechange = function() {
if (r.readyState != 4 || r.status != 200) return;
if (r.responseText > 0) {
console.log("There are", r.responseText, "new mails.");
document.getElementById("new-content-avalable").style.display = 'block';
// If there are no emails displayed, we can reload the page without losing any state.
if (mailCount === 0) {
location.reload();
}
}
};
r.send();
}, 15000);
</script>
</head>
<body>
<div id="new-content-avalable">
<div class="alert alert-info alert-fixed" role="alert">
<strong>New emails</strong> have arrived.
<button type="button" class="btn btn-outline-secondary" onclick="location.reload()">
<i class="fas fa-sync"></i>
Reload!
</button>
</div>
<!-- move the rest of the page a bit down to show all content -->
<div style="height: 3rem"> </div>
</div>
<header>
<div class="container">
<p class="lead ">
Your disposable mailbox is ready.
</p>
<div class="row" id="address-box-normal">
<div class="col my-address-block">
<span id="my-address"><?php echo $user->address ?></span> <button class="copy-button" data-clipboard-target="#my-address">Copy</button>
</div>
<div class="col get-new-address-col">
<button type="button" class="btn btn-outline-dark" title="Reload page" onclick="location.reload()">
<i class="fas fa-magic"></i> Reload
</button>
</div>
</div>
<form class="collapse change-address-toggle" id="address-box-edit" action="?action=redirect" method="post">
<div class="card">
<div class="card-body">
<p>
<a href="?action=random" role="button" class="btn btn-dark">
<i class="fa fa-random"></i>
Open random mailbox
</a>
</p>
or create your own address:
<div class="form-row align-items-center">
<div class="col-sm">
<label class="sr-only" for="inlineFormInputName">username</label>
<input name="username" type="text" class="form-control" id="inlineFormInputName" placeholder="username" value="<?php echo $user->username ?>">
</div>
<div class="col-sm-auto my-1">
<label class="sr-only" for="inlineFormInputGroupUsername">Domain</label>
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text">@</div>
</div>
<select class="custom-select" id="inlineFormInputGroupUsername" name="domain">
<?php
foreach ($config['domains'] as $aDomain) {
$selected = $aDomain === $user->domain ? ' selected ' : '';
print "<option value='$aDomain' $selected>$aDomain</option>";
}
?>
</select>
</div>
</div>
<div class="col-auto my-1">
<button type="submit" class="btn btn-primary">Open mailbox</button>
</div>
</div>
</div>
</div>
</form>
</div>
</header>
<main>
<div class="container">
<div id="email-list" class="list-group">
<?php
foreach ($emails as $email) {
$safe_email_id = filter_var($email['id'], FILTER_VALIDATE_INT); ?>
<a class="list-group-item list-group-item-action email-list-item" data-toggle="collapse" href="#mail-box-<?php echo $email['id'] ?>" role="button" aria-expanded="false" aria-controls="mail-box-<?php echo $email['id'] ?>">
<div class="media">
<button class="btn btn-white open-collapse-button">
<i class="fas fa-caret-right expand-button-closed"></i>
<i class="fas fa-caret-down expand-button-opened"></i>
</button>
<div class="media-body">
<h6 class="list-group-item-heading"><?php echo filter_var($email['name'], FILTER_SANITIZE_SPECIAL_CHARS) ?>
<span class="text-muted"><?php echo filter_var($email['address'], FILTER_SANITIZE_SPECIAL_CHARS) ?></span>
<small class="float-right" title="<?php echo $email['pubDate'] ?>"><?php echo niceDate($email['pubDate']) ?></small>
</h6>
<p class="list-group-item-text text-truncate" style="width: 75%">
<?php echo filter_var($email['title'], FILTER_SANITIZE_SPECIAL_CHARS); ?>
</p>
</div>
</div>
</a>
<div id="mail-box-<?php echo $email['id'] ?>" role="tabpanel" aria-labelledby="headingCollapse1" class="card-collapse collapse" aria-expanded="true">
<div class="card-body">
<div class="card-block email-body">
<div class="float-right primary">
<a class="btn btn-outline-primary btn-sm" download="true" role="button" href="<?php echo "?action=download_email&email_id=$safe_email_id&address=$user->address" ?>">
Download
</a>
<a class="btn btn-outline-danger btn-sm" role="button" href="<?php echo "?action=delete_email&email_id=$safe_email_id&address=$user->address" ?>">
Delete
</a>
</div>
<?php
echo htmlspecialchars_decode($email["description"]);
?>
</div>
</div>
</div>
<?php
} ?>
<?php
if (empty($emails)) {
?>
<div id="empty-mailbox">
<p>The mailbox is empty. Checking for new emails automatically. </p>
<div class="spinner">
<div class="rect1"></div>
<div class="rect2"></div>
<div class="rect3"></div>
<div class="rect4"></div>
<div class="rect5"></div>
</div>
</div>
<?php
} ?>
</div>
</div>
</main>
<footer>
<div class="container">
<!-- <select id="language-selection" class="custom-select" title="Language">-->
<!-- <option selected>English</option>-->
<!-- <option value="1">Deutsch</option>-->
<!-- <option value="2">Two</option>-->
<!-- <option value="3">Three</option>-->
<!-- </select>-->
<!-- <br>-->
<small class="text-justify quick-summary">
This is a disposable mailbox service. Whoever knows your username, can read your emails.
Emails will be deleted after 30 days.
<a data-toggle="collapse" href="#about" aria-expanded="false" aria-controls="about">
Show Details
</a>
</small>
<div class="card card-body collapse" id="about" style="max-width: 40rem">
<p class="text-justify">This disposable mailbox keeps your main mailbox clean from spam.</p>
<p class="text-justify">Just choose an address and use it on websites you don't trust and
don't
want to use
your
main email address.
Once you are done, you can just forget about the mailbox. All the spam stays here and does
not
fill up
your
main mailbox.
</p>
<p class="text-justify">
You select the address you want to use and received emails will be displayed
automatically.
There is no registration and no passwords. If you know the address, you can read the
emails.
<strong>Basically, all emails are public. So don't use it for sensitive data.</strong>
</p>
</div>
<p>
<small>Powered by
<a href="https://github.com/synox/disposable-mailbox"><strong>synox/disposable-mailbox</strong></a>
</small>
</p>
</div>
</footer>
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="assets/jquery/jquery-3.3.1.slim.min.js"></script>
<script src="assets/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="assets/bootstrap/4.1.1/bootstrap.min.js"></script>
<script src="assets/clipboard.js/clipboard.min.js"></script>
<script>
clipboard = new ClipboardJS('[data-clipboard-target]');
$(function() {
$('[data-tooltip="tooltip"]').tooltip()
});
/** from https://github.com/twbs/bootstrap/blob/c11132351e3e434f6d4ed72e5a418eb692c6a319/assets/js/src/application.js */
clipboard.on('success', function(e) {
$(e.trigger)
.attr('title', 'Copied!')
.tooltip('_fixTitle')
.tooltip('show')
.tooltip('_fixTitle');
e.clearSelection();
});
</script>
</body>
</html>