2019-02-04 00:31:03 +00:00
|
|
|
/*
|
|
|
|
Onionr - P2P Anonymous Storage Network
|
|
|
|
|
|
|
|
This file handles the mail interface
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2019-02-01 06:38:12 +00:00
|
|
|
pms = ''
|
2019-02-08 18:53:28 +00:00
|
|
|
sentbox = ''
|
2019-02-01 06:38:12 +00:00
|
|
|
threadPart = document.getElementById('threads')
|
2019-02-03 18:19:50 +00:00
|
|
|
threadPlaceholder = document.getElementById('threadPlaceholder')
|
2019-02-04 00:31:03 +00:00
|
|
|
tabBtns = document.getElementById('tabBtns')
|
2019-02-04 23:48:21 +00:00
|
|
|
threadContent = {}
|
2019-02-04 00:31:03 +00:00
|
|
|
myPub = httpGet('/getActivePubkey')
|
|
|
|
|
2019-02-07 01:03:31 +00:00
|
|
|
function openThread(bHash, sender, date, sigBool){
|
2019-02-04 23:48:21 +00:00
|
|
|
var messageDisplay = document.getElementById('threadDisplay')
|
2019-02-07 01:03:31 +00:00
|
|
|
var blockContent = httpGet('/getblockbody/' + bHash)
|
2019-02-05 06:29:06 +00:00
|
|
|
document.getElementById('fromUser').value = sender
|
|
|
|
messageDisplay.innerText = blockContent
|
2019-02-07 01:03:31 +00:00
|
|
|
var sigEl = document.getElementById('sigValid')
|
|
|
|
var sigMsg = 'signature'
|
|
|
|
|
|
|
|
if (sigBool){
|
|
|
|
sigMsg = 'Good ' + sigMsg
|
|
|
|
sigEl.classList.remove('danger')
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
sigMsg = 'Bad/no ' + sigMsg + ' (message could be fake)'
|
|
|
|
sigEl.classList.add('danger')
|
|
|
|
}
|
|
|
|
sigEl.innerText = sigMsg
|
2019-02-04 23:48:21 +00:00
|
|
|
overlay('messageDisplay')
|
|
|
|
}
|
|
|
|
|
2019-02-04 00:31:03 +00:00
|
|
|
function setActiveTab(tabName){
|
|
|
|
threadPart.innerHTML = ""
|
|
|
|
switch(tabName){
|
|
|
|
case 'inbox':
|
2019-02-08 18:53:28 +00:00
|
|
|
getInbox()
|
2019-02-04 00:31:03 +00:00
|
|
|
break
|
|
|
|
case 'sentbox':
|
2019-02-08 18:53:28 +00:00
|
|
|
getSentbox()
|
2019-02-04 00:31:03 +00:00
|
|
|
break
|
|
|
|
case 'send message':
|
2019-02-09 06:32:11 +00:00
|
|
|
overlay('sendMessage')
|
2019-02-04 00:31:03 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-04 23:48:21 +00:00
|
|
|
function loadInboxEntrys(bHash){
|
|
|
|
fetch('/getblockheader/' + bHash, {
|
|
|
|
headers: {
|
|
|
|
"token": webpass
|
|
|
|
}})
|
|
|
|
.then((resp) => resp.json()) // Transform the data into json
|
|
|
|
.then(function(resp) {
|
2019-02-09 06:32:11 +00:00
|
|
|
//console.log(resp)
|
2019-02-04 23:48:21 +00:00
|
|
|
var entry = document.createElement('div')
|
|
|
|
var bHashDisplay = document.createElement('span')
|
|
|
|
var senderInput = document.createElement('input')
|
|
|
|
var subjectLine = document.createElement('span')
|
|
|
|
var dateStr = document.createElement('span')
|
2019-02-05 23:20:36 +00:00
|
|
|
var validSig = document.createElement('span')
|
2019-02-04 23:48:21 +00:00
|
|
|
var humanDate = new Date(0)
|
|
|
|
var metadata = resp['metadata']
|
|
|
|
humanDate.setUTCSeconds(resp['meta']['time'])
|
2019-02-10 02:21:36 +00:00
|
|
|
if (resp['meta']['signer'] != ''){
|
|
|
|
senderInput.value = httpGet('/getHumanReadable/' + resp['meta']['signer'])
|
|
|
|
}
|
2019-02-05 23:20:36 +00:00
|
|
|
if (resp['meta']['validSig']){
|
|
|
|
validSig.innerText = 'Signature Validity: Good'
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
validSig.innerText = 'Signature Validity: Bad'
|
2019-02-09 06:32:11 +00:00
|
|
|
validSig.style.color = 'red'
|
2019-02-05 23:20:36 +00:00
|
|
|
}
|
|
|
|
if (senderInput.value == ''){
|
|
|
|
senderInput.value = 'Anonymous'
|
|
|
|
}
|
2019-02-04 23:48:21 +00:00
|
|
|
bHashDisplay.innerText = bHash.substring(0, 10)
|
2019-02-09 06:32:11 +00:00
|
|
|
entry.setAttribute('hash', bHash)
|
2019-02-04 23:48:21 +00:00
|
|
|
senderInput.readOnly = true
|
|
|
|
dateStr.innerText = humanDate.toString()
|
|
|
|
if (metadata['subject'] === undefined || metadata['subject'] === null) {
|
|
|
|
subjectLine.innerText = '()'
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
subjectLine.innerText = '(' + metadata['subject'] + ')'
|
|
|
|
}
|
|
|
|
//entry.innerHTML = 'sender ' + resp['meta']['signer'] + ' - ' + resp['meta']['time']
|
|
|
|
threadPart.appendChild(entry)
|
|
|
|
entry.appendChild(bHashDisplay)
|
|
|
|
entry.appendChild(senderInput)
|
2019-02-05 23:20:36 +00:00
|
|
|
entry.appendChild(validSig)
|
2019-02-04 23:48:21 +00:00
|
|
|
entry.appendChild(subjectLine)
|
|
|
|
entry.appendChild(dateStr)
|
|
|
|
entry.classList.add('threadEntry')
|
|
|
|
|
|
|
|
entry.onclick = function(){
|
2019-02-07 01:03:31 +00:00
|
|
|
openThread(entry.getAttribute('hash'), senderInput.value, dateStr.innerText, resp['meta']['validSig'])
|
2019-02-04 23:48:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}.bind(bHash))
|
|
|
|
}
|
|
|
|
|
2019-02-01 06:38:12 +00:00
|
|
|
function getInbox(){
|
2019-02-03 18:19:50 +00:00
|
|
|
var showed = false
|
2019-02-04 23:48:21 +00:00
|
|
|
var requested = ''
|
2019-02-01 06:38:12 +00:00
|
|
|
for(var i = 0; i < pms.length; i++) {
|
2019-02-03 18:19:50 +00:00
|
|
|
if (pms[i].trim().length == 0){
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
threadPlaceholder.style.display = 'none'
|
|
|
|
showed = true
|
|
|
|
}
|
2019-02-04 23:48:21 +00:00
|
|
|
loadInboxEntrys(pms[i])
|
2019-02-01 06:38:12 +00:00
|
|
|
}
|
2019-02-03 18:19:50 +00:00
|
|
|
if (! showed){
|
|
|
|
threadPlaceholder.style.display = 'block'
|
|
|
|
}
|
2019-02-08 18:53:28 +00:00
|
|
|
}
|
2019-02-01 06:38:12 +00:00
|
|
|
|
2019-02-08 18:53:28 +00:00
|
|
|
function getSentbox(){
|
|
|
|
fetch('/apipoints/mail/sentbox', {
|
|
|
|
headers: {
|
|
|
|
"token": webpass
|
|
|
|
}})
|
2019-02-09 06:32:11 +00:00
|
|
|
.then((resp) => resp.json()) // Transform the data into json
|
|
|
|
.then(function(resp) {
|
|
|
|
var keys = [];
|
|
|
|
var entry = document.createElement('div')
|
|
|
|
var entryUsed;
|
|
|
|
for(var k in resp) keys.push(k);
|
|
|
|
for (var i = 0; i < keys.length; i++){
|
|
|
|
var entry = document.createElement('div')
|
|
|
|
var obj = resp[i];
|
|
|
|
var toLabel = document.createElement('span')
|
|
|
|
toLabel.innerText = 'To: '
|
|
|
|
var toEl = document.createElement('input')
|
|
|
|
var preview = document.createElement('span')
|
|
|
|
toEl.readOnly = true
|
|
|
|
toEl.value = resp[keys[i]][1]
|
|
|
|
preview.innerText = resp[keys[i]][0].split('\n')[0];
|
|
|
|
entry.appendChild(toLabel)
|
|
|
|
entry.appendChild(toEl)
|
|
|
|
entry.appendChild(preview)
|
|
|
|
entryUsed = resp[keys[i]]
|
|
|
|
entry.onclick = function(){
|
|
|
|
console.log(resp)
|
|
|
|
showSentboxWindow(toEl.value, entryUsed[0])
|
|
|
|
}
|
|
|
|
threadPart.appendChild(entry)
|
|
|
|
}
|
|
|
|
threadPart.appendChild(entry)
|
|
|
|
}.bind(threadPart))
|
|
|
|
}
|
|
|
|
|
|
|
|
function showSentboxWindow(to, content){
|
|
|
|
document.getElementById('toID').value = to
|
|
|
|
document.getElementById('sentboxDisplayText').innerText = content
|
|
|
|
overlay('sentboxDisplay')
|
2019-02-01 06:38:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fetch('/getblocksbytype/pm', {
|
|
|
|
headers: {
|
|
|
|
"token": webpass
|
|
|
|
}})
|
|
|
|
.then((resp) => resp.text()) // Transform the data into json
|
|
|
|
.then(function(data) {
|
|
|
|
pms = data.split(',')
|
2019-02-04 00:31:03 +00:00
|
|
|
setActiveTab('inbox')
|
2019-02-01 06:38:12 +00:00
|
|
|
})
|
|
|
|
|
2019-02-04 00:31:03 +00:00
|
|
|
tabBtns.onclick = function(event){
|
|
|
|
var children = tabBtns.children
|
|
|
|
for (var i = 0; i < children.length; i++) {
|
|
|
|
var btn = children[i]
|
|
|
|
btn.classList.remove('activeTab')
|
|
|
|
}
|
|
|
|
event.target.classList.add('activeTab')
|
|
|
|
setActiveTab(event.target.innerText.toLowerCase())
|
|
|
|
}
|
|
|
|
|
|
|
|
var idStrings = document.getElementsByClassName('myPub')
|
|
|
|
var myHumanReadable = httpGet('/getHumanReadable/' + myPub)
|
|
|
|
for (var i = 0; i < idStrings.length; i++){
|
|
|
|
if (idStrings[i].tagName.toLowerCase() == 'input'){
|
|
|
|
idStrings[i].value = myHumanReadable
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
idStrings[i].innerText = myHumanReadable
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0; i < document.getElementsByClassName('refresh').length; i++){
|
|
|
|
document.getElementsByClassName('refresh')[i].style.float = 'right'
|
2019-02-05 06:29:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0; i < document.getElementsByClassName('closeOverlay').length; i++){
|
|
|
|
document.getElementsByClassName('closeOverlay')[i].onclick = function(e){
|
|
|
|
document.getElementById(e.target.getAttribute('overlay')).style.visibility = 'hidden'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|