mail fixes

This commit is contained in:
Kevin Froman 2019-02-11 16:36:43 -06:00
parent 1d32b3daa1
commit b09dae276c
6 changed files with 35 additions and 31 deletions

View File

@ -27,6 +27,7 @@ from onionrblockapi import Block
import onionrutils, onionrexceptions, onionrcrypto, blockimporter, onionrevents as events, logger, config, onionr
class FDSafeHandler(WSGIHandler):
'''Our WSGI handler. Doesn't do much non-default except timeouts'''
def handle(self):
timeout = Timeout(60, exception=Exception)
timeout.start()
@ -37,24 +38,6 @@ class FDSafeHandler(WSGIHandler):
except Timeout as ex:
raise
def guessMime(path):
'''
Guesses the mime type of a file from the input filename
'''
mimetypes = {
'html' : 'text/html',
'js' : 'application/javascript',
'css' : 'text/css',
'png' : 'image/png',
'jpg' : 'image/jpeg'
}
for mimetype in mimetypes:
if path.endswith('.%s' % mimetype):
return mimetypes[mimetype]
return 'text/plain'
def setBindIP(filePath):
'''Set a random localhost IP to a specified file (intended for private or public API localhost IPs)'''
hostOctets = [str(127), str(random.randint(0x02, 0xFF)), str(random.randint(0x02, 0xFF)), str(random.randint(0x02, 0xFF))]
@ -65,6 +48,7 @@ def setBindIP(filePath):
try:
s.bind((data, 0))
except OSError:
# if mac/non-bindable, show warning and default to 127.0.0.1
logger.warn('Your platform appears to not support random local host addresses 127.x.x.x. Falling back to 127.0.0.1.')
data = '127.0.0.1'
s.close()
@ -486,7 +470,8 @@ class API:
meta = json.loads(bData['meta'])
except KeyError:
pass
return Response(self._core.insertBlock(message, header=bType, encryptType=encryptType, sign=sign, asymPeer=to, meta=meta))
threading.Thread(target=self._core.insertBlock, args=(message,), kwargs={'header': bType, 'encryptType': encryptType, 'sign':sign, 'asymPeer': to, 'meta': meta}).start()
return Response('success')
@app.route('/apipoints/<path:subpath>', methods=['POST', 'GET'])
def pluginEndpoints(subpath=''):

View File

@ -194,9 +194,9 @@ class OnionrMail:
self.sentMessages = {}
for i in self.sentboxTools.listSent():
self.sentboxList.append(i['hash'])
self.sentMessages[i['hash']] = (self.myCore._utils.bytesToStr(i['message']), i['peer'])
self.sentMessages[i['hash']] = (self.myCore._utils.bytesToStr(i['message']), i['peer'], i['subject'])
if display:
logger.info('%s. %s - %s - %s' % (count, i['hash'], i['peer'][:12], i['date']))
logger.info('%s. %s - %s - (%s) - %s' % (count, i['hash'], i['peer'][:12], i['subject'], i['date']))
count += 1
return json.dumps(self.sentMessages)
@ -247,7 +247,6 @@ class OnionrMail:
logger.info('Inserting encrypted message as Onionr block....')
blockID = self.myCore.insertBlock(message, header='pm', encryptType='asym', asymPeer=recip, sign=self.doSigs, meta={'subject': subject})
self.sentboxTools.addToSent(blockID, recip, message)
def toggle_signing(self):
self.doSigs = not self.doSigs
@ -291,8 +290,8 @@ class OnionrMail:
def on_insertblock(api, data={}):
sentboxTools = sentboxdb.SentBox(api.get_core())
meta = json.dumps(data['meta'])
sentboxTools.addToSent(data['hash'], data['peer'], data['content'])
meta = json.loads(data['meta'])
sentboxTools.addToSent(data['hash'], data['peer'], data['content'], meta['subject'])
def on_pluginrequest(api, data=None):
resp = ''

View File

@ -37,6 +37,7 @@ class SentBox:
hash id not null,
peer text not null,
message text not null,
subject text not null,
date int not null
);
''')
@ -46,12 +47,12 @@ class SentBox:
def listSent(self):
retData = []
for entry in self.cursor.execute('SELECT * FROM sent;'):
retData.append({'hash': entry[0], 'peer': entry[1], 'message': entry[2], 'date': entry[3]})
retData.append({'hash': entry[0], 'peer': entry[1], 'message': entry[2], 'subject': entry[3], 'date': entry[4]})
return retData
def addToSent(self, blockID, peer, message):
args = (blockID, peer, message, self.core._utils.getEpoch())
self.cursor.execute('INSERT INTO sent VALUES(?, ?, ?, ?)', args)
def addToSent(self, blockID, peer, message, subject=''):
args = (blockID, peer, message, subject, self.core._utils.getEpoch())
self.cursor.execute('INSERT INTO sent VALUES(?, ?, ?, ?, ?)', args)
self.conn.commit()
return

View File

@ -13,9 +13,9 @@
<body>
<div id="infoOverlay" class='overlay'>
</div>
<img class='logo' src='/shared/onionr-icon.png' alt='onionr logo'>
<span class='logoText'>Onionr Mail ✉️</span>
<div class='content'>
<img class='logo' src='/shared/onionr-icon.png' alt='onionr logo'>
<span class='logoText'>Onionr Mail ✉️</span>
<div>Current Used Identity: <input class='myPub' type='text' readonly> <button class='refresh'>Refresh Page</button></div>
<br><br>
<div class="btn-group" id='tabBtns'>

View File

@ -154,7 +154,7 @@ function getSentbox(){
var preview = document.createElement('span')
toEl.readOnly = true
toEl.value = resp[keys[i]][1]
preview.innerText = resp[keys[i]][0].split('\n')[0];
preview.innerText = '(' + resp[keys[i]][2] + ')'
entry.appendChild(toLabel)
entry.appendChild(toEl)
entry.appendChild(preview)

View File

@ -1,3 +1,22 @@
/*
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/>.
*/
webpass = document.location.hash.replace('#', '')
nowebpass = false