2020-01-29 03:39:01 +00:00
|
|
|
"""
|
2019-06-20 07:59:32 +00:00
|
|
|
Onionr - Private P2P Communication
|
2018-11-11 02:10:58 +00:00
|
|
|
|
|
|
|
This file handles the sentbox for the mail plugin
|
2020-01-29 03:39:01 +00:00
|
|
|
"""
|
|
|
|
import sqlite3
|
|
|
|
import os
|
|
|
|
from onionrutils import epoch
|
|
|
|
from utils import identifyhome, reconstructhash
|
|
|
|
"""
|
2018-11-11 02:10:58 +00:00
|
|
|
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/>.
|
2020-01-29 03:39:01 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
2018-11-11 02:10:58 +00:00
|
|
|
class SentBox:
|
2019-07-21 00:29:08 +00:00
|
|
|
def __init__(self):
|
|
|
|
self.dbLocation = identifyhome.identify_home() + '/sentbox.db'
|
2018-11-11 02:10:58 +00:00
|
|
|
if not os.path.exists(self.dbLocation):
|
|
|
|
self.createDB()
|
|
|
|
return
|
2020-01-29 03:39:01 +00:00
|
|
|
|
2019-03-03 06:26:55 +00:00
|
|
|
def connect(self):
|
|
|
|
self.conn = sqlite3.connect(self.dbLocation)
|
|
|
|
self.cursor = self.conn.cursor()
|
|
|
|
|
|
|
|
def close(self):
|
|
|
|
self.conn.close()
|
2018-12-09 17:29:39 +00:00
|
|
|
|
2018-11-11 02:10:58 +00:00
|
|
|
def createDB(self):
|
|
|
|
conn = sqlite3.connect(self.dbLocation)
|
|
|
|
cursor = conn.cursor()
|
2020-01-29 03:39:01 +00:00
|
|
|
cursor.execute("""CREATE TABLE sent(
|
2018-11-11 02:10:58 +00:00
|
|
|
hash id not null,
|
|
|
|
peer text not null,
|
|
|
|
message text not null,
|
2019-02-11 22:36:43 +00:00
|
|
|
subject text not null,
|
2018-11-11 02:10:58 +00:00
|
|
|
date int not null
|
|
|
|
);
|
2020-01-29 03:39:01 +00:00
|
|
|
""")
|
2018-11-11 02:10:58 +00:00
|
|
|
conn.commit()
|
2019-03-03 06:26:55 +00:00
|
|
|
conn.close()
|
2018-11-11 02:10:58 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
def listSent(self):
|
2019-03-03 06:26:55 +00:00
|
|
|
self.connect()
|
2018-11-11 02:10:58 +00:00
|
|
|
retData = []
|
|
|
|
for entry in self.cursor.execute('SELECT * FROM sent;'):
|
2019-02-11 22:36:43 +00:00
|
|
|
retData.append({'hash': entry[0], 'peer': entry[1], 'message': entry[2], 'subject': entry[3], 'date': entry[4]})
|
2019-03-03 06:26:55 +00:00
|
|
|
self.close()
|
2018-11-11 02:10:58 +00:00
|
|
|
return retData
|
2018-12-09 17:29:39 +00:00
|
|
|
|
2019-02-11 22:36:43 +00:00
|
|
|
def addToSent(self, blockID, peer, message, subject=''):
|
2019-07-29 18:05:27 +00:00
|
|
|
blockID = reconstructhash.deconstruct_hash(blockID)
|
2019-03-03 06:26:55 +00:00
|
|
|
self.connect()
|
2019-06-25 23:07:35 +00:00
|
|
|
args = (blockID, peer, message, subject, epoch.get_epoch())
|
2019-02-11 22:36:43 +00:00
|
|
|
self.cursor.execute('INSERT INTO sent VALUES(?, ?, ?, ?, ?)', args)
|
2018-11-11 02:10:58 +00:00
|
|
|
self.conn.commit()
|
2019-03-03 06:26:55 +00:00
|
|
|
self.close()
|
2018-11-11 02:10:58 +00:00
|
|
|
return
|
2018-12-09 17:29:39 +00:00
|
|
|
|
2018-11-11 02:10:58 +00:00
|
|
|
def removeSent(self, blockID):
|
2019-07-29 18:05:27 +00:00
|
|
|
blockID = reconstructhash.deconstruct_hash(blockID)
|
2019-03-03 06:26:55 +00:00
|
|
|
self.connect()
|
2018-11-11 02:10:58 +00:00
|
|
|
args = (blockID,)
|
|
|
|
self.cursor.execute('DELETE FROM sent where hash=?', args)
|
|
|
|
self.conn.commit()
|
2019-03-03 06:26:55 +00:00
|
|
|
self.close()
|
2018-12-09 17:29:39 +00:00
|
|
|
return
|