From 033be9b5bf30f416d5700a651ed576d31545d97f Mon Sep 17 00:00:00 2001 From: mailchuck Date: Sat, 3 Oct 2015 01:17:47 +0200 Subject: [PATCH] Email Gateway UI implementation First steps, only a tiny part works --- src/bitmessageqt/__init__.py | 47 ++++++++++++++++--------- src/bitmessageqt/account.py | 63 ++++++++++++++++++++++++++++++++++ src/bitmessageqt/foldertree.py | 4 +-- 3 files changed, 96 insertions(+), 18 deletions(-) create mode 100644 src/bitmessageqt/account.py diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 76acb328..187b0192 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -56,6 +56,7 @@ from helper_sql import * import l10n from utils import * from collections import OrderedDict +from account import * def _translate(context, text): return QtGui.QApplication.translate(context, text) @@ -1004,9 +1005,13 @@ class MyForm(QtGui.QMainWindow): font = QFont() font.setBold(True) queryreturn = sqlQuery(sqlStatement, account, folder, what) + acct = None for row in queryreturn: msgid, toAddress, fromAddress, subject, received, read = row + if acct is None: + acct = accountClass(toAddress) subject = shared.fixPotentiallyInvalidUTF8Data(subject) + acct.parseMessage(toAddress, fromAddress, subject, "") try: if toAddress == self.str_broadcast_subscribers: toLabel = self.str_broadcast_subscribers @@ -1018,6 +1023,8 @@ class MyForm(QtGui.QMainWindow): toLabel = toAddress fromLabel = '' + if type(acct) == MailchuckAccount: + fromLabel = acct.fromAddress if shared.config.has_section(fromAddress): fromLabel = shared.config.get(fromAddress, 'label') @@ -1066,8 +1073,8 @@ class MyForm(QtGui.QMainWindow): from_item.setIcon(avatarize(fromAddress)) tableWidget.setItem(0, 1, from_item) # subject - subject_item = QtGui.QTableWidgetItem(unicode(subject, 'utf-8')) - subject_item.setToolTip(unicode(subject, 'utf-8')) + subject_item = QtGui.QTableWidgetItem(unicode(acct.subject, 'utf-8')) + subject_item.setToolTip(unicode(acct.subject, 'utf-8')) subject_item.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) if not read: @@ -1751,11 +1758,12 @@ class MyForm(QtGui.QMainWindow): def drawTrayIcon(self, iconFileName, inboxUnreadCount): self.tray.setIcon(self.calcTrayIcon(iconFileName, inboxUnreadCount)) - def changedInboxUnread(self): + def changedInboxUnread(self, row = None): self.drawTrayIcon(self.currentTrayIconFileName, self.findInboxUnreadCount()) - if self.ui.tabWidget.currentIndex() == 0: - self.rerenderTabTreeMessages() - elif self.ui.tabWidget.currentIndex() == 2: + self.rerenderTabTreeMessages() + if not row is None: + row[1], row[6] + if self.ui.tabWidget.currentIndex() == 2: self.rerenderTabTreeSubscriptions() elif self.ui.tabWidget.currentIndex() == 3: self.rerenderTabTreeChans() @@ -2281,6 +2289,8 @@ more work your computer must do to send the message. A Time-To-Live of four or f font = QFont() font.setBold(True) self.ui.tableWidgetInbox.setSortingEnabled(False) + account = accountClass(toAddress) + account.parseMessage(toAddress, fromAddress, subject, message) newItem = QtGui.QTableWidgetItem(unicode(toLabel, 'utf-8')) newItem.setToolTip(unicode(toLabel, 'utf-8')) newItem.setFont(font) @@ -2293,7 +2303,12 @@ more work your computer must do to send the message. A Time-To-Live of four or f newItem.setIcon(avatarize(toAddress)) self.ui.tableWidgetInbox.setItem(0, 0, newItem) - if fromLabel == '': + if type(account) is MailchuckAccount: + newItem = QtGui.QTableWidgetItem(unicode(account.fromAddress, 'utf-8')) + newItem.setToolTip(unicode(account.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(account.fromAddress, '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'): @@ -2308,7 +2323,7 @@ more work your computer must do to send the message. A Time-To-Live of four or f newItem.setIcon(avatarize(fromAddress)) self.ui.tableWidgetInbox.setItem(0, 1, newItem) newItem = QtGui.QTableWidgetItem(unicode(subject, 'utf-8)')) - newItem.setToolTip(unicode(subject, 'utf-8)')) + newItem.setToolTip(unicode(account.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.setFont(font) self.ui.tableWidgetInbox.setItem(0, 2, newItem) @@ -3272,25 +3287,25 @@ more work your computer must do to send the message. A Time-To-Live of four or f # Group of functions for the Your Identities dialog box def getCurrentAccount(self): - treeWidget = self.getCurrentTreeWidget() + #treeWidget = self.getCurrentTreeWidget() + treeWidget = self.ui.treeWidgetYourIdentities if treeWidget: currentItem = treeWidget.currentItem() if currentItem: - accountFolder = currentItem.data(0, Qt.UserRole).toPyObject() - account = accountFolder[0] - return str(account) + account = currentItem.address + return account else: # TODO need debug msg? return False def getCurrentFolder(self): - treeWidget = self.getCurrentTreeWidget() + #treeWidget = self.getCurrentTreeWidget() + treeWidget = self.ui.treeWidgetYourIdentities if treeWidget: currentItem = treeWidget.currentItem() if currentItem: - accountFolder = currentItem.data(0, Qt.UserRole).toPyObject() - folder = accountFolder[1] - return str(folder) + account = currentItem.folderName + return account else: # TODO need debug msg? return False diff --git a/src/bitmessageqt/account.py b/src/bitmessageqt/account.py new file mode 100644 index 00000000..b8171bc6 --- /dev/null +++ b/src/bitmessageqt/account.py @@ -0,0 +1,63 @@ +from PyQt4 import QtCore, QtGui + +import shared +import re +import sys + +def accountClass(address): + if not shared.config.has_section(address): + return None + try: + gateway = shared.config.get(address, "gateway") + if (gateway == "mailchuck"): + return MailchuckAccount(address) + else: + return GatewayAccount(address) + except: + return BMAccount(address) + +class BMAccount(object): + def __init__(self, address): + self.address = address + + def parseMessage(self, toAddress, fromAddress, subject, message): + self.toAddress = toAddress + self.fromAddress = fromAddress + self.subject = subject + self.message = message + +class GatewayAccount(BMAccount): + def __init__(self, address): + super(BMAccount, self).__init__(address) + + def parseMessage(self, toAddress, fromAddress, subject, message): + super(BMAccount, self).parseMessage(toAddress, fromAddress, subject, message) + +class MailchuckAccount(GatewayAccount): + registrationAddress = "BM-2cVYYrhaY5Gbi3KqrX9Eae2NRNrkfrhCSA" + unregistrationAddress = "BM-2cVMAHTRjZHCTPMue75XBK5Tco175DtJ9J" + relayAddress = "BM-2cWim8aZwUNqxzjMxstnUMtVEUQJeezstf" + regExpIncoming = re.compile("(.*)MAILCHUCK-FROM::(\S+) \| (.*)") + regExpOutgoing = re.compile("(\S+) (.*)") + def __init__(self, address): + super(GatewayAccount, self).__init__(address) + + def parseMessage(self, toAddress, fromAddress, subject, message): + super(GatewayAccount, self).parseMessage(toAddress, fromAddress, subject, message) + if fromAddress == self.relayAddress: + matches = self.regExpIncoming.search(subject) + if not matches is None: + self.subject = "" + if not matches.group(1) is None: + self.subject += matches.group(1) + if not matches.group(3) is None: + self.subject += matches.group(3) + if not matches.group(2) is None: + self.fromAddress = matches.group(2) + if toAddress == self.relayAddress: + matches = self.regExpOutgoing.search(subject) + if not matches is None: + if not matches.group(2) is None: + self.subject = matches.group(2) + if not matches.group(1) is None: + self.toAddress = matches.group(1) \ No newline at end of file diff --git a/src/bitmessageqt/foldertree.py b/src/bitmessageqt/foldertree.py index ca90ad60..78524187 100644 --- a/src/bitmessageqt/foldertree.py +++ b/src/bitmessageqt/foldertree.py @@ -36,7 +36,7 @@ class Ui_FolderWidget(QtGui.QTreeWidgetItem): self.setFont(0, font) self.setText(0, text) self.setToolTip(0, text) - self.setData(0, QtCore.Qt.UserRole, [self.address, self.folderName]) + # self.setData(0, QtCore.Qt.UserRole, [self.address, self.folderName]) # inbox, sent, thrash first, rest alphabetically def __lt__(self, other): @@ -108,7 +108,7 @@ class Ui_AddressWidget(QtGui.QTreeWidgetItem): self.setIcon(0, avatarize(self.address)) self.setText(0, text) self.setToolTip(0, text) - self.setData(0, QtCore.Qt.UserRole, [self.address, "inbox"]) +# self.setData(0, QtCore.Qt.UserRole, [self.address, "inbox"]) def setExpanded(self, expand): super(Ui_AddressWidget, self).setExpanded(expand)