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
|
2020-09-15 13:18:24 +02:00
|
|
|
from bmconfigparser import BMConfigParser
|
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
|
|
|
|
def insert(msgid, toAddress, ripe, fromAddress, subject, message, ackdata,
|
|
|
|
sentTime, lastActionTime, sleeptill=0, status='msgqueued',
|
|
|
|
retryNumber=0, folder='sent', encoding=2, ttl=0, is_testcase=False):
|
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
|
|
|
|
|
|
|
|
msgid = msgid if msgid else uuid.uuid4().bytes
|
|
|
|
|
|
|
|
if not ripe or not ackdata:
|
|
|
|
new_status, addressVersionNumber, streamNumber, new_ripe = decodeAddress(toAddress)
|
|
|
|
if not ripe:
|
|
|
|
ripe = new_ripe
|
|
|
|
|
|
|
|
if not ackdata:
|
|
|
|
stealthLevel = BMConfigParser().safeGetInt(
|
|
|
|
'bitmessagesettings', 'ackstealthlevel')
|
|
|
|
new_ackdata = genAckPayload(streamNumber, stealthLevel)
|
|
|
|
ackdata = new_ackdata
|
|
|
|
|
|
|
|
sentTime = sentTime if sentTime else int(time.time())
|
|
|
|
lastActionTime = lastActionTime if lastActionTime else int(time.time())
|
|
|
|
|
|
|
|
sleeptill = sleeptill if sleeptill else 0
|
|
|
|
status = status if status else 'msgqueued'
|
|
|
|
retryNumber = retryNumber if retryNumber else 0
|
|
|
|
folder = folder if folder else 'sent'
|
|
|
|
encoding = encoding if encoding else 2
|
|
|
|
|
|
|
|
ttl = ttl if ttl else BMConfigParser().getint('bitmessagesettings', 'ttl')
|
|
|
|
|
|
|
|
t = (msgid, toAddress, ripe, fromAddress, subject, message, ackdata,
|
|
|
|
sentTime, lastActionTime, sleeptill, status, retryNumber, folder,
|
|
|
|
encoding, ttl)
|
2020-11-07 11:41:29 +01:00
|
|
|
|
2015-03-09 07:35:32 +01:00
|
|
|
sqlExecute('''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''', *t)
|
2020-11-05 21:32:13 +01:00
|
|
|
return t if is_testcase else None
|