Preferences/ConfigurationPages/EmailPage.py

changeset 5443
3ef014765648
parent 5389
9b1c800daff3
child 5464
1d4f700489f8
equal deleted inserted replaced
5442:43d42a54cf50 5443:3ef014765648
39 # set initial values 39 # set initial values
40 self.mailServerEdit.setText(Preferences.getUser("MailServer")) 40 self.mailServerEdit.setText(Preferences.getUser("MailServer"))
41 self.portSpin.setValue(Preferences.getUser("MailServerPort")) 41 self.portSpin.setValue(Preferences.getUser("MailServerPort"))
42 self.emailEdit.setText(Preferences.getUser("Email")) 42 self.emailEdit.setText(Preferences.getUser("Email"))
43 self.signatureEdit.setPlainText(Preferences.getUser("Signature")) 43 self.signatureEdit.setPlainText(Preferences.getUser("Signature"))
44 self.mailAuthenticationCheckBox.setChecked( 44 self.mailAuthenticationGroup.setChecked(
45 Preferences.getUser("MailServerAuthentication")) 45 Preferences.getUser("MailServerAuthentication"))
46 self.mailUserEdit.setText(Preferences.getUser("MailServerUser")) 46 self.mailUserEdit.setText(Preferences.getUser("MailServerUser"))
47 self.mailPasswordEdit.setText( 47 self.mailPasswordEdit.setText(
48 Preferences.getUser("MailServerPassword")) 48 Preferences.getUser("MailServerPassword"))
49 self.useTlsCheckBox.setChecked( 49 encryption = Preferences.getUser("MailServerEncryption")
50 Preferences.getUser("MailServerUseTLS")) 50 if encryption == "TLS":
51 self.useTlsButton.setChecked(True)
52 elif encryption == "SSL":
53 self.useSslButton.setChecke(True)
54 else:
55 self.noEncryptionButton.setChecked(True)
51 56
52 def save(self): 57 def save(self):
53 """ 58 """
54 Public slot to save the Email configuration. 59 Public slot to save the Email configuration.
55 """ 60 """
65 Preferences.setUser( 70 Preferences.setUser(
66 "Signature", 71 "Signature",
67 self.signatureEdit.toPlainText()) 72 self.signatureEdit.toPlainText())
68 Preferences.setUser( 73 Preferences.setUser(
69 "MailServerAuthentication", 74 "MailServerAuthentication",
70 self.mailAuthenticationCheckBox.isChecked()) 75 self.mailAuthenticationGroup.isChecked())
71 Preferences.setUser( 76 Preferences.setUser(
72 "MailServerUser", 77 "MailServerUser",
73 self.mailUserEdit.text()) 78 self.mailUserEdit.text())
74 Preferences.setUser( 79 Preferences.setUser(
75 "MailServerPassword", 80 "MailServerPassword",
76 self.mailPasswordEdit.text()) 81 self.mailPasswordEdit.text())
77 Preferences.setUser( 82 if self.useTlsButton.isChecked():
78 "MailServerUseTLS", 83 encryption = "TLS"
79 self.useTlsCheckBox.isChecked()) 84 elif self.useSslButton.isChecked():
85 encryption = "SSL"
86 else:
87 encryption = "No"
88 Preferences.setUser("MailServerEncryption", encryption)
89
90 def __updatePortSpin(self):
91 """
92 Private slot to set the value of the port spin box depending upon
93 the selected encryption method.
94 """
95 if self.useSslButton.isChecked():
96 self.portSpin.setValue(465)
97 elif self.useTlsButton.isChecked():
98 self.portSpin.setValue(587)
99 else:
100 self.portSpin.setValue(25)
101
102 @pyqtSlot(bool)
103 def on_noEncryptionButton_toggled(self, checked):
104 """
105 Private slot handling a change of no encryption button.
106
107 @param checked current state of the button
108 @type bool
109 """
110 self.__updatePortSpin()
111
112 @pyqtSlot(bool)
113 def on_useSslButton_toggled(self, checked):
114 """
115 Private slot handling a change of SSL encryption button.
116
117 @param checked current state of the button
118 @type bool
119 """
120 self.__updatePortSpin()
121
122 @pyqtSlot(bool)
123 def on_useTlsButton_toggled(self, checked):
124 """
125 Private slot handling a change of TLS encryption button.
126
127 @param checked current state of the button
128 @type bool
129 """
130 self.__updatePortSpin()
80 131
81 def __updateTestButton(self): 132 def __updateTestButton(self):
82 """ 133 """
83 Private slot to update the enabled state of the test button. 134 Private slot to update the enabled state of the test button.
84 """ 135 """
85 self.testButton.setEnabled( 136 self.testButton.setEnabled(
86 self.mailAuthenticationCheckBox.isChecked() and 137 self.mailAuthenticationGroup.isChecked() and
87 self.mailUserEdit.text() != "" and 138 self.mailUserEdit.text() != "" and
88 self.mailPasswordEdit.text() != "" and 139 self.mailPasswordEdit.text() != "" and
89 self.mailServerEdit.text() != "" 140 self.mailServerEdit.text() != ""
90 ) 141 )
91 142
92 @pyqtSlot(bool) 143 @pyqtSlot(str)
93 def on_mailAuthenticationCheckBox_toggled(self, checked): 144 def on_mailServerEdit_textChanged(self, txt):
145 """
146 Private slot to handle a change of the text of the mail server edit.
147
148 @param txt current text of the edit (string)
149 @type str
150 """
151 self.__updateTestButton()
152
153 @pyqtSlot(bool)
154 def on_mailAuthenticationGroup_toggled(self, checked):
94 """ 155 """
95 Private slot to handle a change of the state of the authentication 156 Private slot to handle a change of the state of the authentication
96 selector. 157 group.
97 158
98 @param checked state of the checkbox (boolean) 159 @param checked state of the group (boolean)
99 """ 160 """
100 self.__updateTestButton() 161 self.__updateTestButton()
101 162
102 @pyqtSlot(str) 163 @pyqtSlot(str)
103 def on_mailUserEdit_textChanged(self, txt): 164 def on_mailUserEdit_textChanged(self, txt):
123 Private slot to test the mail server login data. 184 Private slot to test the mail server login data.
124 """ 185 """
125 QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) 186 QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
126 QApplication.processEvents() 187 QApplication.processEvents()
127 try: 188 try:
128 server = smtplib.SMTP(self.mailServerEdit.text(), 189 if self.useSslButton.isChecked():
129 self.portSpin.value(), 190 server = smtplib.SMTP_SSL(self.mailServerEdit.text(),
130 timeout=10) 191 self.portSpin.value(),
131 if self.useTlsCheckBox.isChecked(): 192 timeout=10)
132 server.starttls() 193 else:
194 server = smtplib.SMTP(self.mailServerEdit.text(),
195 self.portSpin.value(),
196 timeout=10)
197 if self.useTlsButton.isChecked():
198 server.starttls()
133 try: 199 try:
134 server.login(self.mailUserEdit.text(), 200 server.login(self.mailUserEdit.text(),
135 self.mailPasswordEdit.text()) 201 self.mailPasswordEdit.text())
136 QApplication.restoreOverrideCursor() 202 QApplication.restoreOverrideCursor()
137 E5MessageBox.information( 203 E5MessageBox.information(

eric ide

mercurial