From 1a92db54c95651ecadffeda40f6b085f6809d031 Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Mon, 15 Feb 2016 08:19:45 +0100 Subject: [PATCH] Process gateway registration rejections A message from gateway registration addres regarding registration rejection is processed and a dialog displayed to get a new email address. Fixes #14 --- src/bitmessageqt/__init__.py | 28 +++++++++++++++++++++++++++- src/bitmessageqt/account.py | 7 +++++++ src/bitmessageqt/emailgateway.py | 29 +++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index ee018efb..f971728a 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -2335,7 +2335,20 @@ class MyForm(settingsmixin.SMainWindow): if self.getCurrentAccount() is not None and ((self.getCurrentFolder(treeWidget) != "inbox" and self.getCurrentFolder(treeWidget) is not None) or self.getCurrentAccount(treeWidget) != acct.address): # Ubuntu should notify of new message irespective of whether it's in current message list or not self.ubuntuMessagingMenuUpdate(True, None, acct.toLabel) - return + if hasattr(acct, "feedback") and acct.feedback != GatewayAccount.ALL_OK: + if acct.feedback == GatewayAccount.REGISTRATION_DENIED: + self.dialog = EmailGatewayRegistrationDialog(self, _translate("EmailGatewayRegistrationDialog", "Registration failed:"), + _translate("EmailGatewayRegistrationDialog", "The requested email address is not available, please try a new one. Fill out the new designed email address (including @mailchuck.com) below:") + ) + if self.dialog.exec_(): + email = str(self.dialog.ui.lineEditEmail.text().toUtf8()) + # register resets address variables + acct.register(email) + shared.config.set(acct.fromAddress, 'label', email) + shared.config.set(acct.fromAddress, 'gateway', 'mailchuck') + shared.writeKeysFile() + self.statusBar().showMessage(_translate( + "MainWindow", "Sending email gateway registration request")) def click_pushButtonAddAddressBook(self): self.AddAddressDialogInstance = AddAddressDialog(self) @@ -4309,6 +4322,19 @@ class EmailGatewayDialog(QtGui.QDialog): QtGui.QWidget.resize(self, QtGui.QWidget.sizeHint(self)) +class EmailGatewayRegistrationDialog(QtGui.QDialog): + + def __init__(self, parent, title, label): + QtGui.QWidget.__init__(self, parent) + self.ui = Ui_EmailGatewayRegistrationDialog() + self.ui.setupUi(self) + self.parent = parent + self.setWindowTitle(title) + self.ui.label.setText(label) + + QtGui.QWidget.resize(self, QtGui.QWidget.sizeHint(self)) + + class AddAddressDialog(QtGui.QDialog): def __init__(self, parent): diff --git a/src/bitmessageqt/account.py b/src/bitmessageqt/account.py index 7bf897cf..610b9b46 100644 --- a/src/bitmessageqt/account.py +++ b/src/bitmessageqt/account.py @@ -138,6 +138,8 @@ class BroadcastAccount(BMAccount): class GatewayAccount(BMAccount): gatewayName = None + ALL_OK = 0 + REGISTRATION_DENIED = 1 def __init__(self, address): super(BMAccount, self).__init__(address) @@ -179,6 +181,7 @@ class MailchuckAccount(GatewayAccount): regExpOutgoing = re.compile("(\S+) (.*)") def __init__(self, address): super(GatewayAccount, self).__init__(address) + self.feedback = self.ALL_OK def createMessage(self, toAddress, fromAddress, subject, message): self.subject = toAddress + " " + subject @@ -273,3 +276,7 @@ class MailchuckAccount(GatewayAccount): if not matches.group(1) is None: self.toLabel = matches.group(1) self.toAddress = matches.group(1) + self.feedback = self.ALL_OK + if fromAddress == self.registrationAddress and self.subject == "Registration Request Denied": + self.feedback = self.REGISTRATION_DENIED + return self.feedback diff --git a/src/bitmessageqt/emailgateway.py b/src/bitmessageqt/emailgateway.py index 7fd478ad..664a2b44 100644 --- a/src/bitmessageqt/emailgateway.py +++ b/src/bitmessageqt/emailgateway.py @@ -72,3 +72,32 @@ class Ui_EmailGatewayDialog(object): self.label.setText(QtGui.QApplication.translate("EmailGatewayDialog", "Email gateway allows you to communicate with email users. Currently, only the Mailchuck email gateway (@mailchuck.com) is available.", None, QtGui.QApplication.UnicodeUTF8)) self.label_2.setText(QtGui.QApplication.translate("EmailGatewayDialog", "Desired email address (including @mailchuck.com):", None, QtGui.QApplication.UnicodeUTF8)) + +class Ui_EmailGatewayRegistrationDialog(object): + def setupUi(self, EmailGatewayRegistrationDialog): + EmailGatewayRegistrationDialog.setObjectName(_fromUtf8("EmailGatewayRegistrationDialog")) + EmailGatewayRegistrationDialog.resize(386, 172) + self.gridLayout = QtGui.QGridLayout(EmailGatewayRegistrationDialog) + self.gridLayout.setObjectName(_fromUtf8("gridLayout")) + self.label = QtGui.QLabel(EmailGatewayRegistrationDialog) + self.label.setWordWrap(True) + self.label.setObjectName(_fromUtf8("label")) + self.gridLayout.addWidget(self.label, 0, 0, 1, 1) + self.lineEditEmail = QtGui.QLineEdit(EmailGatewayRegistrationDialog) + self.lineEditEmail.setObjectName(_fromUtf8("lineEditEmail")) + self.gridLayout.addWidget(self.lineEditEmail, 1, 0, 1, 1) + self.buttonBox = QtGui.QDialogButtonBox(EmailGatewayRegistrationDialog) + self.buttonBox.setMinimumSize(QtCore.QSize(368, 0)) + self.buttonBox.setOrientation(QtCore.Qt.Horizontal) + self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok) + self.buttonBox.setObjectName(_fromUtf8("buttonBox")) + self.gridLayout.addWidget(self.buttonBox, 7, 0, 1, 1) + + self.retranslateUi(EmailGatewayRegistrationDialog) + QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("accepted()")), EmailGatewayRegistrationDialog.accept) + QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("rejected()")), EmailGatewayRegistrationDialog.reject) + QtCore.QMetaObject.connectSlotsByName(EmailGatewayRegistrationDialog) + + def retranslateUi(self, EmailGatewayRegistrationDialog): + EmailGatewayRegistrationDialog.setWindowTitle(QtGui.QApplication.translate("EmailGatewayRegistrationDialog", "Email gateway registration", None, QtGui.QApplication.UnicodeUTF8)) + self.label.setText(QtGui.QApplication.translate("EmailGatewayRegistrationDialog", "Email gateway allows you to communicate with email users. Currently, only the Mailchuck email gateway (@mailchuck.com) is available.\nPlease type the desiged email address (including @mailchuck.com) below:", None, QtGui.QApplication.UnicodeUTF8))