work on sentbox
parent
f8867fb08e
commit
f270d3c522
|
@ -101,7 +101,6 @@ class DataPOW:
|
||||||
endTime = math.floor(time.time())
|
endTime = math.floor(time.time())
|
||||||
if self.reporting:
|
if self.reporting:
|
||||||
logger.debug('Found token after %s seconds: %s' % (endTime - startTime, token), timestamp=True)
|
logger.debug('Found token after %s seconds: %s' % (endTime - startTime, token), timestamp=True)
|
||||||
logger.debug('Random value was: %s' % base64.b64encode(rand).decode())
|
|
||||||
self.result = (token, rand)
|
self.result = (token, rand)
|
||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
|
@ -201,7 +200,6 @@ class POW:
|
||||||
endTime = math.floor(time.time())
|
endTime = math.floor(time.time())
|
||||||
if self.reporting:
|
if self.reporting:
|
||||||
logger.debug('Found token after %s seconds: %s' % (endTime - startTime, token), timestamp=True)
|
logger.debug('Found token after %s seconds: %s' % (endTime - startTime, token), timestamp=True)
|
||||||
logger.debug('Random value was: %s' % base64.b64encode(rand).decode())
|
|
||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
self.hashing = False
|
self.hashing = False
|
||||||
|
|
|
@ -22,9 +22,13 @@
|
||||||
import logger, config, threading, time, readline, datetime
|
import logger, config, threading, time, readline, datetime
|
||||||
from onionrblockapi import Block
|
from onionrblockapi import Block
|
||||||
import onionrexceptions, onionrusers
|
import onionrexceptions, onionrusers
|
||||||
import locale
|
import locale, sys, os
|
||||||
|
|
||||||
locale.setlocale(locale.LC_ALL, '')
|
locale.setlocale(locale.LC_ALL, '')
|
||||||
|
|
||||||
|
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
|
||||||
|
import sentboxdb # import after path insert
|
||||||
|
|
||||||
plugin_name = 'pms'
|
plugin_name = 'pms'
|
||||||
PLUGIN_VERSION = '0.0.1'
|
PLUGIN_VERSION = '0.0.1'
|
||||||
|
|
||||||
|
@ -60,6 +64,9 @@ class OnionrMail:
|
||||||
#self.dataFolder = pluginapi.get_data_folder()
|
#self.dataFolder = pluginapi.get_data_folder()
|
||||||
self.strings = MailStrings(self)
|
self.strings = MailStrings(self)
|
||||||
|
|
||||||
|
self.sentboxTools = sentboxdb.SentBox(self.myCore)
|
||||||
|
self.sentboxList = []
|
||||||
|
self.sentMessages = {}
|
||||||
return
|
return
|
||||||
|
|
||||||
def inbox(self):
|
def inbox(self):
|
||||||
|
@ -139,27 +146,35 @@ class OnionrMail:
|
||||||
'''
|
'''
|
||||||
entering = True
|
entering = True
|
||||||
while entering:
|
while entering:
|
||||||
print('''1. List Sent Messages
|
self.getSentList()
|
||||||
2. Read sent message
|
print('Enter block number or -q to return')
|
||||||
3. Delete Sent Message
|
|
||||||
4. Main Menu
|
|
||||||
''')
|
|
||||||
try:
|
try:
|
||||||
choice = logger.readline('>').lower()
|
choice = input('>')
|
||||||
except (KeyboardInterrupt, EOFError):
|
except (EOFError, KeyboardInterrupt) as e:
|
||||||
entering = False
|
entering = False
|
||||||
else:
|
else:
|
||||||
if choice in ('1', 'list'):
|
if choice == '-q':
|
||||||
print(getSentList())
|
entering = False
|
||||||
elif choice in ('2', 'read'):
|
|
||||||
pass
|
|
||||||
else:
|
else:
|
||||||
print('Not implemented')
|
try:
|
||||||
|
self.sentboxList[int(choice) - 1]
|
||||||
|
except IndexError:
|
||||||
|
print('Invalid block')
|
||||||
|
else:
|
||||||
|
logger.info('Sent to: ' + self.sentMessages[self.sentboxList[int(choice) - 1]][1])
|
||||||
|
# Print ansi escaped sent message
|
||||||
|
print(self.myCore._utils.escapeAnsi(self.sentMessages[self.sentboxList[int(choice) - 1]][0]))
|
||||||
|
input('Press enter to continue...')
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def getSentList(self):
|
def getSentList(self):
|
||||||
return ""
|
count = 1
|
||||||
|
for i in self.sentboxTools.listSent():
|
||||||
|
self.sentboxList.append(i['hash'])
|
||||||
|
self.sentMessages[i['hash']] = (i['message'], i['peer'])
|
||||||
|
print('%s. %s - %s - %s' % (count, i['hash'], i['peer'][:12], i['date']))
|
||||||
|
count += 1
|
||||||
|
|
||||||
def draftMessage(self):
|
def draftMessage(self):
|
||||||
message = ''
|
message = ''
|
||||||
|
@ -197,8 +212,8 @@ class OnionrMail:
|
||||||
|
|
||||||
print('Inserting encrypted message as Onionr block....')
|
print('Inserting encrypted message as Onionr block....')
|
||||||
|
|
||||||
self.myCore.insertBlock(message, header='pm', encryptType='asym', asymPeer=recip, sign=True)
|
blockID = self.myCore.insertBlock(message, header='pm', encryptType='asym', asymPeer=recip, sign=True)
|
||||||
|
self.sentboxTools.addToSent(blockID, recip, message)
|
||||||
def menu(self):
|
def menu(self):
|
||||||
choice = ''
|
choice = ''
|
||||||
while True:
|
while True:
|
||||||
|
|
|
@ -20,24 +20,27 @@
|
||||||
import sqlite3, os
|
import sqlite3, os
|
||||||
import core
|
import core
|
||||||
class SentBox:
|
class SentBox:
|
||||||
def __init__(self, core):
|
def __init__(self, mycore):
|
||||||
assert isinstance(core, core.Core)
|
assert isinstance(mycore, core.Core)
|
||||||
self.dbLocation = core.dataDir + 'sentbox.db'
|
self.dbLocation = mycore.dataDir + 'sentbox.db'
|
||||||
if not os.path.exists(self.dbLocation):
|
if not os.path.exists(self.dbLocation):
|
||||||
self.createDB()
|
self.createDB()
|
||||||
self.conn = sqlite3.connect(self.dbLocation)
|
self.conn = sqlite3.connect(self.dbLocation)
|
||||||
self.cursor = self.conn.cursor()
|
self.cursor = self.conn.cursor()
|
||||||
|
self.core = mycore
|
||||||
return
|
return
|
||||||
|
|
||||||
def createDB(self):
|
def createDB(self):
|
||||||
self.cursor.execute('''CREATE TABLE sent(
|
conn = sqlite3.connect(self.dbLocation)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute('''CREATE TABLE sent(
|
||||||
hash id not null,
|
hash id not null,
|
||||||
peer text not null,
|
peer text not null,
|
||||||
message text not null,
|
message text not null,
|
||||||
date int not null
|
date int not null
|
||||||
);
|
);
|
||||||
''')
|
''')
|
||||||
self.conn.commit()
|
conn.commit()
|
||||||
return
|
return
|
||||||
|
|
||||||
def listSent(self):
|
def listSent(self):
|
||||||
|
@ -46,8 +49,14 @@ class SentBox:
|
||||||
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], 'date': entry[3]})
|
||||||
return retData
|
return retData
|
||||||
|
|
||||||
def addToSent(self, blockID):
|
def addToSent(self, blockID, peer, message):
|
||||||
|
args = (blockID, peer, message, self.core._utils.getEpoch())
|
||||||
|
self.cursor.execute('INSERT INTO sent VALUES(?, ?, ?, ?)', args)
|
||||||
|
self.conn.commit()
|
||||||
return
|
return
|
||||||
|
|
||||||
def removeSent(self, blockID):
|
def removeSent(self, blockID):
|
||||||
|
args = (blockID,)
|
||||||
|
self.cursor.execute('DELETE FROM sent where hash=?', args)
|
||||||
|
self.conn.commit()
|
||||||
return
|
return
|
Loading…
Reference in New Issue