From 234aa4dfec16e002a0418ebd6bea70a8494076eb Mon Sep 17 00:00:00 2001 From: delicatebits Date: Mon, 1 Apr 2013 19:29:30 -0400 Subject: [PATCH 1/5] Add context menu action to view message as richtext --- bitmessagemain.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/bitmessagemain.py b/bitmessagemain.py index 2b30ea56..60dd894f 100755 --- a/bitmessagemain.py +++ b/bitmessagemain.py @@ -3426,9 +3426,12 @@ class MyForm(QtGui.QMainWindow): self.actionReply = self.ui.inboxContextMenuToolbar.addAction("Reply", self.on_action_InboxReply) self.actionAddSenderToAddressBook = self.ui.inboxContextMenuToolbar.addAction("Add sender to your Address Book", self.on_action_InboxAddSenderToAddressBook) self.actionTrashInboxMessage = self.ui.inboxContextMenuToolbar.addAction("Move to Trash", self.on_action_InboxTrash) + self.actionForceHtml = self.ui.inboxContextMenuToolbar.addAction("View as Richtext", self.on_action_InboxMsgForceHtml) self.ui.tableWidgetInbox.setContextMenuPolicy( QtCore.Qt.CustomContextMenu ) self.connect(self.ui.tableWidgetInbox, QtCore.SIGNAL('customContextMenuRequested(const QPoint&)'), self.on_context_menuInbox) self.popMenuInbox = QtGui.QMenu( self ) + self.popMenuInbox.addAction( self.actionForceHtml ) + self.popMenuInbox.addSeparator() self.popMenuInbox.addAction( self.actionReply ) self.popMenuInbox.addAction( self.actionAddSenderToAddressBook ) self.popMenuInbox.addSeparator() @@ -4637,6 +4640,16 @@ class MyForm(QtGui.QMainWindow): event.accept() raise SystemExit + def on_action_InboxMsgForceHtml(self): + lines = str(self.ui.textEditInboxMessage.toPlainText()).split('\n') + from_prefix = 'Message ostensibly from ' + for i in xrange(len(lines)): + if lines[i].find(from_prefix) != -1: + lines[i] = '

%s%s

' % (from_prefix,lines[i][24:-1]) + elif lines[i] == '------------------------------------------------------': + lines[i] = '
' + content = '\n'.join(lines) + self.ui.textEditInboxMessage.setHtml(QtCore.QString(content)) def on_action_InboxReply(self): currentInboxRow = self.ui.tableWidgetInbox.currentRow() From d94397443963a3dcad267cbb25dd2128c352bc6b Mon Sep 17 00:00:00 2001 From: delicatebits Date: Mon, 1 Apr 2013 20:52:22 -0400 Subject: [PATCH 2/5] Updated to catch exception --- bitmessagemain.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bitmessagemain.py b/bitmessagemain.py index 60dd894f..f4cf3d57 100755 --- a/bitmessagemain.py +++ b/bitmessagemain.py @@ -4641,7 +4641,13 @@ class MyForm(QtGui.QMainWindow): raise SystemExit def on_action_InboxMsgForceHtml(self): - lines = str(self.ui.textEditInboxMessage.toPlainText()).split('\n') + # Updated to work with all characters. Previously, non-english characters caused errors. + try: + lines = str(self.ui.textEditInboxMessage.toPlainText()).split('\n') + except UnicodeEncodeError: + currentInboxRow = self.ui.tableWidgetInbox.currentRow() + self.ui.textEditInboxMessage.setHtml(self.ui.tableWidgetInbox.item(currentInboxRow,2).data(Qt.UserRole).toPyObject()) + return from_prefix = 'Message ostensibly from ' for i in xrange(len(lines)): if lines[i].find(from_prefix) != -1: @@ -4649,6 +4655,7 @@ class MyForm(QtGui.QMainWindow): elif lines[i] == '------------------------------------------------------': lines[i] = '
' content = '\n'.join(lines) + content = content.replace('\n\n', '

') self.ui.textEditInboxMessage.setHtml(QtCore.QString(content)) def on_action_InboxReply(self): From 7f9fda22846887d20cc4b7230971be9dd1e5d25e Mon Sep 17 00:00:00 2001 From: Jonathan Warren Date: Tue, 2 Apr 2013 11:39:19 -0400 Subject: [PATCH 3/5] 12px font is good --- bitmessagemain.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bitmessagemain.py b/bitmessagemain.py index f4cf3d57..442acaec 100755 --- a/bitmessagemain.py +++ b/bitmessagemain.py @@ -3603,6 +3603,7 @@ class MyForm(QtGui.QMainWindow): newItem.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled ) self.ui.tableWidgetInbox.setItem(0,3,newItem) #self.ui.textEditInboxMessage.setPlainText(self.ui.tableWidgetInbox.item(0,2).data(Qt.UserRole).toPyObject()) + self.ui.tableWidgetInbox.sortItems(3,Qt.DescendingOrder) self.ui.tableWidgetInbox.keyPressEvent = self.tableWidgetInboxKeyPressEvent #Load Sent items from database @@ -3665,6 +3666,7 @@ class MyForm(QtGui.QMainWindow): newItem.setData(33,int(lastactiontime)) newItem.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled ) self.ui.tableWidgetSent.setItem(0,3,newItem) + self.ui.tableWidgetSent.sortItems(3,Qt.DescendingOrder) #Initialize the address book sqlSubmitQueue.put('SELECT * FROM addressbook') @@ -4651,7 +4653,7 @@ class MyForm(QtGui.QMainWindow): from_prefix = 'Message ostensibly from ' for i in xrange(len(lines)): if lines[i].find(from_prefix) != -1: - lines[i] = '

%s%s

' % (from_prefix,lines[i][24:-1]) + lines[i] = '

%s%s

' % (from_prefix,lines[i][24:-1]) elif lines[i] == '------------------------------------------------------': lines[i] = '
' content = '\n'.join(lines) From 5f479ab05b62336a12c21f5282c8e1408e224aba Mon Sep 17 00:00:00 2001 From: Jonathan Warren Date: Tue, 2 Apr 2013 12:23:34 -0400 Subject: [PATCH 4/5] use len(data) instead of self.payloadLength --- bitmessagemain.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/bitmessagemain.py b/bitmessagemain.py index 442acaec..033eb598 100755 --- a/bitmessagemain.py +++ b/bitmessagemain.py @@ -509,7 +509,7 @@ class receiveDataThread(QThread): if embeddedTime < (int(time.time())-maximumAgeOfAnObjectThatIAmWillingToAccept): print 'The embedded time in this broadcast message is too old. Ignoring message.' return - if self.payloadLength < 66: #todo: When version 1 addresses are completely abandoned, this should be changed to 180 + if len(data) < 180: print 'The payload length of this broadcast packet is unreasonably low. Someone is probably trying funny business. Ignoring message.' return inventoryLock.acquire() @@ -533,11 +533,11 @@ class receiveDataThread(QThread): self.processbroadcast(data)#When this function returns, we will have either successfully processed this broadcast because we are interested in it, ignored it because we aren't interested in it, or found problem with the broadcast that warranted ignoring it. # Let us now set lengthOfTimeWeShouldUseToProcessThisMessage. If we haven't used the specified amount of time, we shall sleep. These values are mostly the same values used for msg messages although broadcast messages are processed faster. - if self.payloadLength > 100000000: #Size is greater than 100 megabytes + if len(data) > 100000000: #Size is greater than 100 megabytes lengthOfTimeWeShouldUseToProcessThisMessage = 100 #seconds. - elif self.payloadLength > 10000000: #Between 100 and 10 megabytes + elif len(data) > 10000000: #Between 100 and 10 megabytes lengthOfTimeWeShouldUseToProcessThisMessage = 20 #seconds. - elif self.payloadLength > 1000000: #Between 10 and 1 megabyte + elif len(data) > 1000000: #Between 10 and 1 megabyte lengthOfTimeWeShouldUseToProcessThisMessage = 3 #seconds. else: #Less than 1 megabyte lengthOfTimeWeShouldUseToProcessThisMessage = .1 #seconds. @@ -714,11 +714,11 @@ class receiveDataThread(QThread): self.processmsg(readPosition,data) #When this function returns, we will have either successfully processed the message bound for us, ignored it because it isn't bound for us, or found problem with the message that warranted ignoring it. # Let us now set lengthOfTimeWeShouldUseToProcessThisMessage. If we haven't used the specified amount of time, we shall sleep. These values are based on test timings and you may change them at-will. - if self.payloadLength > 100000000: #Size is greater than 100 megabytes + if len(data) > 100000000: #Size is greater than 100 megabytes lengthOfTimeWeShouldUseToProcessThisMessage = 100 #seconds. Actual length of time it took my computer to decrypt and verify the signature of a 100 MB message: 3.7 seconds. - elif self.payloadLength > 10000000: #Between 100 and 10 megabytes + elif len(data) > 10000000: #Between 100 and 10 megabytes lengthOfTimeWeShouldUseToProcessThisMessage = 20 #seconds. Actual length of time it took my computer to decrypt and verify the signature of a 10 MB message: 0.53 seconds. Actual length of time it takes in practice when processing a real message: 1.44 seconds. - elif self.payloadLength > 1000000: #Between 10 and 1 megabyte + elif len(data) > 1000000: #Between 10 and 1 megabyte lengthOfTimeWeShouldUseToProcessThisMessage = 3 #seconds. Actual length of time it took my computer to decrypt and verify the signature of a 1 MB message: 0.18 seconds. Actual length of time it takes in practice when processing a real message: 0.30 seconds. else: #Less than 1 megabyte lengthOfTimeWeShouldUseToProcessThisMessage = .6 #seconds. Actual length of time it took my computer to decrypt and verify the signature of a 100 KB message: 0.15 seconds. Actual length of time it takes in practice when processing a real message: 0.25 seconds. @@ -1072,8 +1072,8 @@ class receiveDataThread(QThread): printLock.release() return if addressVersion == 2: - if self.payloadLength < 146: #sanity check. This is the minimum possible length. - print 'payloadLength less than 146. Sanity check failed.' + if len(data) < 146: #sanity check. This is the minimum possible length. + print '(within processpubkey) payloadLength less than 146. Sanity check failed.' return bitfieldBehaviors = data[readPosition:readPosition+4] readPosition += 4 @@ -1521,7 +1521,7 @@ class receiveDataThread(QThread): #We have received a version message def recversion(self,data): - if self.payloadLength < 83: + if len(data) < 83: #This version message is unreasonably short. Forget it. return elif not self.verackSent: From df2b996b88298f55ad4f3c05028d571a5d02a4c1 Mon Sep 17 00:00:00 2001 From: Jonathan Warren Date: Tue, 2 Apr 2013 12:31:14 -0400 Subject: [PATCH 5/5] Msg designation reserved for person-to-person messages --- bitmessagemain.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bitmessagemain.py b/bitmessagemain.py index 033eb598..aa7987e2 100755 --- a/bitmessagemain.py +++ b/bitmessagemain.py @@ -3426,7 +3426,7 @@ class MyForm(QtGui.QMainWindow): self.actionReply = self.ui.inboxContextMenuToolbar.addAction("Reply", self.on_action_InboxReply) self.actionAddSenderToAddressBook = self.ui.inboxContextMenuToolbar.addAction("Add sender to your Address Book", self.on_action_InboxAddSenderToAddressBook) self.actionTrashInboxMessage = self.ui.inboxContextMenuToolbar.addAction("Move to Trash", self.on_action_InboxTrash) - self.actionForceHtml = self.ui.inboxContextMenuToolbar.addAction("View as Richtext", self.on_action_InboxMsgForceHtml) + self.actionForceHtml = self.ui.inboxContextMenuToolbar.addAction("View as Richtext", self.on_action_InboxMessageForceHtml) self.ui.tableWidgetInbox.setContextMenuPolicy( QtCore.Qt.CustomContextMenu ) self.connect(self.ui.tableWidgetInbox, QtCore.SIGNAL('customContextMenuRequested(const QPoint&)'), self.on_context_menuInbox) self.popMenuInbox = QtGui.QMenu( self ) @@ -4642,7 +4642,7 @@ class MyForm(QtGui.QMainWindow): event.accept() raise SystemExit - def on_action_InboxMsgForceHtml(self): + def on_action_InboxMessageForceHtml(self): # Updated to work with all characters. Previously, non-english characters caused errors. try: lines = str(self.ui.textEditInboxMessage.toPlainText()).split('\n')