aboutsummaryrefslogtreecommitdiff
path: root/html/mail.html
blob: 732040064b1805d3fd92b00544444983315fd2e5 (plain)
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
<html>

<head>
    <title>mail</title>
    <script src="/src/bundle.js"></script>
</head>

<body onload="load()">
    <script>
        const sid = makeid(20)
        window.sid = sid
        function makeid(length) {
            var result = '';
            var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
            var charactersLength = characters.length;
            for (var i = 0; i < length; i++) {
                result += characters.charAt(Math.floor(Math.random() *
                    charactersLength));
            }
            return result;
        }
        function sendenc(location, content) {
            var promise = new Promise((resolve, reject) => {
                var xhr = new XMLHttpRequest();
                xhr.open("POST", window.location.href + location, true);
                xhr.setRequestHeader('Content-Type', 'application/json');
                xhr.onreadystatechange = function () {
                    if (xhr.readyState == XMLHttpRequest.DONE) {
                        console.log('recived')
                        pub = new TextDecoder().decode(kekw.decrypt(JSON.parse(xhr.responseText).data));
                        console.log('decrypted')
                        resolve(pub)
                    }
                }
                let out = {}
                Object.assign(out, { json: true, enc: true, sid: sid }, { data: nodersa(pub, 'pkcs8-public').encrypt({ data: content, date: new Date() }, 'base64') })
                xhr.send(JSON.stringify(out))
            })
            return (promise)
        }
        function sendnoenc(location, content) {
            var promise = new Promise((resolve, reject) => {
                var xhr = new XMLHttpRequest();
                xhr.open("POST", window.location.origin + location, true);
                xhr.setRequestHeader('Content-Type', 'application/json');
                xhr.onreadystatechange = function () {
                    if (xhr.readyState == XMLHttpRequest.DONE) {
                        resolve(xhr.responseText);
                    }
                }
                let out = {}
                Object.assign(out, { json: true, enc: false }, content)
                xhr.send(JSON.stringify(out))
            })
            return (promise)
        }
        document.onkeypress = function (key) {
            key = key || window.event;
            if (key.key == "Enter") {
                submit()
            }
        };
        let emails = []
        function update() {
            //console.log('hi')
            sendenc('/get', { 'user': 'root', 'pass': 'password' }).then(res => {
                res = JSON.parse(res)
                console.log('parsed')
                emails = res.reverse()
            })
        }
        let mypriv, mypub, pub, kekw
        async function load() {

            kekw = await nodersa({ b: 512 })
            mypriv = await kekw.exportKey('pkcs1-private')
            mypub = await kekw.exportKey('pkcs8-public')
            pub = await sendnoenc('/pub.key', { sid: sid, pub: mypub })
            update()
            setInterval(() => {
                let ret = ''
                let evo = false

                for (let email of emails) {
                    let c = '#2C3333'
                    if (evo) {
                        c = '#395B64'
                    }
                    evo = !evo
                    ret += '<div style="color:#A5C9CA;border-radius:10px;max-width:50%;min-width:400px;padding:20px;background-color:' + c + ';">'
                    ret += '<tt><b><font size="4">sub:' + email.envelope.subject + '</font></b></br>frm:' + email.envelope.from[0].address + '</br><sub style="color:#E7F6F2;">' + email.envelope.date + '</sub></tt></br></div><div style="height:2px;"></div>'
                }

                document.getElementById('emails').innerHTML = ret
            }, 5000)
        }
        //<button onclick="update()">update mail</button>
    </script>
    <div id="emails"></div>
</body>


</html>