Gateway update and sort fix

- shows gateway parser results more accurately
- gateway class assigned dynamically
- inbox sort order is aware of what you click on and defaults to
ascending
This commit is contained in:
mailchuck 2015-10-03 12:12:18 +02:00 committed by Peter Surda
parent 033be9b5bf
commit b4fa5d4abf
3 changed files with 123 additions and 166 deletions

View File

@ -447,7 +447,9 @@ class MyForm(QtGui.QMainWindow):
elif tab == 'chan': elif tab == 'chan':
treeWidget = self.ui.treeWidgetChans treeWidget = self.ui.treeWidgetChans
#treeWidget.clear() # sort ascending when creating
if treeWidget.topLevelItemCount() == 0:
treeWidget.header().setSortIndicator(0, Qt.AscendingOrder)
# init dictionary # init dictionary
db = {} db = {}
@ -860,6 +862,10 @@ class MyForm(QtGui.QMainWindow):
else: else:
where = "toaddress || fromaddress || subject || message" where = "toaddress || fromaddress || subject || message"
tableWidget.setColumnHidden(0, False)
tableWidget.setColumnHidden(1, True)
tableWidget.setSortingEnabled(False)
sqlStatement = ''' sqlStatement = '''
SELECT toaddress, fromaddress, subject, status, ackdata, lastactiontime SELECT toaddress, fromaddress, subject, status, ackdata, lastactiontime
FROM sent WHERE fromaddress=? AND folder="sent" AND %s LIKE ? FROM sent WHERE fromaddress=? AND folder="sent" AND %s LIKE ?
@ -868,60 +874,34 @@ class MyForm(QtGui.QMainWindow):
while tableWidget.rowCount() > 0: while tableWidget.rowCount() > 0:
tableWidget.removeRow(0) tableWidget.removeRow(0)
acct = None
queryreturn = sqlQuery(sqlStatement, account, what) queryreturn = sqlQuery(sqlStatement, account, what)
for row in queryreturn: for row in queryreturn:
toAddress, fromAddress, subject, status, ackdata, lastactiontime = row toAddress, fromAddress, subject, status, ackdata, lastactiontime = row
subject = shared.fixPotentiallyInvalidUTF8Data(subject) subject = shared.fixPotentiallyInvalidUTF8Data(subject)
if acct is None:
if shared.config.has_section(fromAddress): acct = accountClass(fromAddress)
fromLabel = shared.config.get(fromAddress, 'label') acct.parseMessage(toAddress, fromAddress, subject, "")
else:
fromLabel = fromAddress
toLabel = ''
queryreturn = sqlQuery(
'''select label from addressbook where address=?''', toAddress)
if queryreturn != []:
for row in queryreturn:
toLabel, = row
if toLabel == '':
# It might be a broadcast message. We should check for that
# label.
queryreturn = sqlQuery(
'''select label from subscriptions where address=?''', toAddress)
if queryreturn != []:
for row in queryreturn:
toLabel, = row
if toLabel == '':
if shared.config.has_section(toAddress):
toLabel = shared.config.get(toAddress, 'label')
if toLabel == '':
toLabel = toAddress
tableWidget.insertRow(0) tableWidget.insertRow(0)
toAddressItem = QtGui.QTableWidgetItem(unicode(toLabel, 'utf-8')) toAddressItem = QtGui.QTableWidgetItem(unicode(acct.toLabel, 'utf-8'))
toAddressItem.setToolTip(unicode(toLabel, 'utf-8')) toAddressItem.setToolTip(unicode(acct.toLabel, 'utf-8'))
toAddressItem.setIcon(avatarize(toAddress)) toAddressItem.setIcon(avatarize(toAddress))
toAddressItem.setData(Qt.UserRole, str(toAddress)) toAddressItem.setData(Qt.UserRole, str(toAddress))
toAddressItem.setFlags( toAddressItem.setFlags(
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
tableWidget.setItem(0, 0, toAddressItem) tableWidget.setItem(0, 0, toAddressItem)
if fromLabel == '': fromAddressItem = QtGui.QTableWidgetItem(unicode(acct.fromLabel, 'utf-8'))
fromLabel = fromAddress fromAddressItem.setToolTip(unicode(acct.fromLabel, 'utf-8'))
fromAddressItem = QtGui.QTableWidgetItem(unicode(fromLabel, 'utf-8'))
fromAddressItem.setToolTip(unicode(fromLabel, 'utf-8'))
fromAddressItem.setIcon(avatarize(fromAddress)) fromAddressItem.setIcon(avatarize(fromAddress))
fromAddressItem.setData(Qt.UserRole, str(fromAddress)) fromAddressItem.setData(Qt.UserRole, str(fromAddress))
fromAddressItem.setFlags( fromAddressItem.setFlags(
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
tableWidget.setItem(0, 1, fromAddressItem) tableWidget.setItem(0, 1, fromAddressItem)
subjectItem = QtGui.QTableWidgetItem(unicode(subject, 'utf-8')) subjectItem = QtGui.QTableWidgetItem(unicode(acct.subject, 'utf-8'))
subjectItem.setToolTip(unicode(subject, 'utf-8')) subjectItem.setToolTip(unicode(acct.subject, 'utf-8'))
subjectItem.setFlags( subjectItem.setFlags(
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
tableWidget.setItem(0, 2, subjectItem) tableWidget.setItem(0, 2, subjectItem)
@ -972,7 +952,9 @@ class MyForm(QtGui.QMainWindow):
newItem.setFlags( newItem.setFlags(
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
tableWidget.setItem(0, 3, newItem) tableWidget.setItem(0, 3, newItem)
tableWidget.sortItems(3, Qt.DescendingOrder)
tableWidget.setSortingEnabled(False)
tableWidget.horizontalHeader().setSortIndicator(3, Qt.DescendingOrder)
tableWidget.keyPressEvent = self.tableWidgetInboxKeyPressEvent tableWidget.keyPressEvent = self.tableWidgetInboxKeyPressEvent
# Load messages from database file # Load messages from database file
@ -993,62 +975,43 @@ class MyForm(QtGui.QMainWindow):
else: else:
where = "toaddress || fromaddress || subject || message" where = "toaddress || fromaddress || subject || message"
if folder != False:
sqlStatement = ''' sqlStatement = '''
SELECT msgid, toaddress, fromaddress, subject, received, read SELECT folder, msgid, toaddress, fromaddress, subject, received, read
FROM inbox WHERE toaddress=? AND folder=? AND %s LIKE ? FROM inbox WHERE toaddress=? AND folder=? AND %s LIKE ?
ORDER BY received ORDER BY received
''' % (where) ''' % (where)
queryreturn = sqlQuery(sqlStatement, account, folder, what)
else:
sqlStatement = '''
SELECT folder, msgid, toaddress, fromaddress, subject, received, read
FROM inbox WHERE toaddress=? AND folder != "trash" AND %s LIKE ?
ORDER BY received
''' % (where)
queryreturn = sqlQuery(sqlStatement, account, what)
while tableWidget.rowCount() > 0: while tableWidget.rowCount() > 0:
tableWidget.removeRow(0) tableWidget.removeRow(0)
tableWidget.setColumnHidden(0, True)
tableWidget.setColumnHidden(1, False)
tableWidget.setSortingEnabled(False)
font = QFont() font = QFont()
font.setBold(True) font.setBold(True)
queryreturn = sqlQuery(sqlStatement, account, folder, what)
acct = None acct = None
for row in queryreturn: for row in queryreturn:
msgid, toAddress, fromAddress, subject, received, read = row msgfolder, msgid, toAddress, fromAddress, subject, received, read = row
if acct is None: if acct is None:
acct = accountClass(toAddress) acct = accountClass(toAddress)
subject = shared.fixPotentiallyInvalidUTF8Data(subject) subject = shared.fixPotentiallyInvalidUTF8Data(subject)
acct.parseMessage(toAddress, fromAddress, subject, "") acct.parseMessage(toAddress, fromAddress, subject, "")
try:
if toAddress == self.str_broadcast_subscribers:
toLabel = self.str_broadcast_subscribers
else:
toLabel = shared.config.get(toAddress, 'label')
except:
toLabel = ''
if toLabel == '':
toLabel = toAddress
fromLabel = ''
if type(acct) == MailchuckAccount:
fromLabel = acct.fromAddress
if shared.config.has_section(fromAddress):
fromLabel = shared.config.get(fromAddress, 'label')
if fromLabel == '': # If the fromAddress isn't one of our addresses and isn't a chan
queryreturn = sqlQuery(
'''select label from addressbook where address=?''', fromAddress)
if queryreturn != []:
for row in queryreturn:
fromLabel, = row
if fromLabel == '': # If this address wasn't in our address book...
queryreturn = sqlQuery(
'''select label from subscriptions where address=?''', fromAddress)
if queryreturn != []:
for row in queryreturn:
fromLabel, = row
if fromLabel == '':
fromLabel = fromAddress
# message row # message row
tableWidget.insertRow(0) tableWidget.insertRow(0)
# to # to
to_item = QtGui.QTableWidgetItem(unicode(toLabel, 'utf-8')) to_item = QtGui.QTableWidgetItem(unicode(acct.toLabel, 'utf-8'))
to_item.setToolTip(unicode(toLabel, 'utf-8')) to_item.setToolTip(unicode(acct.toLabel, 'utf-8'))
to_item.setFlags( to_item.setFlags(
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
if not read: if not read:
@ -1061,8 +1024,8 @@ class MyForm(QtGui.QMainWindow):
to_item.setIcon(avatarize(toAddress)) to_item.setIcon(avatarize(toAddress))
tableWidget.setItem(0, 0, to_item) tableWidget.setItem(0, 0, to_item)
# from # from
from_item = QtGui.QTableWidgetItem(unicode(fromLabel, 'utf-8')) from_item = QtGui.QTableWidgetItem(unicode(acct.fromLabel, 'utf-8'))
from_item.setToolTip(unicode(fromLabel, 'utf-8')) from_item.setToolTip(unicode(acct.fromLabel, 'utf-8'))
from_item.setFlags( from_item.setFlags(
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
if not read: if not read:
@ -1091,7 +1054,8 @@ class MyForm(QtGui.QMainWindow):
time_item.setFont(font) time_item.setFont(font)
tableWidget.setItem(0, 3, time_item) tableWidget.setItem(0, 3, time_item)
tableWidget.sortItems(3, Qt.DescendingOrder) tableWidget.horizontalHeader().setSortIndicator(3, Qt.DescendingOrder)
tableWidget.setSortingEnabled(True)
tableWidget.keyPressEvent = self.tableWidgetInboxKeyPressEvent tableWidget.keyPressEvent = self.tableWidgetInboxKeyPressEvent
# create application indicator # create application indicator
@ -1761,8 +1725,8 @@ class MyForm(QtGui.QMainWindow):
def changedInboxUnread(self, row = None): def changedInboxUnread(self, row = None):
self.drawTrayIcon(self.currentTrayIconFileName, self.findInboxUnreadCount()) self.drawTrayIcon(self.currentTrayIconFileName, self.findInboxUnreadCount())
self.rerenderTabTreeMessages() self.rerenderTabTreeMessages()
if not row is None: # if not row is None:
row[1], row[6] # row[1], row[6]
if self.ui.tabWidget.currentIndex() == 2: if self.ui.tabWidget.currentIndex() == 2:
self.rerenderTabTreeSubscriptions() self.rerenderTabTreeSubscriptions()
elif self.ui.tabWidget.currentIndex() == 3: elif self.ui.tabWidget.currentIndex() == 3:
@ -2216,35 +2180,23 @@ more work your computer must do to send the message. A Time-To-Live of four or f
return return
subject = shared.fixPotentiallyInvalidUTF8Data(subject) subject = shared.fixPotentiallyInvalidUTF8Data(subject)
message = shared.fixPotentiallyInvalidUTF8Data(message) message = shared.fixPotentiallyInvalidUTF8Data(message)
try: acct = accountClass(fromAddress)
fromLabel = shared.config.get(fromAddress, 'label') acct.parseMessage(toAddress, fromAddress, subject, message)
except:
fromLabel = ''
if fromLabel == '':
fromLabel = fromAddress
self.ui.tableWidgetInbox.setSortingEnabled(False) self.ui.tableWidgetInbox.setSortingEnabled(False)
self.ui.tableWidgetInbox.insertRow(0) self.ui.tableWidgetInbox.insertRow(0)
if toLabel == '': newItem = QtGui.QTableWidgetItem(unicode(acct.toLabel, 'utf-8'))
newItem = QtGui.QTableWidgetItem(unicode(toAddress, 'utf-8')) newItem.setToolTip(unicode(acct.toLabel, 'utf-8'))
newItem.setToolTip(unicode(toAddress, 'utf-8'))
else:
newItem = QtGui.QTableWidgetItem(unicode(toLabel, 'utf-8'))
newItem.setToolTip(unicode(toLabel, 'utf-8'))
newItem.setData(Qt.UserRole, str(toAddress)) newItem.setData(Qt.UserRole, str(toAddress))
newItem.setIcon(avatarize(toAddress)) newItem.setIcon(avatarize(toAddress))
self.ui.tableWidgetInbox.setItem(0, 0, newItem) self.ui.tableWidgetInbox.setItem(0, 0, newItem)
if fromLabel == '': newItem = QtGui.QTableWidgetItem(unicode(acct.fromLabel, 'utf-8'))
newItem = QtGui.QTableWidgetItem(unicode(fromAddress, 'utf-8')) newItem.setToolTip(unicode(acct.fromLabel, 'utf-8'))
newItem.setToolTip(unicode(fromAddress, 'utf-8'))
else:
newItem = QtGui.QTableWidgetItem(unicode(fromLabel, 'utf-8'))
newItem.setToolTip(unicode(fromLabel, 'utf-8'))
newItem.setData(Qt.UserRole, str(fromAddress)) newItem.setData(Qt.UserRole, str(fromAddress))
newItem.setIcon(avatarize(fromAddress)) newItem.setIcon(avatarize(fromAddress))
self.ui.tableWidgetInbox.setItem(0, 1, newItem) self.ui.tableWidgetInbox.setItem(0, 1, newItem)
newItem = QtGui.QTableWidgetItem(unicode(subject, 'utf-8)')) newItem = QtGui.QTableWidgetItem(unicode(acct.subject, 'utf-8)'))
newItem.setToolTip(unicode(subject, 'utf-8)')) newItem.setToolTip(unicode(acct.subject, 'utf-8)'))
#newItem.setData(Qt.UserRole, unicode(message, 'utf-8)')) # No longer hold the message in the table; we'll use a SQL query to display it as needed. #newItem.setData(Qt.UserRole, unicode(message, 'utf-8)')) # No longer hold the message in the table; we'll use a SQL query to display it as needed.
self.ui.tableWidgetInbox.setItem(0, 2, newItem) self.ui.tableWidgetInbox.setItem(0, 2, newItem)
# newItem = QtGui.QTableWidgetItem('Doing work necessary to send # newItem = QtGui.QTableWidgetItem('Doing work necessary to send
@ -2259,40 +2211,17 @@ more work your computer must do to send the message. A Time-To-Live of four or f
self.ui.tableWidgetInbox.setSortingEnabled(True) self.ui.tableWidgetInbox.setSortingEnabled(True)
def displayNewInboxMessage(self, inventoryHash, toAddress, fromAddress, subject, message): def displayNewInboxMessage(self, inventoryHash, toAddress, fromAddress, subject, message):
if self.getCurrentFolder() != "inbox" or self.getCurrentAccount() != toAddress: if (self.getCurrentFolder() != "inbox" and self.getCurrentFolder() != False) or self.getCurrentAccount() != toAddress:
return return
subject = shared.fixPotentiallyInvalidUTF8Data(subject) subject = shared.fixPotentiallyInvalidUTF8Data(subject)
fromLabel = '' acct = accountClass(toAddress)
queryreturn = sqlQuery( acct.parseMessage(toAddress, fromAddress, subject, message)
'''select label from addressbook where address=?''', fromAddress)
if queryreturn != []:
for row in queryreturn:
fromLabel, = row
else:
# There might be a label in the subscriptions table
queryreturn = sqlQuery(
'''select label from subscriptions where address=?''', fromAddress)
if queryreturn != []:
for row in queryreturn:
fromLabel, = row
try:
if toAddress == self.str_broadcast_subscribers:
toLabel = self.str_broadcast_subscribers
else:
toLabel = shared.config.get(toAddress, 'label')
except:
toLabel = ''
if toLabel == '':
toLabel = toAddress
font = QFont() font = QFont()
font.setBold(True) font.setBold(True)
self.ui.tableWidgetInbox.setSortingEnabled(False) self.ui.tableWidgetInbox.setSortingEnabled(False)
account = accountClass(toAddress) newItem = QtGui.QTableWidgetItem(unicode(acct.toLabel, 'utf-8'))
account.parseMessage(toAddress, fromAddress, subject, message) newItem.setToolTip(unicode(acct.toLabel, 'utf-8'))
newItem = QtGui.QTableWidgetItem(unicode(toLabel, 'utf-8'))
newItem.setToolTip(unicode(toLabel, 'utf-8'))
newItem.setFont(font) newItem.setFont(font)
newItem.setData(Qt.UserRole, str(toAddress)) newItem.setData(Qt.UserRole, str(toAddress))
if shared.safeConfigGetBoolean(str(toAddress), 'mailinglist'): if shared.safeConfigGetBoolean(str(toAddress), 'mailinglist'):
@ -2303,27 +2232,16 @@ more work your computer must do to send the message. A Time-To-Live of four or f
newItem.setIcon(avatarize(toAddress)) newItem.setIcon(avatarize(toAddress))
self.ui.tableWidgetInbox.setItem(0, 0, newItem) self.ui.tableWidgetInbox.setItem(0, 0, newItem)
if type(account) is MailchuckAccount: newItem = QtGui.QTableWidgetItem(unicode(acct.fromLabel, 'utf-8'))
newItem = QtGui.QTableWidgetItem(unicode(account.fromAddress, 'utf-8')) newItem.setToolTip(unicode(acct.fromLabel, 'utf-8'))
newItem.setToolTip(unicode(account.fromAddress, 'utf-8'))
if shared.config.getboolean('bitmessagesettings', 'showtraynotifications'): if shared.config.getboolean('bitmessagesettings', 'showtraynotifications'):
self.notifierShow(unicode(_translate("MainWindow",'New Message').toUtf8(),'utf-8'), unicode(_translate("MainWindow",'From ').toUtf8(),'utf-8') + unicode(account.fromAddress, 'utf-8'), self.SOUND_UNKNOWN, None) self.notifierShow(unicode(_translate("MainWindow",'New Message').toUtf8(),'utf-8'), unicode(_translate("MainWindow",'From ').toUtf8(),'utf-8') + unicode(acct.fromLabel, 'utf-8'), self.SOUND_UNKNOWN, None)
elif fromLabel == '':
newItem = QtGui.QTableWidgetItem(unicode(fromAddress, 'utf-8'))
newItem.setToolTip(unicode(fromAddress, 'utf-8'))
if shared.config.getboolean('bitmessagesettings', 'showtraynotifications'):
self.notifierShow(unicode(_translate("MainWindow",'New Message').toUtf8(),'utf-8'), unicode(_translate("MainWindow",'From ').toUtf8(),'utf-8') + unicode(fromAddress, 'utf-8'), self.SOUND_UNKNOWN, None)
else:
newItem = QtGui.QTableWidgetItem(unicode(fromLabel, 'utf-8'))
newItem.setToolTip(unicode(unicode(fromLabel, 'utf-8')))
if shared.config.getboolean('bitmessagesettings', 'showtraynotifications'):
self.notifierShow(unicode(_translate("MainWindow",'New Message').toUtf8(),'utf-8'), unicode(_translate("MainWindow",'From ').toUtf8(),'utf-8') + unicode(fromLabel, 'utf-8'), self.SOUND_KNOWN, unicode(fromLabel, 'utf-8'))
newItem.setData(Qt.UserRole, str(fromAddress)) newItem.setData(Qt.UserRole, str(fromAddress))
newItem.setFont(font) newItem.setFont(font)
newItem.setIcon(avatarize(fromAddress)) newItem.setIcon(avatarize(fromAddress))
self.ui.tableWidgetInbox.setItem(0, 1, newItem) self.ui.tableWidgetInbox.setItem(0, 1, newItem)
newItem = QtGui.QTableWidgetItem(unicode(subject, 'utf-8)')) newItem = QtGui.QTableWidgetItem(unicode(acct.subject, 'utf-8)'))
newItem.setToolTip(unicode(account.subject, 'utf-8)')) newItem.setToolTip(unicode(acct.subject, 'utf-8)'))
#newItem.setData(Qt.UserRole, unicode(message, 'utf-8)')) # No longer hold the message in the table; we'll use a SQL query to display it as needed. #newItem.setData(Qt.UserRole, unicode(message, 'utf-8)')) # No longer hold the message in the table; we'll use a SQL query to display it as needed.
newItem.setFont(font) newItem.setFont(font)
self.ui.tableWidgetInbox.setItem(0, 2, newItem) self.ui.tableWidgetInbox.setItem(0, 2, newItem)
@ -2334,7 +2252,7 @@ more work your computer must do to send the message. A Time-To-Live of four or f
newItem.setFont(font) newItem.setFont(font)
self.ui.tableWidgetInbox.setItem(0, 3, newItem) self.ui.tableWidgetInbox.setItem(0, 3, newItem)
self.ui.tableWidgetInbox.setSortingEnabled(True) self.ui.tableWidgetInbox.setSortingEnabled(True)
self.ubuntuMessagingMenuUpdate(True, newItem, toLabel) self.ubuntuMessagingMenuUpdate(True, newItem, self.toLabel)
def click_pushButtonAddAddressBook(self): def click_pushButtonAddAddressBook(self):
self.AddAddressDialogInstance = AddAddressDialog(self) self.AddAddressDialogInstance = AddAddressDialog(self)
@ -2955,11 +2873,14 @@ more work your computer must do to send the message. A Time-To-Live of four or f
tableWidget = self.getCurrentMessagelist() tableWidget = self.getCurrentMessagelist()
if not tableWidget: if not tableWidget:
return return
unread = False
while tableWidget.selectedIndexes() != []: while tableWidget.selectedIndexes() != []:
currentRow = tableWidget.selectedIndexes()[0].row() currentRow = tableWidget.selectedIndexes()[0].row()
inventoryHashToTrash = str(tableWidget.item( inventoryHashToTrash = str(tableWidget.item(
currentRow, 3).data(Qt.UserRole).toPyObject()) currentRow, 3).data(Qt.UserRole).toPyObject())
sqlExecute('''UPDATE inbox SET folder='trash' WHERE msgid=?''', inventoryHashToTrash) sqlExecute('''UPDATE inbox SET folder='trash' WHERE msgid=?''', inventoryHashToTrash)
if tableWidget.item(currentRow, 0).font().bold():
unread = True
self.ui.textEditInboxMessage.setText("") self.ui.textEditInboxMessage.setText("")
tableWidget.removeRow(currentRow) tableWidget.removeRow(currentRow)
self.statusBar().showMessage(_translate( self.statusBar().showMessage(_translate(
@ -2968,6 +2889,8 @@ more work your computer must do to send the message. A Time-To-Live of four or f
tableWidget.selectRow(currentRow) tableWidget.selectRow(currentRow)
else: else:
tableWidget.selectRow(currentRow - 1) tableWidget.selectRow(currentRow - 1)
if unread:
changedInboxUnread()
def on_action_InboxSaveMessageAs(self): def on_action_InboxSaveMessageAs(self):
tableWidget = self.getCurrentMessagelist() tableWidget = self.getCurrentMessagelist()
@ -3303,9 +3226,8 @@ more work your computer must do to send the message. A Time-To-Live of four or f
treeWidget = self.ui.treeWidgetYourIdentities treeWidget = self.ui.treeWidgetYourIdentities
if treeWidget: if treeWidget:
currentItem = treeWidget.currentItem() currentItem = treeWidget.currentItem()
if currentItem: if currentItem and hasattr(currentItem, 'folderName'):
account = currentItem.folderName return currentItem.folderName
return account
else: else:
# TODO need debug msg? # TODO need debug msg?
return False return False
@ -3518,7 +3440,7 @@ more work your computer must do to send the message. A Time-To-Live of four or f
refresh = False refresh = False
for row in queryreturn: for row in queryreturn:
message, read = row message, read = row
if folder == 'inbox' and read == 0: if folder != 'sent' and read == 0:
markread = sqlQuery( markread = sqlQuery(
'''UPDATE inbox SET read = 1 WHERE msgid = ?''', msgid) '''UPDATE inbox SET read = 1 WHERE msgid = ?''', msgid)
refresh = True refresh = True

View File

@ -3,30 +3,58 @@ from PyQt4 import QtCore, QtGui
import shared import shared
import re import re
import sys import sys
import inspect
from helper_sql import *
def accountClass(address): def accountClass(address):
if not shared.config.has_section(address): if not shared.config.has_section(address):
return None return None
try: try:
gateway = shared.config.get(address, "gateway") gateway = shared.config.get(address, "gateway")
if (gateway == "mailchuck"): for name, cls in inspect.getmembers(sys.modules[__name__], inspect.isclass):
return MailchuckAccount(address) # obj = g(address)
else: if issubclass(cls, GatewayAccount) and cls.gatewayName == gateway:
return cls(address)
# general gateway
return GatewayAccount(address) return GatewayAccount(address)
except: except:
pass
# no gateway
return BMAccount(address) return BMAccount(address)
class BMAccount(object): class BMAccount(object):
def __init__(self, address): def __init__(self, address = None):
self.address = address self.address = address
def getLabel(self, address = None):
if address is None:
address = self.address
label = address
if shared.config.has_section(address):
label = shared.config.get(address, 'label')
queryreturn = sqlQuery(
'''select label from addressbook where address=?''', address)
if queryreturn != []:
for row in queryreturn:
label, = row
else:
queryreturn = sqlQuery(
'''select label from subscriptions where address=?''', address)
if queryreturn != []:
for row in queryreturn:
label, = row
return label
def parseMessage(self, toAddress, fromAddress, subject, message): def parseMessage(self, toAddress, fromAddress, subject, message):
self.toAddress = toAddress self.toAddress = toAddress
self.fromAddress = fromAddress self.fromAddress = fromAddress
self.subject = subject self.subject = subject
self.message = message self.message = message
self.fromLabel = self.getLabel(fromAddress)
self.toLabel = self.getLabel(toAddress)
class GatewayAccount(BMAccount): class GatewayAccount(BMAccount):
gatewayName = None
def __init__(self, address): def __init__(self, address):
super(BMAccount, self).__init__(address) super(BMAccount, self).__init__(address)
@ -34,6 +62,8 @@ class GatewayAccount(BMAccount):
super(BMAccount, self).parseMessage(toAddress, fromAddress, subject, message) super(BMAccount, self).parseMessage(toAddress, fromAddress, subject, message)
class MailchuckAccount(GatewayAccount): class MailchuckAccount(GatewayAccount):
# set "gateway" in keys.dat to this
gatewayName = "mailchuck"
registrationAddress = "BM-2cVYYrhaY5Gbi3KqrX9Eae2NRNrkfrhCSA" registrationAddress = "BM-2cVYYrhaY5Gbi3KqrX9Eae2NRNrkfrhCSA"
unregistrationAddress = "BM-2cVMAHTRjZHCTPMue75XBK5Tco175DtJ9J" unregistrationAddress = "BM-2cVMAHTRjZHCTPMue75XBK5Tco175DtJ9J"
relayAddress = "BM-2cWim8aZwUNqxzjMxstnUMtVEUQJeezstf" relayAddress = "BM-2cWim8aZwUNqxzjMxstnUMtVEUQJeezstf"
@ -53,11 +83,11 @@ class MailchuckAccount(GatewayAccount):
if not matches.group(3) is None: if not matches.group(3) is None:
self.subject += matches.group(3) self.subject += matches.group(3)
if not matches.group(2) is None: if not matches.group(2) is None:
self.fromAddress = matches.group(2) self.fromLabel = matches.group(2)
if toAddress == self.relayAddress: if toAddress == self.relayAddress:
matches = self.regExpOutgoing.search(subject) matches = self.regExpOutgoing.search(subject)
if not matches is None: if not matches is None:
if not matches.group(2) is None: if not matches.group(2) is None:
self.subject = matches.group(2) self.subject = matches.group(2)
if not matches.group(1) is None: if not matches.group(1) is None:
self.toAddress = matches.group(1) self.toLabel = matches.group(1)

View File

@ -49,11 +49,13 @@ class Ui_FolderWidget(QtGui.QTreeWidgetItem):
y = self.folderWeight[other.folderName] y = self.folderWeight[other.folderName]
else: else:
y = 4 y = 4
reverse = False
if self.treeWidget().header().sortIndicatorOrder() == QtCore.Qt.DescendingOrder:
reverse = True
if x == y: if x == y:
return self.folderName > other.folderName return self.folderName < other.folderName
else: else:
return x > y return (x >= y if reverse else x < y)
return super(QtGui.QTreeWidgetItem, self).__lt__(other) return super(QtGui.QTreeWidgetItem, self).__lt__(other)
@ -117,6 +119,9 @@ class Ui_AddressWidget(QtGui.QTreeWidgetItem):
# label (or address) alphabetically, disabled at the end # label (or address) alphabetically, disabled at the end
def __lt__(self, other): def __lt__(self, other):
if (isinstance(other, Ui_AddressWidget)): if (isinstance(other, Ui_AddressWidget)):
reverse = False
if self.treeWidget().header().sortIndicatorOrder() == QtCore.Qt.DescendingOrder:
reverse = True
if shared.config.getboolean(self.address, 'enabled') == shared.config.getboolean(other.address, 'enabled'): if shared.config.getboolean(self.address, 'enabled') == shared.config.getboolean(other.address, 'enabled'):
if shared.config.get(self.address, 'label'): if shared.config.get(self.address, 'label'):
x = shared.config.get(self.address, 'label').decode('utf-8').lower() x = shared.config.get(self.address, 'label').decode('utf-8').lower()
@ -126,8 +131,8 @@ class Ui_AddressWidget(QtGui.QTreeWidgetItem):
y = shared.config.get(other.address, 'label').decode('utf-8').lower() y = shared.config.get(other.address, 'label').decode('utf-8').lower()
else: else:
y = other.address.decode('utf-8').lower() y = other.address.decode('utf-8').lower()
return y < x return x < y
# else: # else:
return (False if shared.config.getboolean(self.address, 'enabled') else True) return (not reverse if shared.config.getboolean(self.address, 'enabled') else reverse)
return super(QtGui.QTreeWidgetItem, self).__lt__(other) return super(QtGui.QTreeWidgetItem, self).__lt__(other)