change helper_sent.insert methods
This commit is contained in:
parent
0ec15d1d4d
commit
a9e9f25b5d
64
src/api.py
64
src/api.py
|
@ -1116,22 +1116,22 @@ class BMRPCDispatcher(object):
|
||||||
'bitmessagesettings', 'ackstealthlevel')
|
'bitmessagesettings', 'ackstealthlevel')
|
||||||
ackdata = genAckPayload(streamNumber, stealthLevel)
|
ackdata = genAckPayload(streamNumber, stealthLevel)
|
||||||
|
|
||||||
t = ('',
|
helper_sent.insert(
|
||||||
toAddress,
|
'',
|
||||||
toRipe,
|
toAddress,
|
||||||
fromAddress,
|
toRipe,
|
||||||
subject,
|
fromAddress,
|
||||||
message,
|
subject,
|
||||||
ackdata,
|
message,
|
||||||
int(time.time()), # sentTime (this won't change)
|
ackdata,
|
||||||
int(time.time()), # lastActionTime
|
int(time.time()), # sentTime (this won't change)
|
||||||
0,
|
int(time.time()), # lastActionTime
|
||||||
'msgqueued',
|
0,
|
||||||
0,
|
'msgqueued',
|
||||||
'sent',
|
0,
|
||||||
encodingType,
|
'sent',
|
||||||
TTL)
|
encodingType,
|
||||||
helper_sent.insert(t)
|
TTL)
|
||||||
|
|
||||||
toLabel = ''
|
toLabel = ''
|
||||||
queryreturn = sqlQuery(
|
queryreturn = sqlQuery(
|
||||||
|
@ -1176,22 +1176,22 @@ class BMRPCDispatcher(object):
|
||||||
toAddress = str_broadcast_subscribers
|
toAddress = str_broadcast_subscribers
|
||||||
ripe = ''
|
ripe = ''
|
||||||
|
|
||||||
t = ('',
|
helper_sent.insert(
|
||||||
toAddress,
|
'',
|
||||||
ripe,
|
toAddress,
|
||||||
fromAddress,
|
ripe,
|
||||||
subject,
|
fromAddress,
|
||||||
message,
|
subject,
|
||||||
ackdata,
|
message,
|
||||||
int(time.time()), # sentTime (this doesn't change)
|
ackdata,
|
||||||
int(time.time()), # lastActionTime
|
int(time.time()), # sentTime (this doesn't change)
|
||||||
0,
|
int(time.time()), # lastActionTime
|
||||||
'broadcastqueued',
|
0,
|
||||||
0,
|
'broadcastqueued',
|
||||||
'sent',
|
0,
|
||||||
encodingType,
|
'sent',
|
||||||
TTL)
|
encodingType,
|
||||||
helper_sent.insert(t)
|
TTL)
|
||||||
|
|
||||||
toLabel = str_broadcast_subscribers
|
toLabel = str_broadcast_subscribers
|
||||||
queues.UISignalQueue.put(('displayNewSentMessage', (
|
queues.UISignalQueue.put(('displayNewSentMessage', (
|
||||||
|
|
|
@ -968,7 +968,7 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
|
||||||
scrollbox(d, unicode("Because you are not currently connected to the network, "))
|
scrollbox(d, unicode("Because you are not currently connected to the network, "))
|
||||||
stealthLevel = BMConfigParser().safeGetInt('bitmessagesettings', 'ackstealthlevel')
|
stealthLevel = BMConfigParser().safeGetInt('bitmessagesettings', 'ackstealthlevel')
|
||||||
ackdata = genAckPayload(decodeAddress(addr)[2], stealthLevel)
|
ackdata = genAckPayload(decodeAddress(addr)[2], stealthLevel)
|
||||||
t = (
|
helper_sent.insert(
|
||||||
'',
|
'',
|
||||||
addr,
|
addr,
|
||||||
ripe,
|
ripe,
|
||||||
|
@ -985,7 +985,6 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
|
||||||
2, # encodingType
|
2, # encodingType
|
||||||
0
|
0
|
||||||
)
|
)
|
||||||
helper_sent.insert(t)
|
|
||||||
queues.workerQueue.put(("sendmessage", addr))
|
queues.workerQueue.put(("sendmessage", addr))
|
||||||
else: # Broadcast
|
else: # Broadcast
|
||||||
if recv == "":
|
if recv == "":
|
||||||
|
@ -996,7 +995,7 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
|
||||||
ackdata = genAckPayload(decodeAddress(addr)[2], 0)
|
ackdata = genAckPayload(decodeAddress(addr)[2], 0)
|
||||||
recv = BROADCAST_STR
|
recv = BROADCAST_STR
|
||||||
ripe = ""
|
ripe = ""
|
||||||
t = (
|
helper_sent.insert(
|
||||||
'',
|
'',
|
||||||
recv,
|
recv,
|
||||||
ripe,
|
ripe,
|
||||||
|
@ -1013,7 +1012,6 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
|
||||||
2, # encodingType
|
2, # encodingType
|
||||||
0
|
0
|
||||||
)
|
)
|
||||||
helper_sent.insert(t)
|
|
||||||
queues.workerQueue.put(('sendbroadcast', ''))
|
queues.workerQueue.put(('sendbroadcast', ''))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2166,7 +2166,7 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
stealthLevel = BMConfigParser().safeGetInt(
|
stealthLevel = BMConfigParser().safeGetInt(
|
||||||
'bitmessagesettings', 'ackstealthlevel')
|
'bitmessagesettings', 'ackstealthlevel')
|
||||||
ackdata = genAckPayload(streamNumber, stealthLevel)
|
ackdata = genAckPayload(streamNumber, stealthLevel)
|
||||||
t = (
|
helper_sent.insert(
|
||||||
'',
|
'',
|
||||||
toAddress,
|
toAddress,
|
||||||
ripe,
|
ripe,
|
||||||
|
@ -2183,7 +2183,6 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
encoding, # encodingtype
|
encoding, # encodingtype
|
||||||
0
|
0
|
||||||
)
|
)
|
||||||
helper_sent.insert(t)
|
|
||||||
toLabel = ''
|
toLabel = ''
|
||||||
queryreturn = sqlQuery('''select label from addressbook where address=?''',
|
queryreturn = sqlQuery('''select label from addressbook where address=?''',
|
||||||
toAddress)
|
toAddress)
|
||||||
|
@ -2221,23 +2220,23 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
ackdata = genAckPayload(streamNumber, 0)
|
ackdata = genAckPayload(streamNumber, 0)
|
||||||
toAddress = str_broadcast_subscribers
|
toAddress = str_broadcast_subscribers
|
||||||
ripe = ''
|
ripe = ''
|
||||||
t = ('', # msgid. We don't know what this will be until the POW is done.
|
helper_sent.insert(
|
||||||
toAddress,
|
'', # msgid. We don't know what this will be until the POW is done.
|
||||||
ripe,
|
toAddress,
|
||||||
fromAddress,
|
ripe,
|
||||||
subject,
|
fromAddress,
|
||||||
message,
|
subject,
|
||||||
ackdata,
|
message,
|
||||||
int(time.time()), # sentTime (this will never change)
|
ackdata,
|
||||||
int(time.time()), # lastActionTime
|
int(time.time()), # sentTime (this will never change)
|
||||||
0, # sleepTill time. This will get set when the POW gets done.
|
int(time.time()), # lastActionTime
|
||||||
'broadcastqueued',
|
0, # sleepTill time. This will get set when the POW gets done.
|
||||||
0, # retryNumber
|
'broadcastqueued',
|
||||||
'sent', # folder
|
0, # retryNumber
|
||||||
encoding, # encoding type
|
'sent', # folder
|
||||||
0
|
encoding, # encoding type
|
||||||
)
|
0
|
||||||
helper_sent.insert(t)
|
)
|
||||||
|
|
||||||
toLabel = str_broadcast_subscribers
|
toLabel = str_broadcast_subscribers
|
||||||
|
|
||||||
|
|
|
@ -755,22 +755,22 @@ class objectProcessor(threading.Thread):
|
||||||
# set the TTL for mailing list broadcasts. This is obviously
|
# set the TTL for mailing list broadcasts. This is obviously
|
||||||
# hard-coded.
|
# hard-coded.
|
||||||
TTL = 2 * 7 * 24 * 60 * 60 # 2 weeks
|
TTL = 2 * 7 * 24 * 60 * 60 # 2 weeks
|
||||||
t = ('',
|
helper_sent.insert(
|
||||||
toAddress,
|
'',
|
||||||
ripe,
|
toAddress,
|
||||||
fromAddress,
|
ripe,
|
||||||
subject,
|
fromAddress,
|
||||||
message,
|
subject,
|
||||||
ackdata,
|
message,
|
||||||
int(time.time()), # sentTime (this doesn't change)
|
ackdata,
|
||||||
int(time.time()), # lastActionTime
|
int(time.time()), # sentTime (this doesn't change)
|
||||||
0,
|
int(time.time()), # lastActionTime
|
||||||
'broadcastqueued',
|
0,
|
||||||
0,
|
'broadcastqueued',
|
||||||
'sent',
|
0,
|
||||||
messageEncodingType,
|
'sent',
|
||||||
TTL)
|
messageEncodingType,
|
||||||
helper_sent.insert(t)
|
TTL)
|
||||||
|
|
||||||
queues.UISignalQueue.put((
|
queues.UISignalQueue.put((
|
||||||
'displayNewSentMessage', (
|
'displayNewSentMessage', (
|
||||||
|
|
|
@ -10,38 +10,41 @@ from helper_ackPayload import genAckPayload
|
||||||
from helper_sql import sqlExecute
|
from helper_sql import sqlExecute
|
||||||
|
|
||||||
|
|
||||||
def insert(t, is_testcase=False):
|
# 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):
|
||||||
"""Perform an insert into the `sent` table"""
|
"""Perform an insert into the `sent` table"""
|
||||||
# pylint: disable=unused-variable
|
# pylint: disable=unused-variable
|
||||||
|
# pylint: disable-msg=too-many-locals
|
||||||
|
|
||||||
if '' in t or 0 in t:
|
msgid = msgid if msgid else uuid.uuid4().bytes
|
||||||
temp = list(t)
|
|
||||||
temp_dict = {
|
|
||||||
0: uuid.uuid4().bytes, # if msgid is empty the put uuid
|
|
||||||
7: int(time.time()), # sentTime
|
|
||||||
8: int(time.time()), # lastActionTime
|
|
||||||
9: 0, # sleeptill
|
|
||||||
10: 'msgqueued',
|
|
||||||
11: 0, # retryNumber
|
|
||||||
12: 'sent', # folder
|
|
||||||
13: 2, # encoding
|
|
||||||
14: BMConfigParser().getint('bitmessagesettings', 'ttl')
|
|
||||||
}
|
|
||||||
|
|
||||||
if not temp[2] or not temp[6]:
|
if not ripe or not ackdata:
|
||||||
status, addressVersionNumber, streamNumber, ripe = decodeAddress(temp[1])
|
new_status, addressVersionNumber, streamNumber, new_ripe = decodeAddress(toAddress)
|
||||||
if not temp[2]:
|
if not ripe:
|
||||||
temp_dict[2] = ripe
|
ripe = new_ripe
|
||||||
|
|
||||||
if not temp[6]:
|
if not ackdata:
|
||||||
stealthLevel = BMConfigParser().safeGetInt(
|
stealthLevel = BMConfigParser().safeGetInt(
|
||||||
'bitmessagesettings', 'ackstealthlevel')
|
'bitmessagesettings', 'ackstealthlevel')
|
||||||
ackdata = genAckPayload(streamNumber, stealthLevel)
|
new_ackdata = genAckPayload(streamNumber, stealthLevel)
|
||||||
temp_dict[6] = ackdata
|
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)
|
||||||
|
|
||||||
for i in dict(enumerate(temp)):
|
|
||||||
if not temp[i]:
|
|
||||||
temp[i] = temp_dict[i]
|
|
||||||
t = tuple(temp)
|
|
||||||
sqlExecute('''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''', *t)
|
sqlExecute('''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''', *t)
|
||||||
return t if is_testcase else None
|
return t if is_testcase else None
|
||||||
|
|
|
@ -247,7 +247,8 @@ class TestCore(unittest.TestCase):
|
||||||
message = 'test message'
|
message = 'test message'
|
||||||
subject = 'test subject'
|
subject = 'test subject'
|
||||||
encoding = 2
|
encoding = 2
|
||||||
t = ('', # msgid
|
result = helper_sent.insert(
|
||||||
|
'', # msgid
|
||||||
toAddress,
|
toAddress,
|
||||||
'', # ripe
|
'', # ripe
|
||||||
fromAddress,
|
fromAddress,
|
||||||
|
@ -261,17 +262,18 @@ class TestCore(unittest.TestCase):
|
||||||
0,
|
0,
|
||||||
'sent',
|
'sent',
|
||||||
encoding,
|
encoding,
|
||||||
0)
|
0,
|
||||||
result = helper_sent.insert(t, True)
|
True)
|
||||||
self.assertNotEqual(result[0], '')
|
self.assertNotEqual(result[0], '')
|
||||||
|
|
||||||
def test_defalut_insert_values(self):
|
def test_defalut_insert_values(self):
|
||||||
"""Test missing values in insert method for message sending"""
|
"""Test missing values in insert method for message sending"""
|
||||||
fromAddress = 'BM-2cTrmD22fLRrumi3pPLg1ELJ6PdAaTRTdfg'
|
fromAddress = 'BM-2cTrmD22fLRrumi3pPLg1ELJ6PdAaTRTdfg'
|
||||||
toAddress = 'BM-2cVWtdUzPwF7UNGDrZftWuHWgjdfkj89fdf'
|
toAddress = 'BM-2cVWtdUzPwF7UNGDrZftWuHWiJ6xxBpiSP' # autoresponder address
|
||||||
message = 'test message'
|
message = 'test message'
|
||||||
subject = 'test subject'
|
subject = 'test subject'
|
||||||
t = ('', # msgid
|
result = helper_sent.insert(
|
||||||
|
'', # msgid
|
||||||
toAddress,
|
toAddress,
|
||||||
'', # ripe
|
'', # ripe
|
||||||
fromAddress,
|
fromAddress,
|
||||||
|
@ -285,8 +287,7 @@ class TestCore(unittest.TestCase):
|
||||||
'', # retryNumber
|
'', # retryNumber
|
||||||
'', # folder
|
'', # folder
|
||||||
'', # encoding
|
'', # encoding
|
||||||
'') # ttl
|
'', True)
|
||||||
result = helper_sent.insert(t, True)
|
|
||||||
for index in [0, 2, 6, 7, 8, 9, 10, 11, 12, 13, 14]:
|
for index in [0, 2, 6, 7, 8, 9, 10, 11, 12, 13, 14]:
|
||||||
self.assertNotEqual(result[index], '')
|
self.assertNotEqual(result[index], '')
|
||||||
|
|
||||||
|
|
Reference in New Issue
Block a user