Runnable with both Python3 and Python2, with both PyQt5 and PyQt4 by using Qt.py #2250
|
@ -16,6 +16,10 @@ from datetime import datetime, timedelta
|
||||||
from sqlite3 import register_adapter
|
from sqlite3 import register_adapter
|
||||||
import six
|
import six
|
||||||
from six.moves import range as xrange
|
from six.moves import range as xrange
|
||||||
|
if six.PY3:
|
||||||
|
from codecs import escape_decode
|
||||||
|
if six.PY2:
|
||||||
|
import sqlite3
|
||||||
|
|
||||||
from unqstr import ustr, unic
|
from unqstr import ustr, unic
|
||||||
from PyQt4 import QtCore, QtGui
|
from PyQt4 import QtCore, QtGui
|
||||||
|
@ -2943,7 +2947,15 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
if not msgid:
|
if not msgid:
|
||||||
return
|
return
|
||||||
queryreturn = sqlQuery(
|
queryreturn = sqlQuery(
|
||||||
'''select message from inbox where msgid=?''', msgid)
|
'SELECT message FROM inbox WHERE msgid=?', msgid)
|
||||||
|
# for compatibility
|
||||||
|
if len(queryreturn) < 1:
|
||||||
|
if six.PY3:
|
||||||
|
queryreturn = sqlQuery(
|
||||||
|
'SELECT message FROM inbox WHERE msgid=CAST(? AS TEXT)', msgid)
|
||||||
|
else: # assume six.PY2
|
||||||
|
queryreturn = sqlQuery(
|
||||||
|
'SELECT message FROM inbox WHERE msgid=?', sqlite3.Binary(msgid))
|
||||||
if queryreturn != []:
|
if queryreturn != []:
|
||||||
for row in queryreturn:
|
for row in queryreturn:
|
||||||
messageText, = row
|
messageText, = row
|
||||||
|
@ -3603,7 +3615,11 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
if messagelist:
|
if messagelist:
|
||||||
currentRow = messagelist.currentRow()
|
currentRow = messagelist.currentRow()
|
||||||
if currentRow >= 0:
|
if currentRow >= 0:
|
||||||
return messagelist.item(currentRow, 3).data()
|
msgid_str = messagelist.item(currentRow, 3).data()
|
||||||
|
if six.PY3:
|
||||||
|
return escape_decode(msgid_str)[0][2:-1]
|
||||||
|
else: # assume six.PY2
|
||||||
|
return msgid_str
|
||||||
|
|
||||||
def getCurrentMessageTextedit(self):
|
def getCurrentMessageTextedit(self):
|
||||||
currentIndex = self.ui.tabWidget.currentIndex()
|
currentIndex = self.ui.tabWidget.currentIndex()
|
||||||
|
@ -4147,11 +4163,27 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
folder = self.getCurrentFolder()
|
folder = self.getCurrentFolder()
|
||||||
if msgid:
|
if msgid:
|
||||||
queryreturn = sqlQuery(
|
queryreturn = sqlQuery(
|
||||||
'''SELECT message FROM %s WHERE %s=?''' % (
|
'SELECT message FROM %s WHERE %s=?' % (
|
||||||
('sent', 'ackdata') if folder == 'sent'
|
('sent', 'ackdata') if folder == 'sent'
|
||||||
else ('inbox', 'msgid')
|
else ('inbox', 'msgid')
|
||||||
), msgid
|
), msgid
|
||||||
)
|
)
|
||||||
|
# for compatibility
|
||||||
|
if len(queryreturn) < 1:
|
||||||
|
if six.PY3:
|
||||||
|
queryreturn = sqlQuery(
|
||||||
|
'SELECT message FROM %s WHERE %s=CAST(? AS TEXT)' % (
|
||||||
|
('sent', 'ackdata') if folder == 'sent'
|
||||||
|
else ('inbox', 'msgid')
|
||||||
|
), msgid
|
||||||
|
)
|
||||||
|
else: # assume six.PY2
|
||||||
|
queryreturn = sqlQuery(
|
||||||
|
'SELECT message FROM %s WHERE %s=?' % (
|
||||||
|
('sent', 'ackdata') if folder == 'sent'
|
||||||
|
else ('inbox', 'msgid')
|
||||||
|
), sqlite3.Binary(msgid)
|
||||||
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
message = queryreturn[-1][0]
|
message = queryreturn[-1][0]
|
||||||
|
|
|
@ -478,7 +478,7 @@ class MessageList_TimeWidget(BMTableWidgetItem):
|
||||||
|
|
||||||
def __init__(self, label=None, unread=False, timestamp=None, msgid=b''):
|
def __init__(self, label=None, unread=False, timestamp=None, msgid=b''):
|
||||||
super(MessageList_TimeWidget, self).__init__(label, unread)
|
super(MessageList_TimeWidget, self).__init__(label, unread)
|
||||||
self.setData(QtCore.Qt.UserRole, QtCore.QByteArray(msgid))
|
self.setData(QtCore.Qt.UserRole, QtCore.QByteArray(bytes(msgid)))
|
||||||
self.setData(TimestampRole, int(timestamp))
|
self.setData(TimestampRole, int(timestamp))
|
||||||
|
|
||||||
def __lt__(self, other):
|
def __lt__(self, other):
|
||||||
|
|
Reference in New Issue
Block a user