-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPublic.Mail_Client.html
More file actions
1665 lines (1558 loc) · 53.5 KB
/
Copy pathPublic.Mail_Client.html
File metadata and controls
1665 lines (1558 loc) · 53.5 KB
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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Public.Mail — name-only public mail API-key fixed</title>
<style>
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
--bg: #f8fafc;
--surface: #ffffff;
--border: #e2e8f0;
--text: #0f172a;
--text-secondary: #475569;
--text-muted: #94a3b8;
--accent: #2563eb;
--accent-hover: #1d4ed8;
--accent-light: #eff6ff;
--danger: #ef4444;
--danger-hover: #dc2626;
--success: #22c55e;
--warning: #f59e0b;
--radius: 8px;
--shadow: 0 1px 3px rgba(0,0,0,0.06);
}
body {
font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
background: var(--bg);
color: var(--text);
height: 100vh;
overflow: hidden;
font-size: 14px;
line-height: 1.5;
}
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
#app { height: 100vh; display: flex; flex-direction: column; }
#login-view, #mail-view { flex: 1; overflow: hidden; }
#login-view {
display: flex;
align-items: center;
justify-content: center;
background: var(--bg);
padding: 20px;
}
.login-box {
max-width: 440px;
width: 100%;
background: var(--surface);
border-radius: var(--radius);
box-shadow: 0 4px 24px rgba(0,0,0,0.06);
padding: 32px 28px;
border: 1px solid var(--border);
}
.login-box h1 {
font-size: 23px;
font-weight: 700;
letter-spacing: -0.5px;
margin-bottom: 6px;
color: var(--text);
}
.login-box .sub {
font-size: 13px;
color: var(--text-secondary);
margin-bottom: 22px;
}
.form-group { margin-bottom: 16px; }
.form-group label {
display: block;
font-size: 13px;
font-weight: 600;
color: var(--text-secondary);
margin-bottom: 4px;
}
.form-group input {
width: 100%;
padding: 10px 12px;
border: 1px solid var(--border);
border-radius: 6px;
font-size: 14px;
background: var(--surface);
color: var(--text);
transition: border 0.15s;
}
.form-group input:focus {
border-color: var(--accent);
outline: none;
box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.hint {
font-size: 12px;
color: var(--text-muted);
margin-top: 4px;
}
.warning-box {
background: #fffbeb;
border: 1px solid #fde68a;
color: #92400e;
padding: 10px 12px;
border-radius: 6px;
font-size: 12px;
margin: 14px 0 18px;
}
details.network-box {
border: 1px solid var(--border);
border-radius: 6px;
padding: 10px 12px;
margin-bottom: 16px;
background: var(--bg);
}
details.network-box summary {
cursor: pointer;
color: var(--text-secondary);
font-size: 13px;
font-weight: 600;
}
.network-inner { margin-top: 12px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { min-width: 0; }
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
padding: 10px 18px;
border: none;
border-radius: 6px;
font-weight: 600;
font-size: 14px;
cursor: pointer;
transition: all 0.15s;
background: var(--accent);
color: white;
width: 100%;
white-space: nowrap;
}
.btn:hover { background: var(--accent-hover); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-secondary { background: var(--bg); color: var(--text-secondary); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-sm { padding: 6px 12px; font-size: 12px; width: auto; }
.login-foot {
margin-top: 18px;
font-size: 12px;
color: var(--text-muted);
text-align: center;
border-top: 1px solid var(--border);
padding-top: 16px;
}
code {
background: var(--bg);
border: 1px solid var(--border);
padding: 1px 6px;
border-radius: 4px;
font-size: 12px;
word-break: break-all;
}
#mail-view { display: none; flex-direction: row; }
.sidebar {
width: 230px;
background: var(--surface);
border-right: 1px solid var(--border);
display: flex;
flex-direction: column;
flex-shrink: 0;
}
.sidebar-header {
padding: 16px 18px;
border-bottom: 1px solid var(--border);
}
.sidebar-header h2 {
font-size: 16px;
font-weight: 700;
letter-spacing: -0.3px;
color: var(--text);
}
.sidebar-id {
font-size: 12px;
color: var(--text-muted);
margin-top: 4px;
word-break: break-word;
display: block;
}
.sidebar-id.clickable { cursor: pointer; }
.sidebar-id.clickable:hover { color: var(--accent); }
.nav-btn {
display: flex;
align-items: center;
gap: 10px;
padding: 10px 18px;
border: none;
background: transparent;
font-size: 13px;
font-weight: 600;
color: var(--text-secondary);
cursor: pointer;
transition: all 0.1s;
border-left: 3px solid transparent;
text-align: left;
width: 100%;
}
.nav-btn:hover { background: var(--bg); color: var(--text); }
.nav-btn.active {
background: var(--accent-light);
color: var(--accent);
border-left-color: var(--accent);
}
.nav-btn .badge {
margin-left: auto;
background: var(--accent);
color: white;
font-size: 11px;
font-weight: 700;
padding: 0 8px;
border-radius: 12px;
min-width: 20px;
text-align: center;
line-height: 18px;
}
.sidebar-footer {
margin-top: auto;
padding: 12px 18px;
border-top: 1px solid var(--border);
display: flex;
flex-direction: column;
gap: 6px;
}
.sidebar-footer .btn { width: 100%; font-size: 12px; padding: 7px; }
.main {
flex: 1;
display: flex;
flex-direction: column;
background: var(--bg);
min-width: 0;
}
.topbar {
padding: 12px 20px;
background: var(--surface);
border-bottom: 1px solid var(--border);
display: flex;
align-items: center;
justify-content: space-between;
flex-shrink: 0;
gap: 12px;
flex-wrap: wrap;
}
.topbar h3 {
font-size: 16px;
font-weight: 700;
color: var(--text);
display: flex;
align-items: baseline;
gap: 8px;
}
.topbar h3 small {
font-weight: 400;
font-size: 13px;
color: var(--text-muted);
}
.topbar-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.content { flex: 1; overflow-y: auto; padding: 16px 20px; }
.email-list, .card-list {
background: var(--surface);
border-radius: var(--radius);
border: 1px solid var(--border);
overflow: hidden;
}
.email-item {
display: flex;
align-items: center;
padding: 12px 16px;
border-bottom: 1px solid var(--border);
cursor: pointer;
transition: background 0.1s;
gap: 12px;
}
.email-item:last-child { border-bottom: none; }
.email-item:hover { background: var(--bg); }
.email-item.unread { border-left: 3px solid var(--accent); }
.email-item.read { border-left: 3px solid transparent; }
.email-item.read .from, .email-item.read .subject { color: var(--text-secondary); }
.from { width: 150px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex-shrink: 0; }
.subject { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.date { width: 100px; text-align: right; font-size: 12px; color: var(--text-muted); flex-shrink: 0; }
.email-actions { display: flex; gap: 4px; flex-shrink: 0; }
.email-actions button {
background: transparent;
border: none;
color: var(--text-muted);
cursor: pointer;
padding: 4px 6px;
border-radius: 4px;
font-size: 13px;
transition: all 0.15s;
}
.email-actions button:hover { background: var(--danger); color: white; }
.empty-state {
text-align: center;
padding: 48px 20px;
color: var(--text-secondary);
}
.empty-state h4 { font-weight: 700; margin-bottom: 8px; color: var(--text); }
.empty-state p { font-size: 13px; max-width: 500px; margin: 0 auto 8px; }
.user-item {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 12px 16px;
border-bottom: 1px solid var(--border);
}
.user-item:last-child { border-bottom: none; }
.user-name { font-weight: 700; }
.user-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.modal-overlay {
position: fixed;
inset: 0;
background: rgba(15,23,42,0.5);
backdrop-filter: blur(4px);
display: none;
align-items: center;
justify-content: center;
z-index: 100;
padding: 20px;
}
.modal-overlay.active { display: flex; }
.modal {
background: var(--surface);
width: 100%;
max-width: 720px;
max-height: 90vh;
border-radius: var(--radius);
box-shadow: 0 20px 60px rgba(0,0,0,0.15);
display: flex;
flex-direction: column;
overflow: hidden;
animation: fadeIn 0.15s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.modal-header {
padding: 16px 20px;
border-bottom: 1px solid var(--border);
display: flex;
align-items: center;
justify-content: space-between;
}
.modal-header h3 {
font-size: 16px;
font-weight: 700;
display: flex;
align-items: center;
gap: 8px;
}
.modal-close {
background: transparent;
border: none;
font-size: 22px;
cursor: pointer;
color: var(--text-muted);
line-height: 1;
padding: 0 4px;
}
.modal-close:hover { color: var(--text); }
.modal-body { flex: 1; overflow-y: auto; padding: 20px; }
.modal-meta {
display: flex;
gap: 20px;
padding: 8px 20px;
background: var(--bg);
border-bottom: 1px solid var(--border);
font-size: 13px;
color: var(--text-secondary);
flex-wrap: wrap;
}
.modal-meta strong { color: var(--text); }
.modal-footer {
padding: 12px 20px;
border-top: 1px solid var(--border);
display: flex;
justify-content: flex-end;
gap: 8px;
background: var(--bg);
}
.modal-footer .btn { width: auto; }
.message-body { white-space: pre-wrap; word-wrap: break-word; line-height: 1.7; }
.compose-field { margin-bottom: 16px; }
.compose-field label {
display: block;
font-size: 13px;
font-weight: 600;
color: var(--text-secondary);
margin-bottom: 4px;
}
.compose-field input, .compose-field textarea {
width: 100%;
padding: 10px 12px;
border: 1px solid var(--border);
border-radius: 6px;
font-size: 14px;
font-family: inherit;
background: var(--surface);
color: var(--text);
transition: border 0.15s;
}
.compose-field input:focus, .compose-field textarea:focus {
border-color: var(--accent);
outline: none;
box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.compose-field textarea { min-height: 150px; resize: vertical; }
.compose-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.file-attach-area {
border: 2px dashed var(--border);
border-radius: 6px;
padding: 16px;
text-align: center;
cursor: pointer;
transition: all 0.15s;
margin-top: 8px;
}
.file-attach-area:hover { border-color: var(--accent); background: var(--accent-light); }
.file-attach-area input[type="file"] { display: none; }
.attachments-list { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.att-item {
display: flex;
align-items: center;
justify-content: space-between;
background: var(--bg);
padding: 6px 12px;
border-radius: 4px;
font-size: 13px;
gap: 10px;
}
.att-item .remove-att { background: transparent; border: none; color: var(--danger); cursor: pointer; font-size: 16px; }
.att-item .remove-att:hover { color: var(--danger-hover); }
.attachment-downloads {
margin-top: 18px;
border-top: 1px solid var(--border);
padding-top: 14px;
}
.attachment-downloads h4 { font-size: 13px; margin-bottom: 8px; }
.attachment-downloads a {
display: inline-flex;
margin: 4px 6px 4px 0;
padding: 6px 10px;
border-radius: 6px;
background: var(--accent-light);
color: var(--accent);
text-decoration: none;
font-size: 12px;
font-weight: 700;
}
.toast-container {
position: fixed;
bottom: 20px;
right: 20px;
z-index: 200;
display: flex;
flex-direction: column;
gap: 8px;
max-width: 380px;
width: calc(100% - 40px);
pointer-events: none;
}
.toast {
background: var(--surface);
color: var(--text);
padding: 12px 16px;
border-radius: var(--radius);
box-shadow: 0 4px 20px rgba(0,0,0,0.12);
border: 1px solid var(--border);
font-size: 13px;
pointer-events: auto;
transform: translateX(120%);
transition: transform 0.25s ease;
}
.toast.show { transform: translateX(0); }
.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
.toast.warning { border-left: 4px solid var(--warning); }
@media (max-width: 700px) {
.sidebar { width: 62px; }
.sidebar-header h2, .sidebar-id, .nav-btn span.label, .nav-btn .badge { display: none; }
.nav-btn { justify-content: center; padding: 12px 0; font-size: 18px; }
.from { width: 88px; }
.date { width: 70px; }
.topbar h3 { font-size: 14px; }
.modal { max-width: 100%; margin: 10px; }
.row { flex-direction: column; align-items: stretch; }
}
</style>
</head>
<body>
<div id="app">
<div id="login-view">
<div class="login-box">
<h1>✉️ Public.Mail</h1>
<div class="sub">Name-only public messaging · no passwords · no encryption</div>
<div class="form-group">
<label>Your name</label>
<input type="text" id="login-name" placeholder="e.g. username" autocomplete="username" onkeydown="if(event.key==='Enter')doLogin()">
<div class="hint">Use letters, numbers, dot, dash, or underscore. Log in creates the name automatically when it does not exist.</div>
</div>
<details class="network-box" id="network-details">
<summary>Network setup</summary>
<div class="network-inner">
<div class="form-group" style="margin-bottom:10px">
<label>Public network URL / ID</label>
<input type="text" id="network-id" placeholder="Leave empty to create a new public network" autocomplete="off">
<div class="hint">Share this one network URL/ID with other users once. After that, everyone logs in by name.</div>
</div>
<div class="form-group" style="margin-bottom:10px">
<label>Backend edit key</label>
<input type="text" id="backend-key" placeholder="Public JsonStorage API key" autocomplete="off">
<div class="hint">JsonStorage requires this only to create/update the public network. It is not a user password; this public build pre-fills a demo key.</div>
</div>
<div class="row">
<button class="btn btn-secondary btn-sm" onclick="useNetworkId()">Use this network</button>
<button class="btn btn-secondary btn-sm" onclick="newNetwork()">Create new network</button>
</div>
</div>
</details>
<div class="warning-box">
This build is intentionally public: names, messages, and attachments are plaintext. Anyone with the network URL/ID can read or modify the mailboxes. There is no password and no encryption in this usability build.
</div>
<button class="btn" id="login-btn" onclick="doLogin()">📬 Enter Public.Mail</button>
<div class="login-foot">
jsonstorage.net backend · direct browser CORS · public directory + public mailboxes · public backend edit key<br>Requires live internet access. No local-only fallback is used.<br>
<span id="saved-network-note">No network selected yet.</span>
</div>
</div>
</div>
<div id="mail-view">
<aside class="sidebar">
<div class="sidebar-header">
<h2>✉️ Public.Mail</h2>
<div class="sidebar-id" id="sb-name">…</div>
<div class="sidebar-id clickable" id="sb-network" onclick="copyNetworkId()" title="Click to copy network URL">network …</div>
</div>
<button class="nav-btn active" id="nav-in" onclick="showInbox()">
<span>📥</span> <span class="label">Inbox</span>
<span class="badge" id="ubadge" style="display:none">0</span>
</button>
<button class="nav-btn" id="nav-se" onclick="showSent()">
<span>📤</span> <span class="label">Sent</span>
</button>
<button class="nav-btn" id="nav-users" onclick="showUsers()">
<span>👥</span> <span class="label">Users</span>
</button>
<button class="nav-btn" onclick="openCompose()">
<span>✏️</span> <span class="label">Compose</span>
</button>
<div class="sidebar-footer">
<button class="btn btn-secondary btn-sm" onclick="doSync()">🔄 Sync</button>
<button class="btn btn-secondary btn-sm" onclick="copyName()">📋 Copy Name</button>
<button class="btn btn-secondary btn-sm" onclick="copyNetworkId()">🌐 Copy Network</button>
<button class="btn btn-danger btn-sm" onclick="doLogout()">🚪 Logout</button>
</div>
</aside>
<main class="main">
<div class="topbar">
<h3 id="ptitle">Inbox <small id="sync-status"></small></h3>
<div class="topbar-actions">
<button class="btn btn-secondary btn-sm" onclick="doSync()">Sync</button>
<button class="btn btn-sm" onclick="openCompose()">Compose</button>
</div>
</div>
<div class="content" id="mcontent">
<div class="empty-state"><h4>Loading…</h4></div>
</div>
</main>
</div>
<div class="modal-overlay" id="ov-read">
<div class="modal">
<div class="modal-header">
<h3 id="r-subj">Subject</h3>
<button class="modal-close" onclick="closeRead()">×</button>
</div>
<div class="modal-meta">
<span><strong>From:</strong> <span id="r-from"></span></span>
<span><strong>To:</strong> <span id="r-to"></span></span>
<span><strong>Date:</strong> <span id="r-date"></span></span>
<span style="margin-left:auto;"><span id="r-att-count" style="color:var(--text-muted);font-size:12px;"></span></span>
</div>
<div class="modal-body" id="r-body"></div>
<div class="modal-footer">
<button class="btn btn-secondary btn-sm" onclick="closeRead()">Close</button>
<button class="btn btn-secondary btn-sm" onclick="replyTo()">↩ Reply</button>
<button class="btn btn-danger btn-sm" onclick="delCurrent()">🗑 Delete</button>
</div>
</div>
</div>
<div class="modal-overlay" id="ov-compose">
<div class="modal">
<div class="modal-header">
<h3>✏️ Compose public mail</h3>
<button class="modal-close" onclick="closeCompose()">×</button>
</div>
<div class="modal-body">
<div class="compose-field">
<label>To — public name</label>
<input type="text" id="c-to" placeholder="e.g. username" autocomplete="off" list="user-list">
<datalist id="user-list"></datalist>
<div class="compose-hint">If the name does not exist yet, public.mail will create that mailbox automatically.</div>
</div>
<div class="compose-field">
<label>Subject</label>
<input type="text" id="c-subj" placeholder="(no subject)" autocomplete="off">
</div>
<div class="compose-field">
<label>Message</label>
<textarea id="compose-body" rows="6" placeholder="Your message…"></textarea>
</div>
<div class="compose-field">
<label>Attachments</label>
<div class="file-attach-area" onclick="document.getElementById('file-input').click()">
<div>📎 Click to attach files (max 48KB total)</div>
<input type="file" id="file-input" multiple onchange="handleAttachFiles(this)" style="display:none">
</div>
<div class="attachments-list" id="attachments-list"></div>
<div style="margin-top:6px;font-size:12px;color:var(--text-muted);" id="attach-size-info"></div>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-secondary btn-sm" onclick="closeCompose()">Cancel</button>
<button class="btn btn-sm" id="sendbtn" onclick="doSend()">📨 Send public mail</button>
</div>
</div>
</div>
<div class="toast-container" id="toast-container"></div>
</div>
<script>
"use strict";
// public.mail name-only build: no passwords, no encryption, no local-only mailbox fallback.
// Primary backend: JsonStorage API, because it supports browser CORS and no-auth JSON create/update.
const JSONSTORAGE_BASE = 'https://api.jsonstorage.net/v1/json';
const LEGACY_JSONBLOB_BASE = 'https://jsonblob.com/api/jsonBlob';
// JsonStorage now requires an apiKey for create/update. This public demo key is from
// JsonStorage's own JSFiddle example. It is not a mail password and provides no privacy.
const DEFAULT_JSONSTORAGE_API_KEY = '8969a471-87b7-4758-9f34-b090d396d9bb';
const STATE_KEY = 'publicmail_name_state_v5_jsonstorage_apikey';
const NETWORK_KEY = 'publicmail_network_id_v5_jsonstorage_apikey';
const API_KEY_STORAGE_KEY = 'publicmail_backend_key_v5_jsonstorage_apikey';
const CACHE_PREFIX = 'publicmail_cache_v5_';
const MAX_ATTACH_SIZE = 48 * 1024; // keep JSONStorage items under its small free-item limit after base64 overhead
const FETCH_TIMEOUT_MS = 12000;
let activeBackendName = 'jsonstorage.net';
let state = null; // { dirId, userName, nameKey, blobId }
let directory = null; // { v, type, created, users: { nameKey: { name, blobId, created, updated } } }
let lastNetworkError = '';
let inbox = [];
let sent = [];
let currentFolder = 'inbox';
let currentReadIdx = null;
let attachments = [];
const $ = id => document.getElementById(id);
function toast(msg, type = '') {
const container = $('toast-container');
const el = document.createElement('div');
el.className = 'toast ' + type;
el.textContent = msg;
container.appendChild(el);
requestAnimationFrame(() => el.classList.add('show'));
setTimeout(() => {
el.classList.remove('show');
setTimeout(() => el.remove(), 300);
}, 4200);
}
function setStatus(msg) {
const el = $('sync-status');
if (el) el.textContent = msg ? msg : '';
}
function escHtml(s) {
if (s === null || s === undefined) return '';
return String(s).replace(/[&<>'"]/g, c => ({
'&': '&', '<': '<', '>': '>', "'": ''', '"': '"'
}[c] || c));
}
function canonName(name) {
return String(name || '')
.trim()
.toLowerCase()
.replace(/\s+/g, '-')
.replace(/[^a-z0-9._-]/g, '')
.replace(/[-_.]{2,}/g, '-')
.replace(/^[-_.]+|[-_.]+$/g, '')
.slice(0, 40);
}
function prettyName(raw, key) {
const cleaned = String(raw || '').trim().replace(/\s+/g, ' ').slice(0, 40);
return cleaned || key;
}
function nowIso() {
return new Date().toISOString();
}
function makeDirectory() {
return {
v: 4,
type: 'public.mail.directory',
backend: 'jsonstorage.net',
created: nowIso(),
updated: nowIso(),
users: {}
};
}
function makeMailbox(name, key) {
return {
v: 4,
type: 'public.mail.mailbox',
backend: 'jsonstorage.net',
owner: name,
ownerKey: key,
created: nowIso(),
updated: nowIso(),
messages: []
};
}
function cloneJson(value) {
return JSON.parse(JSON.stringify(value));
}
function getBackendApiKey() {
const input = $('backend-key');
const typed = input ? input.value.trim() : '';
const saved = localStorage.getItem(API_KEY_STORAGE_KEY) || '';
const key = typed || saved || DEFAULT_JSONSTORAGE_API_KEY;
if (input && !input.value) input.value = key;
if (key) localStorage.setItem(API_KEY_STORAGE_KEY, key);
return key;
}
function saveBackendApiKey() {
const key = getBackendApiKey();
if (!key) throw new Error('JsonStorage backend edit key is required for create/update');
localStorage.setItem(API_KEY_STORAGE_KEY, key);
return key;
}
function jsonStorageEditUrl(url, extra = {}) {
const key = saveBackendApiKey();
const u = new URL(url);
u.searchParams.set('apiKey', key);
Object.keys(extra || {}).forEach(k => {
if (extra[k] !== undefined && extra[k] !== null && String(extra[k]) !== '') u.searchParams.set(k, String(extra[k]));
});
return u.toString();
}
function makeStorageItemName(kind) {
return 'public-mail-' + kind + '-' + Date.now().toString(36) + '-' + Math.random().toString(36).slice(2, 8);
}
function findJsonBlobId(text) {
const x = String(text || '').trim();
const uuid = x.match(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i);
if (uuid) return uuid[0];
const numeric = x.match(/(?:jsonBlob\/|jsonblob\.com\/|^)([0-9]{8,})(?:\b|$)/i);
if (numeric) return numeric[1];
return '';
}
function parseStorageRef(ref) {
let x = String(ref || '').trim();
if (!x) return null;
x = x.replace(/^jsonstorage:/i, '').trim();
const full = x.match(/^https:\/\/api\.jsonstorage\.net\/v1\/json\/([^\/?#]+)\/([^\/?#]+)/i);
if (full) {
return {
kind: 'jsonstorage',
url: JSONSTORAGE_BASE + '/' + encodeURIComponent(decodeURIComponent(full[1])) + '/' + encodeURIComponent(decodeURIComponent(full[2])),
label: decodeURIComponent(full[1]) + '/' + decodeURIComponent(full[2])
};
}
const path = x.match(/^([A-Za-z0-9_-]{4,})\/([A-Za-z0-9_-]{4,})$/);
if (path) {
return {
kind: 'jsonstorage',
url: JSONSTORAGE_BASE + '/' + encodeURIComponent(path[1]) + '/' + encodeURIComponent(path[2]),
label: path[1] + '/' + path[2]
};
}
const legacy = findJsonBlobId(x);
if (legacy) {
return {
kind: 'jsonblob-legacy',
url: LEGACY_JSONBLOB_BASE + '/' + encodeURIComponent(legacy),
label: legacy
};
}
return null;
}
function normalizeStorageRef(ref) {
const parsed = parseStorageRef(ref);
return parsed ? parsed.url : '';
}
function isStorageRef(ref) {
return !!parseStorageRef(ref);
}
function describeNetworkError(e) {
const raw = e && e.name === 'AbortError' ? 'request timed out' : (e && e.message ? e.message : String(e));
if (/failed to fetch|networkerror|load failed|cors|cross-origin/i.test(raw)) {
return 'online storage unavailable: the browser blocked the request or the network is offline';
}
return raw;
}
function setStorageMode(mode, note = '') {
if (mode === 'online') setStatus(note || ('online · ' + activeBackendName));
else setStatus(note || 'error');
}
async function fetchWithTimeout(url, options = {}) {
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
try {
return await fetch(url, {
mode: 'cors',
credentials: 'omit',
cache: 'no-store',
redirect: 'follow',
...options,
signal: controller.signal
});
} finally {
clearTimeout(timer);
}
}
async function readJsonResponse(response) {
const text = await response.text();
if (!text) return null;
try { return JSON.parse(text); }
catch (e) { throw new Error('Backend returned non-JSON data'); }
}
async function onlineCreateJsonStorage(data) {
activeBackendName = 'jsonstorage.net';
const itemName = makeStorageItemName(data && data.type === 'public.mail.directory' ? 'directory' : 'mailbox');
const r = await fetchWithTimeout(jsonStorageEditUrl(JSONSTORAGE_BASE, { name: itemName }), {
method: 'POST',
headers: { 'Content-Type': 'application/json; charset=utf-8', 'Accept': 'application/json,text/plain,*/*' },
body: JSON.stringify(data)
});
if (!r.ok) {
const body = await r.text().catch(() => '');
throw new Error('Create failed: HTTP ' + r.status + (body ? ' — ' + body.slice(0, 160) : ''));
}
const body = await readJsonResponse(r).catch(() => null);
const uri = body && (body.uri || body.url || body.location);
const parsed = parseStorageRef(uri || r.headers.get('Location') || '');
if (!parsed || parsed.kind !== 'jsonstorage') throw new Error('Storage created data but did not return a usable JSONStorage URI');
setStorageMode('online');
return parsed.url;
}
async function onlineGetJsonStorage(url) {
activeBackendName = 'jsonstorage.net';
const r = await fetchWithTimeout(url, { headers: { 'Accept': 'application/json,text/plain,*/*' } });
if (r.status === 404) return null;
if (!r.ok) throw new Error('Fetch failed: HTTP ' + r.status);
const data = await readJsonResponse(r);
setStorageMode('online');
return data;
}
async function onlinePutJsonStorage(url, data) {
activeBackendName = 'jsonstorage.net';
const r = await fetchWithTimeout(jsonStorageEditUrl(url), {
method: 'PUT',
headers: { 'Content-Type': 'application/json; charset=utf-8', 'Accept': 'application/json,text/plain,*/*' },
body: JSON.stringify(data)
});
if (!r.ok) {
const body = await r.text().catch(() => '');
throw new Error('Update failed: HTTP ' + r.status + (body ? ' — ' + body.slice(0, 160) : ''));
}
// JsonStorage returns an acknowledgement; keep the object we just wrote as the source of truth.
await r.text().catch(() => '');
setStorageMode('online');
return data;
}
async function legacyJsonBlobGet(url) {
activeBackendName = 'JSONBlob legacy';
const r = await fetchWithTimeout(url, { headers: { 'Accept': 'application/json,text/plain,*/*' } });
if (r.status === 404) return null;
if (!r.ok) throw new Error('Legacy JSONBlob fetch failed: HTTP ' + r.status);
const data = await readJsonResponse(r);
setStorageMode('online');
return data;
}
async function legacyJsonBlobPut(url, data) {
activeBackendName = 'JSONBlob legacy';
const r = await fetchWithTimeout(url, {
method: 'PUT',
headers: { 'Content-Type': 'application/json', 'Accept': 'application/json,text/plain,*/*' },
body: JSON.stringify(data)
});
if (!r.ok) throw new Error('Legacy JSONBlob update failed: HTTP ' + r.status);
setStorageMode('online');
return data;
}
async function blobCreate(data) {
try {
return await onlineCreateJsonStorage(data);
} catch (e) {
lastNetworkError = describeNetworkError(e);
setStatus('error · ' + lastNetworkError);
throw new Error(lastNetworkError);
}
}
async function blobGet(ref) {
const parsed = parseStorageRef(ref);
if (!parsed) throw new Error('Invalid network/mailbox ID');
try {
if (parsed.kind === 'jsonstorage') return await onlineGetJsonStorage(parsed.url);
return await legacyJsonBlobGet(parsed.url);
} catch (e) {
lastNetworkError = describeNetworkError(e);
setStatus('error · ' + lastNetworkError);
throw new Error(lastNetworkError);
}
}
async function blobPut(ref, data) {
const parsed = parseStorageRef(ref);
if (!parsed) throw new Error('Invalid network/mailbox ID');
try {
if (parsed.kind === 'jsonstorage') return await onlinePutJsonStorage(parsed.url, data);
return await legacyJsonBlobPut(parsed.url, data);
} catch (e) {
lastNetworkError = describeNetworkError(e);
setStatus('error · ' + lastNetworkError);
throw new Error(lastNetworkError);
}
}
function savedNetworkId() {
return localStorage.getItem(NETWORK_KEY) || '';
}
function saveState() {
if (state) {
localStorage.setItem(STATE_KEY, JSON.stringify(state));
localStorage.setItem(NETWORK_KEY, state.dirId);
}
updateSavedNetworkNote();
}
function loadState() {
try {
const raw = localStorage.getItem(STATE_KEY);
if (!raw) return false;
const s = JSON.parse(raw);
if (!s || !s.dirId || !s.nameKey || !s.blobId) return false;