diff --git a/onionr/api.py b/onionr/api.py index 3b3cc7e3..6a53ef19 100755 --- a/onionr/api.py +++ b/onionr/api.py @@ -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/', methods=['POST', 'GET']) def pluginEndpoints(subpath=''): diff --git a/onionr/static-data/default-plugins/pms/main.py b/onionr/static-data/default-plugins/pms/main.py index 75480ce2..55cd9a7c 100755 --- a/onionr/static-data/default-plugins/pms/main.py +++ b/onionr/static-data/default-plugins/pms/main.py @@ -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 = '' diff --git a/onionr/static-data/default-plugins/pms/sentboxdb.py b/onionr/static-data/default-plugins/pms/sentboxdb.py index 2d6207e6..f00accb3 100755 --- a/onionr/static-data/default-plugins/pms/sentboxdb.py +++ b/onionr/static-data/default-plugins/pms/sentboxdb.py @@ -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 diff --git a/onionr/static-data/www/mail/index.html b/onionr/static-data/www/mail/index.html index 3ea92f1a..03b0b8ec 100755 --- a/onionr/static-data/www/mail/index.html +++ b/onionr/static-data/www/mail/index.html @@ -13,9 +13,9 @@
- - Onionr Mail ✉️
+ + Onionr Mail ✉️
Current Used Identity:


diff --git a/onionr/static-data/www/mail/mail.js b/onionr/static-data/www/mail/mail.js index 76fc9024..4513ce9b 100755 --- a/onionr/static-data/www/mail/mail.js +++ b/onionr/static-data/www/mail/mail.js @@ -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) diff --git a/onionr/static-data/www/shared/misc.js b/onionr/static-data/www/shared/misc.js index 03d2f3da..d4322887 100755 --- a/onionr/static-data/www/shared/misc.js +++ b/onionr/static-data/www/shared/misc.js @@ -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 . +*/ + webpass = document.location.hash.replace('#', '') nowebpass = false