2019-10-07 10:08:26 +02:00
|
|
|
"""Helper Inbox performs inbox messages related operations"""
|
2018-04-07 12:41:24 +02:00
|
|
|
|
2024-05-30 11:13:15 +02:00
|
|
|
import sqlite3
|
|
|
|
|
2017-02-08 13:41:56 +01:00
|
|
|
import queues
|
2019-10-07 16:17:40 +02:00
|
|
|
from helper_sql import sqlExecute, sqlQuery
|
2024-05-27 15:43:01 +02:00
|
|
|
from dbcompat import dbstr
|
2013-06-21 01:25:01 +02:00
|
|
|
|
2018-04-07 12:41:24 +02:00
|
|
|
|
2013-06-21 01:25:01 +02:00
|
|
|
def insert(t):
|
2019-10-07 10:08:26 +02:00
|
|
|
"""Perform an insert into the "inbox" table"""
|
2024-05-30 13:06:32 +02:00
|
|
|
u = [sqlite3.Binary(t[0]), dbstr(t[1]), dbstr(t[2]), dbstr(t[3]), dbstr(t[4]), dbstr(t[5]), dbstr(t[6]), t[7], t[8], sqlite3.Binary(t[9])]
|
2024-05-27 15:43:01 +02:00
|
|
|
sqlExecute('''INSERT INTO inbox VALUES (?,?,?,?,?,?,?,?,?,?)''', *u)
|
2018-04-07 12:41:24 +02:00
|
|
|
# shouldn't emit changedInboxUnread and displayNewInboxMessage
|
|
|
|
# at the same time
|
|
|
|
# queues.UISignalQueue.put(('changedInboxUnread', None))
|
|
|
|
|
|
|
|
|
2013-06-21 01:25:01 +02:00
|
|
|
def trash(msgid):
|
2019-10-07 16:17:40 +02:00
|
|
|
"""Mark a message in the `inbox` as `trash`"""
|
2024-05-30 11:13:15 +02:00
|
|
|
rowcount = sqlExecute('''UPDATE inbox SET folder='trash' WHERE msgid=?''', sqlite3.Binary(msgid))
|
|
|
|
if rowcount < 1:
|
|
|
|
sqlExecute('''UPDATE inbox SET folder='trash' WHERE msgid=CAST(? AS TEXT)''', msgid)
|
2018-04-07 12:41:24 +02:00
|
|
|
queues.UISignalQueue.put(('removeInboxRowByMsgid', msgid))
|
|
|
|
|
|
|
|
|
2022-07-07 17:47:40 +02:00
|
|
|
def delete(ack_data):
|
|
|
|
"""Permanent delete message from trash"""
|
2024-05-30 11:13:15 +02:00
|
|
|
rowcount = sqlExecute("DELETE FROM inbox WHERE msgid = ?", sqlite3.Binary(ack_data))
|
|
|
|
if rowcount < 1:
|
|
|
|
sqlExecute("DELETE FROM inbox WHERE msgid = CAST(? AS TEXT)", ack_data)
|
2022-07-07 17:47:40 +02:00
|
|
|
|
|
|
|
|
2021-11-30 15:16:18 +01:00
|
|
|
def undeleteMessage(msgid):
|
|
|
|
"""Undelte the message"""
|
2024-05-30 11:13:15 +02:00
|
|
|
rowcount = sqlExecute('''UPDATE inbox SET folder='inbox' WHERE msgid=?''', sqlite3.Binary(msgid))
|
|
|
|
if rowcount < 1:
|
|
|
|
sqlExecute('''UPDATE inbox SET folder='inbox' WHERE msgid=CAST(? AS TEXT)''', msgid)
|
2021-11-30 15:16:18 +01:00
|
|
|
|
|
|
|
|
2015-02-21 03:03:20 +01:00
|
|
|
def isMessageAlreadyInInbox(sigHash):
|
2019-10-07 16:17:40 +02:00
|
|
|
"""Check for previous instances of this message"""
|
2014-07-26 19:15:28 +02:00
|
|
|
queryReturn = sqlQuery(
|
2024-05-30 11:13:15 +02:00
|
|
|
'''SELECT COUNT(*) FROM inbox WHERE sighash=?''', sqlite3.Binary(sigHash))
|
|
|
|
if len(queryReturn) < 1:
|
|
|
|
queryReturn = sqlQuery(
|
|
|
|
'''SELECT COUNT(*) FROM inbox WHERE sighash=CAST(? AS TEXT)''', sigHash)
|
2017-02-08 13:41:56 +01:00
|
|
|
return queryReturn[0][0] != 0
|