Preferences/ConfigurationPages/EmailPage.py

changeset 5443
3ef014765648
parent 5389
9b1c800daff3
child 5464
1d4f700489f8
--- a/Preferences/ConfigurationPages/EmailPage.py	Wed Jan 25 11:17:04 2017 +0100
+++ b/Preferences/ConfigurationPages/EmailPage.py	Wed Jan 25 12:48:42 2017 +0100
@@ -41,13 +41,18 @@
         self.portSpin.setValue(Preferences.getUser("MailServerPort"))
         self.emailEdit.setText(Preferences.getUser("Email"))
         self.signatureEdit.setPlainText(Preferences.getUser("Signature"))
-        self.mailAuthenticationCheckBox.setChecked(
+        self.mailAuthenticationGroup.setChecked(
             Preferences.getUser("MailServerAuthentication"))
         self.mailUserEdit.setText(Preferences.getUser("MailServerUser"))
         self.mailPasswordEdit.setText(
             Preferences.getUser("MailServerPassword"))
-        self.useTlsCheckBox.setChecked(
-            Preferences.getUser("MailServerUseTLS"))
+        encryption = Preferences.getUser("MailServerEncryption")
+        if encryption == "TLS":
+            self.useTlsButton.setChecked(True)
+        elif encryption == "SSL":
+            self.useSslButton.setChecke(True)
+        else:
+            self.noEncryptionButton.setChecked(True)
         
     def save(self):
         """
@@ -67,35 +72,91 @@
             self.signatureEdit.toPlainText())
         Preferences.setUser(
             "MailServerAuthentication",
-            self.mailAuthenticationCheckBox.isChecked())
+            self.mailAuthenticationGroup.isChecked())
         Preferences.setUser(
             "MailServerUser",
             self.mailUserEdit.text())
         Preferences.setUser(
             "MailServerPassword",
             self.mailPasswordEdit.text())
-        Preferences.setUser(
-            "MailServerUseTLS",
-            self.useTlsCheckBox.isChecked())
+        if self.useTlsButton.isChecked():
+            encryption = "TLS"
+        elif self.useSslButton.isChecked():
+            encryption = "SSL"
+        else:
+            encryption = "No"
+        Preferences.setUser("MailServerEncryption", encryption)
+    
+    def __updatePortSpin(self):
+        """
+        Private slot to set the value of the port spin box depending upon
+        the selected encryption method.
+        """
+        if self.useSslButton.isChecked():
+            self.portSpin.setValue(465)
+        elif self.useTlsButton.isChecked():
+            self.portSpin.setValue(587)
+        else:
+            self.portSpin.setValue(25)
+    
+    @pyqtSlot(bool)
+    def on_noEncryptionButton_toggled(self, checked):
+        """
+        Private slot handling a change of no encryption button.
+        
+        @param checked current state of the button
+        @type bool
+        """
+        self.__updatePortSpin()
+    
+    @pyqtSlot(bool)
+    def on_useSslButton_toggled(self, checked):
+        """
+        Private slot handling a change of SSL encryption button.
+        
+        @param checked current state of the button
+        @type bool
+        """
+        self.__updatePortSpin()
+    
+    @pyqtSlot(bool)
+    def on_useTlsButton_toggled(self, checked):
+        """
+        Private slot handling a change of TLS encryption button.
+        
+        @param checked current state of the button
+        @type bool
+        """
+        self.__updatePortSpin()
     
     def __updateTestButton(self):
         """
         Private slot to update the enabled state of the test button.
         """
         self.testButton.setEnabled(
-            self.mailAuthenticationCheckBox.isChecked() and
+            self.mailAuthenticationGroup.isChecked() and
             self.mailUserEdit.text() != "" and
             self.mailPasswordEdit.text() != "" and
             self.mailServerEdit.text() != ""
         )
     
+    @pyqtSlot(str)
+    def on_mailServerEdit_textChanged(self, txt):
+        """
+        Private slot to handle a change of the text of the mail server edit.
+        
+        @param txt current text of the edit (string)
+        @type str
+        """
+        self.__updateTestButton()
+    
     @pyqtSlot(bool)
-    def on_mailAuthenticationCheckBox_toggled(self, checked):
+    def on_mailAuthenticationGroup_toggled(self, checked):
         """
         Private slot to handle a change of the state of the authentication
-        selector.
+        group.
         
-        @param checked state of the checkbox (boolean)
+        @param checked state of the group (boolean)
         """
         self.__updateTestButton()
     
@@ -125,11 +186,16 @@
         QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
         QApplication.processEvents()
         try:
-            server = smtplib.SMTP(self.mailServerEdit.text(),
-                                  self.portSpin.value(),
-                                  timeout=10)
-            if self.useTlsCheckBox.isChecked():
-                server.starttls()
+            if self.useSslButton.isChecked():
+                server = smtplib.SMTP_SSL(self.mailServerEdit.text(),
+                                          self.portSpin.value(),
+                                          timeout=10)
+            else:
+                server = smtplib.SMTP(self.mailServerEdit.text(),
+                                      self.portSpin.value(),
+                                      timeout=10)
+                if self.useTlsButton.isChecked():
+                    server.starttls()
             try:
                 server.login(self.mailUserEdit.text(),
                              self.mailPasswordEdit.text())

eric ide

mercurial