Onionr/onionr/static-data/default-plugins/pms/sentboxdb.py
Kevin Froman c7e06205b7 OnionrUtils fully removed (but not fully bug free)
flow now uses daemon thread for displaying output
2019-06-25 18:07:35 -05:00

77 lines
2.4 KiB
Python
Executable File

'''
Onionr - Private P2P Communication
This file handles the sentbox for the mail plugin
'''
'''
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/>.
'''
import sqlite3, os
import core
from onionrutils import epoch
class SentBox:
def __init__(self, mycore):
assert isinstance(mycore, core.Core)
self.dbLocation = mycore.dataDir + 'sentbox.db'
if not os.path.exists(self.dbLocation):
self.createDB()
self.core = mycore
return
def connect(self):
self.conn = sqlite3.connect(self.dbLocation)
self.cursor = self.conn.cursor()
def close(self):
self.conn.close()
def createDB(self):
conn = sqlite3.connect(self.dbLocation)
cursor = conn.cursor()
cursor.execute('''CREATE TABLE sent(
hash id not null,
peer text not null,
message text not null,
subject text not null,
date int not null
);
''')
conn.commit()
conn.close()
return
def listSent(self):
self.connect()
retData = []
for entry in self.cursor.execute('SELECT * FROM sent;'):
retData.append({'hash': entry[0], 'peer': entry[1], 'message': entry[2], 'subject': entry[3], 'date': entry[4]})
self.close()
return retData
def addToSent(self, blockID, peer, message, subject=''):
self.connect()
args = (blockID, peer, message, subject, epoch.get_epoch())
self.cursor.execute('INSERT INTO sent VALUES(?, ?, ?, ?, ?)', args)
self.conn.commit()
self.close()
return
def removeSent(self, blockID):
self.connect()
args = (blockID,)
self.cursor.execute('DELETE FROM sent where hash=?', args)
self.conn.commit()
self.close()
return