2019-10-07 15:58:12 +02:00
|
|
|
"""
|
2019-10-09 15:27:51 +02:00
|
|
|
Insert values into sent table
|
2019-10-07 15:58:12 +02:00
|
|
|
"""
|
|
|
|
|
2020-11-05 21:32:13 +01:00
|
|
|
import time
|
2020-09-15 13:18:24 +02:00
|
|
|
import uuid
|
2020-11-05 21:32:13 +01:00
|
|
|
from addresses import decodeAddress
|
2022-01-28 13:55:23 +01:00
|
|
|
from bmconfigparser import config
|
2020-11-05 21:32:13 +01:00
|
|
|
from helper_ackPayload import genAckPayload
|
2019-12-23 10:49:03 +01:00
|
|
|
from helper_sql import sqlExecute
|
|
|
|
|
2019-10-09 15:27:51 +02:00
|
|
|
|
2020-11-09 16:15:28 +01:00
|
|
|
# pylint: disable=too-many-arguments
|
2020-11-16 14:20:28 +01:00
|
|
|
def insert(msgid=None, toAddress='[Broadcast subscribers]', fromAddress=None, subject=None,
|
|
|
|
message=None, status='msgqueued', ripe=None, ackdata=None, sentTime=None,
|
|
|
|
lastActionTime=None, sleeptill=0, retryNumber=0, encoding=2, ttl=None, folder='sent'):
|
2019-10-09 15:27:51 +02:00
|
|
|
"""Perform an insert into the `sent` table"""
|
2020-11-07 11:41:29 +01:00
|
|
|
# pylint: disable=unused-variable
|
2020-11-09 16:15:28 +01:00
|
|
|
# pylint: disable-msg=too-many-locals
|
|
|
|
|
2020-11-17 20:36:05 +01:00
|
|
|
valid_addr = True
|
2020-11-09 16:15:28 +01:00
|
|
|
if not ripe or not ackdata:
|
2020-11-16 14:20:28 +01:00
|
|
|
addr = fromAddress if toAddress == '[Broadcast subscribers]' else toAddress
|
|
|
|
new_status, addressVersionNumber, streamNumber, new_ripe = decodeAddress(addr)
|
2020-11-17 20:36:05 +01:00
|
|
|
valid_addr = True if new_status == 'success' else False
|
2020-11-09 16:15:28 +01:00
|
|
|
if not ripe:
|
|
|
|
ripe = new_ripe
|
|
|
|
|
|
|
|
if not ackdata:
|
2022-01-28 13:55:23 +01:00
|
|
|
stealthLevel = config.safeGetInt(
|
2020-11-09 16:15:28 +01:00
|
|
|
'bitmessagesettings', 'ackstealthlevel')
|
|
|
|
new_ackdata = genAckPayload(streamNumber, stealthLevel)
|
|
|
|
ackdata = new_ackdata
|
2020-11-17 20:36:05 +01:00
|
|
|
if valid_addr:
|
|
|
|
msgid = msgid if msgid else uuid.uuid4().bytes
|
|
|
|
sentTime = sentTime if sentTime else int(time.time()) # sentTime (this doesn't change)
|
|
|
|
lastActionTime = lastActionTime if lastActionTime else int(time.time())
|
2020-11-09 16:15:28 +01:00
|
|
|
|
2022-01-28 13:55:23 +01:00
|
|
|
ttl = ttl if ttl else config.getint('bitmessagesettings', 'ttl')
|
2020-11-09 16:15:28 +01:00
|
|
|
|
2020-11-17 20:36:05 +01:00
|
|
|
t = (msgid, toAddress, ripe, fromAddress, subject, message, ackdata,
|
|
|
|
sentTime, lastActionTime, sleeptill, status, retryNumber, folder,
|
|
|
|
encoding, ttl)
|
2020-11-07 11:41:29 +01:00
|
|
|
|
2020-11-17 20:36:05 +01:00
|
|
|
sqlExecute('''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''', *t)
|
|
|
|
return ackdata
|
|
|
|
else:
|
|
|
|
return None
|