Merge pull request #43 from jaicis/py3convert
Solved message not receiving issue and solved address generation pub…
This commit is contained in:
commit
64bb14f7ef
|
@ -153,10 +153,12 @@ class Inbox(Screen):
|
|||
self.set_inboxCount(state.inbox_count)
|
||||
for mail in self.queryreturn:
|
||||
# third_text = mail[3].replace('\n', ' ')
|
||||
subject = mail[3].decode() if isinstance(mail[3],bytes) else mail[3]
|
||||
body = mail[5].decode() if isinstance(mail[5],bytes) else mail[5]
|
||||
data.append({
|
||||
'text': mail[4].strip(),
|
||||
'secondary_text': mail[5][:50] + '........' if len(
|
||||
mail[5]) >= 50 else (mail[5] + ',' + mail[3].replace(
|
||||
'secondary_text': body[:50] + '........' if len(
|
||||
body) >= 50 else (body + ',' + subject.replace(
|
||||
'\n', ''))[0:50] + '........',
|
||||
'msgid': mail[1], 'received': mail[6]})
|
||||
self.has_refreshed = True
|
||||
|
@ -239,10 +241,12 @@ class Inbox(Screen):
|
|||
self.inboxDataQuery('toaddress', where, what, total_message, 5)
|
||||
for mail in self.queryreturn:
|
||||
# third_text = mail[3].replace('\n', ' ')
|
||||
subject = mail[3].decode() if isinstance(mail[3],bytes) else mail[3]
|
||||
body = mail[5].decode() if isinstance(mail[5],bytes) else mail[5]
|
||||
data.append({
|
||||
'text': mail[4].strip(),
|
||||
'secondary_text': mail[5][:50] + '........' if len(
|
||||
mail[5]) >= 50 else (mail[5] + ',' + mail[3].replace(
|
||||
'secondary_text': body[:50] + '........' if len(
|
||||
body) >= 50 else (body + ',' +subject.replace(
|
||||
'\n', ''))[0:50] + '........',
|
||||
'msgid': mail[1]})
|
||||
self.set_mdList(data)
|
||||
|
@ -1233,16 +1237,17 @@ class Trash(Screen):
|
|||
"""This method is used to create the mdlist"""
|
||||
total_trash_msg = len(self.ids.ml.children)
|
||||
for item in self.trash_messages:
|
||||
subject = item[2].decode() if isinstance(item[2],bytes) else item[2]
|
||||
body = item[3].decode() if isinstance(item[3],bytes) else item[3]
|
||||
meny = TwoLineAvatarIconListItem(
|
||||
text=item[1],
|
||||
secondary_text=item[2][:50] + '........' if len(
|
||||
item[2]) >= 50 else (item[2] + ',' + item[3].replace(
|
||||
subject) >= 50 else (subject + ',' + body.replace(
|
||||
'\n', ''))[0:50] + '........',
|
||||
theme_text_color='Custom',
|
||||
text_color=NavigateApp().theme_cls.primary_color)
|
||||
img_latter = './images/text_images/{}.png'.format(
|
||||
item[2][0].upper() if (item[2][0].upper() >= 'A' and item[
|
||||
2][0].upper() <= 'Z') else '!')
|
||||
subject[0].upper() if (subject[0].upper() >= 'A' and subject[0].upper() <= 'Z') else '!')
|
||||
meny.add_widget(AvatarSampleWidget(source=img_latter))
|
||||
meny.add_widget(AddTimeWidget(item[7]))
|
||||
carousel = Carousel(direction='right')
|
||||
|
@ -2021,11 +2026,14 @@ class MailDetail(Screen):
|
|||
|
||||
def assign_mail_details(self, data):
|
||||
"""Assigning mail details"""
|
||||
subject = data[0][2].decode() if isinstance(data[0][2],bytes) else data[0][2]
|
||||
body = data[0][3].decode() if isinstance(data[0][2],bytes) else data[0][3]
|
||||
self.to_addr = data[0][0]
|
||||
self.from_addr = data[0][1]
|
||||
self.subject = data[0][2].upper(
|
||||
) if data[0][2].upper() else '(no subject)'
|
||||
self.message = data[0][3]
|
||||
|
||||
self.subject = subject.upper(
|
||||
) if subject.upper() else '(no subject)'
|
||||
self.message = body
|
||||
if len(data[0]) == 7:
|
||||
self.status = data[0][4]
|
||||
self.time_tag = ShowTimeHistoy(data[0][4]) if state.detailPageType == 'inbox' else ShowTimeHistoy(data[0][6])
|
||||
|
@ -2519,17 +2527,19 @@ class Allmails(Screen):
|
|||
"""This method is used to create mdList for allmaills"""
|
||||
data_exist = len(self.ids.ml.children)
|
||||
for item in self.all_mails:
|
||||
body = item[3].decode() if isinstance(item[3],bytes) else item[3]
|
||||
subject = item[2].decode() if isinstance(item[2],bytes) else item[2]
|
||||
meny = TwoLineAvatarIconListItem(
|
||||
text=item[1],
|
||||
secondary_text=item[2][:50] + '........' if len(
|
||||
item[2]) >= 50 else (
|
||||
item[2] + ',' + item[3].replace(
|
||||
secondary_text=body[:50] + '........' if len(
|
||||
body) >= 50 else (
|
||||
body + ',' + subject.replace(
|
||||
'\n', ''))[0:50] + '........',
|
||||
theme_text_color='Custom',
|
||||
text_color=NavigateApp().theme_cls.primary_color)
|
||||
meny.add_widget(AvatarSampleWidget(
|
||||
source='./images/text_images/{}.png'.format(
|
||||
avatarImageFirstLetter(item[2].strip()))))
|
||||
avatarImageFirstLetter(body.strip()))))
|
||||
meny.bind(on_press=partial(
|
||||
self.mail_detail, item[5], item[4]))
|
||||
meny.add_widget(AddTimeWidget(item[7]))
|
||||
|
|
|
@ -479,16 +479,15 @@ class objectProcessor(threading.Thread):
|
|||
|
||||
# This is not an acknowledgement bound for me. See if it is a message
|
||||
# bound for me by trying to decrypt it with my private keys.
|
||||
|
||||
for key, cryptorObject in sorted(
|
||||
shared.myECCryptorObjects.items(),
|
||||
key=lambda x: random.random()):
|
||||
try:
|
||||
# continue decryption attempts to avoid timing attacks
|
||||
if initialDecryptionSuccessful:
|
||||
cryptorObject.decrypt(data[readPosition:])
|
||||
cryptorObject.decrypt(bytes(data[readPosition:]))
|
||||
else:
|
||||
decryptedData = cryptorObject.decrypt(data[readPosition:])
|
||||
decryptedData = cryptorObject.decrypt(bytes(data[readPosition:]))
|
||||
# This is the RIPE hash of my pubkeys. We need this
|
||||
# below to compare to the destination_ripe included
|
||||
# in the encrypted data.
|
||||
|
@ -536,9 +535,9 @@ class objectProcessor(threading.Thread):
|
|||
return
|
||||
readPosition += sendersStreamNumberLength
|
||||
readPosition += 4
|
||||
pubSigningKey = '\x04' + decryptedData[readPosition:readPosition + 64]
|
||||
pubSigningKey = '\x04'.encode() + decryptedData[readPosition:readPosition + 64]
|
||||
readPosition += 64
|
||||
pubEncryptionKey = '\x04' + decryptedData[readPosition:readPosition + 64]
|
||||
pubEncryptionKey = '\x04'.encode() + decryptedData[readPosition:readPosition + 64]
|
||||
readPosition += 64
|
||||
if sendersAddressVersionNumber >= 3:
|
||||
requiredAverageProofOfWorkNonceTrialsPerByte, varintLength = \
|
||||
|
@ -589,7 +588,7 @@ class objectProcessor(threading.Thread):
|
|||
readPosition += signatureLengthLength
|
||||
signature = decryptedData[
|
||||
readPosition:readPosition + signatureLength]
|
||||
signedData = data[8:20] + encodeVarint(1) + encodeVarint(
|
||||
signedData = bytes(data[8:20]) + encodeVarint(1) + encodeVarint(
|
||||
streamNumberAsClaimedByMsg
|
||||
) + decryptedData[:positionOfBottomOfAckData]
|
||||
|
||||
|
@ -635,7 +634,6 @@ class objectProcessor(threading.Thread):
|
|||
# pubkey in order to send a message. If we are, it will do the POW
|
||||
# and send it.
|
||||
self.possibleNewPubkey(fromAddress)
|
||||
|
||||
# If this message is bound for one of my version 3 addresses (or
|
||||
# higher), then we must check to make sure it meets our demanded
|
||||
# proof of work requirement. If this is bound for one of my chan
|
||||
|
@ -648,10 +646,10 @@ class objectProcessor(threading.Thread):
|
|||
# If I'm not friendly with this person:
|
||||
if not shared.isAddressInMyAddressBookSubscriptionsListOrWhitelist(
|
||||
fromAddress):
|
||||
requiredNonceTrialsPerByte = BMConfigParser().getint(
|
||||
toAddress, 'noncetrialsperbyte')
|
||||
requiredPayloadLengthExtraBytes = BMConfigParser().getint(
|
||||
toAddress, 'payloadlengthextrabytes')
|
||||
requiredNonceTrialsPerByte = int(BMConfigParser().get(
|
||||
toAddress, 'noncetrialsperbyte'))
|
||||
requiredPayloadLengthExtraBytes = int(BMConfigParser().get(
|
||||
toAddress, 'payloadlengthextrabytes'))
|
||||
if not protocol.isProofOfWorkSufficient(
|
||||
data, requiredNonceTrialsPerByte,
|
||||
requiredPayloadLengthExtraBytes):
|
||||
|
@ -684,7 +682,6 @@ class objectProcessor(threading.Thread):
|
|||
toLabel = BMConfigParser().get(toAddress, 'label')
|
||||
if toLabel == '':
|
||||
toLabel = toAddress
|
||||
|
||||
try:
|
||||
decodedMessage = helper_msgcoding.MsgDecode(
|
||||
messageEncodingType, message)
|
||||
|
@ -1121,8 +1118,8 @@ class objectProcessor(threading.Thread):
|
|||
if checksum != hashlib.sha512(payload).digest()[0:4]:
|
||||
logger.info('ackdata checksum wrong. Not sending ackdata.')
|
||||
return False
|
||||
command = command.rstrip('\x00')
|
||||
if command != 'object':
|
||||
command = command.rstrip('\x00'.encode())
|
||||
if command != 'object'.encode():
|
||||
return False
|
||||
return True
|
||||
|
||||
|
|
|
@ -396,7 +396,7 @@ class singleWorker(StoppableThread):
|
|||
TTL = int(28 * 24 * 60 * 60 + helper_random.randomrandrange(-300, 300))
|
||||
embeddedTime = int(time.time() + TTL)
|
||||
payload = pack('>Q', (embeddedTime))
|
||||
payload += '\x00\x00\x00\x01' # object type: pubkey
|
||||
payload += '\x00\x00\x00\x01'.encode() # object type: pubkey
|
||||
payload += encodeVarint(addressVersionNumber) # Address version number
|
||||
payload += encodeVarint(streamNumber)
|
||||
dataToEncrypt = protocol.getBitfield(myAddress)
|
||||
|
@ -415,10 +415,10 @@ class singleWorker(StoppableThread):
|
|||
|
||||
dataToEncrypt += pubSigningKey + pubEncryptionKey
|
||||
|
||||
dataToEncrypt += encodeVarint(BMConfigParser().getint(
|
||||
myAddress, 'noncetrialsperbyte'))
|
||||
dataToEncrypt += encodeVarint(BMConfigParser().getint(
|
||||
myAddress, 'payloadlengthextrabytes'))
|
||||
dataToEncrypt += encodeVarint(int(BMConfigParser().get(
|
||||
myAddress, 'noncetrialsperbyte')))
|
||||
dataToEncrypt += encodeVarint(int(BMConfigParser().get(
|
||||
myAddress, 'payloadlengthextrabytes')))
|
||||
|
||||
# When we encrypt, we'll use a hash of the data
|
||||
# contained in an address as a decryption key. This way
|
||||
|
@ -449,7 +449,7 @@ class singleWorker(StoppableThread):
|
|||
|
||||
inventoryHash = calculateInventoryHash(payload)
|
||||
objectType = 1
|
||||
Inventory()[inventoryHash] = (
|
||||
Inventory()._realInventory[inventoryHash] = (
|
||||
objectType, streamNumber, payload, embeddedTime,
|
||||
doubleHashOfAddressData[32:]
|
||||
)
|
||||
|
|
|
@ -99,14 +99,14 @@ class MsgDecode(object):
|
|||
def decodeExtended(self, data):
|
||||
"""Handle extended encoding"""
|
||||
dc = zlib.decompressobj()
|
||||
tmp = ""
|
||||
tmp = bytes()
|
||||
while len(tmp) <= BMConfigParser().safeGetInt("zlib", "maxsize"):
|
||||
try:
|
||||
got = dc.decompress(
|
||||
data, BMConfigParser().safeGetInt("zlib", "maxsize") +
|
||||
1 - len(tmp))
|
||||
# EOF
|
||||
if got == "":
|
||||
if got == bytes():
|
||||
break
|
||||
tmp += got
|
||||
data = dc.unconsumed_tail
|
||||
|
@ -128,7 +128,6 @@ class MsgDecode(object):
|
|||
except KeyError:
|
||||
logger.error("Message type missing")
|
||||
raise MsgDecodeException("Message type missing")
|
||||
|
||||
msgObj = messagetypes.constructObject(tmp)
|
||||
if msgObj is None:
|
||||
raise MsgDecodeException("Malformed message")
|
||||
|
@ -142,7 +141,7 @@ class MsgDecode(object):
|
|||
|
||||
def decodeSimple(self, data):
|
||||
"""Handle simple encoding"""
|
||||
bodyPositionIndex = string.find(data, '\nBody:')
|
||||
bodyPositionIndex = bytes.find(data, '\nBody:'.encode())
|
||||
if bodyPositionIndex > 1:
|
||||
subject = data[8:bodyPositionIndex]
|
||||
# Only save and show the first 500 characters of the subject.
|
||||
|
|
|
@ -14,13 +14,17 @@ class Message(MsgBase):
|
|||
"""Decode a message"""
|
||||
# UTF-8 and variable type validator
|
||||
if isinstance(data["subject"], str):
|
||||
self.subject = unicode(data["subject"], 'utf-8', 'replace')
|
||||
# Unicode is depreciated
|
||||
self.subject =data["subject"]
|
||||
else:
|
||||
self.subject = unicode(str(data["subject"]), 'utf-8', 'replace')
|
||||
# Unicode is depreciated
|
||||
self.subject = str(data["subject"])
|
||||
if isinstance(data["body"], str):
|
||||
self.body = unicode(data["body"], 'utf-8', 'replace')
|
||||
# Unicode is depreciated
|
||||
self.body = data["body"]
|
||||
else:
|
||||
self.body = unicode(str(data["body"]), 'utf-8', 'replace')
|
||||
# Unicode is depreciated
|
||||
self.body = str(data["body"])
|
||||
|
||||
def encode(self, data):
|
||||
"""Encode a message"""
|
||||
|
|
|
@ -276,7 +276,7 @@ def isProofOfWorkSufficient(
|
|||
if TTL < 300:
|
||||
TTL = 300
|
||||
POW, = unpack('>Q', hashlib.sha512(hashlib.sha512(
|
||||
data[:8] + hashlib.sha512(data[8:]).digest()
|
||||
bytes(data[:8]) + hashlib.sha512(data[8:]).digest()
|
||||
).digest()).digest()[0:8])
|
||||
return POW <= 2 ** 64 / (
|
||||
nonceTrialsPerByte * (
|
||||
|
|
Reference in New Issue
Block a user