Preferences/ConfigurationPages/EmailPage.py

changeset 1032
f7c2e348f6f3
parent 945
8cd4d08fa9f6
child 1061
3e21869872e3
equal deleted inserted replaced
1031:c0f795aa71a7 1032:f7c2e348f6f3
4 # 4 #
5 5
6 """ 6 """
7 Module implementing the Email configuration page. 7 Module implementing the Email configuration page.
8 """ 8 """
9
10 import smtplib
11 import socket
12
13 from PyQt4.QtCore import pyqtSlot, Qt
14 from PyQt4.QtGui import QApplication, QCursor
15
16 from E5Gui import E5MessageBox
9 17
10 from .ConfigurationPageBase import ConfigurationPageBase 18 from .ConfigurationPageBase import ConfigurationPageBase
11 from .Ui_EmailPage import Ui_EmailPage 19 from .Ui_EmailPage import Ui_EmailPage
12 20
13 import Preferences 21 import Preferences
57 Preferences.setUser("MailServerPassword", 65 Preferences.setUser("MailServerPassword",
58 self.mailPasswordEdit.text()) 66 self.mailPasswordEdit.text())
59 Preferences.setUser("MailServerUseTLS", 67 Preferences.setUser("MailServerUseTLS",
60 self.useTlsCheckBox.isChecked()) 68 self.useTlsCheckBox.isChecked())
61 69
70
71 def __updateTestButton(self):
72 """
73 Private slot to update the enabled state of the test button.
74 """
75 self.testButton.setEnabled(
76 self.mailAuthenticationCheckBox.isChecked() and \
77 self.mailUserEdit.text() != "" and \
78 self.mailPasswordEdit.text() != "" and \
79 self.mailServerEdit.text() != ""
80 )
81
82 @pyqtSlot(bool)
83 def on_mailAuthenticationCheckBox_toggled(self, checked):
84 """
85 Private slot to handle a change of the state of the authentication
86 selector.
87
88 @param checked state of the checkbox (boolean)
89 """
90 self.__updateTestButton()
91
92 @pyqtSlot(str)
93 def on_mailUserEdit_textChanged(self, txt):
94 """
95 Private slot to handle a change of the text of the user edit.
96
97 @param txt current text of the edit (string)
98 """
99 self.__updateTestButton()
100
101 @pyqtSlot(str)
102 def on_mailPasswordEdit_textChanged(self, txt):
103 """
104 Private slot to handle a change of the text of the user edit.
105
106 @param txt current text of the edit (string)
107 """
108 self.__updateTestButton()
109
110 @pyqtSlot()
111 def on_testButton_clicked(self):
112 """
113 Private slot to test the mail server login data.
114 """
115 QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
116 QApplication.processEvents()
117 try:
118 server = smtplib.SMTP(self.mailServerEdit.text(),
119 self.portSpin.value(),
120 "", 10)
121 if self.useTlsCheckBox.isChecked():
122 server.starttls()
123 try:
124 server.login(self.mailUserEdit.text(),
125 self.mailPasswordEdit.text())
126 QApplication.restoreOverrideCursor()
127 E5MessageBox.information(self,
128 self.trUtf8("Login Test"),
129 self.trUtf8("""The login test succeeded."""))
130 except (smtplib.SMTPException, socket.error) as e:
131 QApplication.restoreOverrideCursor()
132 if isinstance(e, smtplib.SMTPResponseException):
133 errorStr = e.smtp_error.decode()
134 elif isinstance(e, socket.timeout):
135 errorStr = str(e)
136 elif isinstance(e, socket.error):
137 errorStr = e[1]
138 else:
139 errorStr = str(e)
140 E5MessageBox.critical(self,
141 self.trUtf8("Login Test"),
142 self.trUtf8("""<p>The login test failed.<br>Reason: {0}</p>""")
143 .format(errorStr))
144 server.quit()
145 except (smtplib.SMTPException, socket.error) as e:
146 QApplication.restoreOverrideCursor()
147 if isinstance(e, smtplib.SMTPResponseException):
148 errorStr = e.smtp_error.decode()
149 elif isinstance(e, socket.timeout):
150 errorStr = str(e)
151 elif isinstance(e, socket.error):
152 errorStr = e[1]
153 else:
154 errorStr = str(e)
155 E5MessageBox.critical(self,
156 self.trUtf8("Login Test"),
157 self.trUtf8("""<p>The login test failed.<br>Reason: {0}</p>""")
158 .format(errorStr))
62 159
63 def create(dlg): 160 def create(dlg):
64 """ 161 """
65 Module function to create the configuration page. 162 Module function to create the configuration page.
66 163

eric ide

mercurial