From c848d55462fc9fea599e1774dd8219a2ab131ae6 Mon Sep 17 00:00:00 2001 From: Innocenty Enikeew Date: Mon, 2 Jun 2014 21:05:26 +0400 Subject: [PATCH 1/2] Fix unicode handling in 'View HTML code as formated text'. Fixes #667 --- src/bitmessageqt/__init__.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 9543503f..486f80ec 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -2583,16 +2583,18 @@ class MyForm(QtGui.QMainWindow): '''select message from inbox where msgid=?''', msgid) if queryreturn != []: for row in queryreturn: - messageAtCurrentInboxRow, = row + messageText, = row - lines = messageAtCurrentInboxRow.split('\n') + messageText = shared.fixPotentiallyInvalidUTF8Data(messageText) + messageText = unicode(messageText, 'utf-8)') + lines = messageText.split('\n') for i in xrange(len(lines)): if 'Message ostensibly from ' in lines[i]: - lines[i] = '

%s

' % ( + lines[i] = u'

%s

' % ( lines[i]) elif lines[i] == '------------------------------------------------------': lines[i] = '
' - content = '' + content = u'' for i in xrange(len(lines)): content += lines[i] content = content.replace('\n\n', '

') From 51b9a59719815c6f30aa55e4fd95e38619413450 Mon Sep 17 00:00:00 2001 From: Innocenty Enikeew Date: Tue, 3 Jun 2014 09:45:59 +0400 Subject: [PATCH 2/2] Optimizations and better newlines handling --- src/bitmessageqt/__init__.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 486f80ec..dd67d211 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -2585,19 +2585,20 @@ class MyForm(QtGui.QMainWindow): for row in queryreturn: messageText, = row - messageText = shared.fixPotentiallyInvalidUTF8Data(messageText) - messageText = unicode(messageText, 'utf-8)') lines = messageText.split('\n') - for i in xrange(len(lines)): + totalLines = len(lines) + for i in xrange(totalLines): if 'Message ostensibly from ' in lines[i]: - lines[i] = u'

%s

' % ( + lines[i] = '

%s

' % ( lines[i]) elif lines[i] == '------------------------------------------------------': lines[i] = '
' - content = u'' - for i in xrange(len(lines)): - content += lines[i] - content = content.replace('\n\n', '

') + elif lines[i] == '' and (i+1) < totalLines and \ + lines[i+1] != '------------------------------------------------------': + lines[i] = '

' + content = ' '.join(lines) # To keep the whitespace between lines + content = shared.fixPotentiallyInvalidUTF8Data(content) + content = unicode(content, 'utf-8)') self.ui.textEditInboxMessage.setHtml(QtCore.QString(content)) def on_action_InboxMarkUnread(self):