14 import socket |
14 import socket |
15 |
15 |
16 from PyQt4.QtCore import * |
16 from PyQt4.QtCore import * |
17 from PyQt4.QtGui import * |
17 from PyQt4.QtGui import * |
18 |
18 |
19 from Ui_EmailDialog import Ui_EmailDialog |
19 from .Ui_EmailDialog import Ui_EmailDialog |
20 |
20 |
21 from Info import Program, Version, BugAddress, FeatureAddress |
21 from .Info import Program, Version, BugAddress, FeatureAddress |
22 import Preferences |
22 import Preferences |
23 import Utilities |
23 import Utilities |
24 |
24 |
25 from email import Encoders |
25 from email import encoders |
26 from email.MIMEBase import MIMEBase |
26 from email.mime.base import MIMEBase |
27 from email.MIMEText import MIMEText |
27 from email.mime.text import MIMEText |
28 from email.MIMEImage import MIMEImage |
28 from email.mime.image import MIMEImage |
29 from email.MIMEAudio import MIMEAudio |
29 from email.mime.audio import MIMEAudio |
30 from email.MIMEMultipart import MIMEMultipart |
30 from email.mime.multipart import MIMEMultipart |
31 |
31 |
32 class EmailDialog(QDialog, Ui_EmailDialog): |
32 class EmailDialog(QDialog, Ui_EmailDialog): |
33 """ |
33 """ |
34 Class implementing a dialog to send bug reports. |
34 Class implementing a dialog to send bug reports. |
35 """ |
35 """ |
213 elif maintype == 'audio': |
213 elif maintype == 'audio': |
214 att = MIMEAudio(open(fname, 'rb').read(), _subtype = subtype) |
214 att = MIMEAudio(open(fname, 'rb').read(), _subtype = subtype) |
215 else: |
215 else: |
216 att = MIMEBase(maintype, subtype) |
216 att = MIMEBase(maintype, subtype) |
217 att.set_payload(open(fname, 'rb').read()) |
217 att.set_payload(open(fname, 'rb').read()) |
218 Encoders.encode_base64(att) |
218 encoders.encode_base64(att) |
219 att.add_header('Content-Disposition', 'attachment', filename = fname) |
219 att.add_header('Content-Disposition', 'attachment', filename = fname) |
220 msg.attach(att) |
220 msg.attach(att) |
221 |
221 |
222 return msg.as_string() |
222 return msg.as_string() |
223 |
223 |
246 # abort |
246 # abort |
247 return False |
247 return False |
248 try: |
248 try: |
249 server.login(Preferences.getUser("MailServerUser"), |
249 server.login(Preferences.getUser("MailServerUser"), |
250 password) |
250 password) |
251 except (smtplib.SMTPException, socket.error), e: |
251 except (smtplib.SMTPException, socket.error) as e: |
252 res = QMessageBox.critical(self, |
252 res = QMessageBox.critical(self, |
253 self.trUtf8("Send bug report"), |
253 self.trUtf8("Send bug report"), |
254 self.trUtf8("""<p>Authentication failed.<br>Reason: {0}</p>""") |
254 self.trUtf8("""<p>Authentication failed.<br>Reason: {0}</p>""") |
255 .format(unicode(e)), |
255 .format(str(e)), |
256 QMessageBox.StandardButtons(\ |
256 QMessageBox.StandardButtons(\ |
257 QMessageBox.Abort | \ |
257 QMessageBox.Abort | \ |
258 QMessageBox.Retry), |
258 QMessageBox.Retry), |
259 QMessageBox.Retry) |
259 QMessageBox.Retry) |
260 if res == QMessageBox.Retry: |
260 if res == QMessageBox.Retry: |
266 QApplication.processEvents() |
266 QApplication.processEvents() |
267 result = server.sendmail(Preferences.getUser("Email"), |
267 result = server.sendmail(Preferences.getUser("Email"), |
268 self.__toAddress, msg) |
268 self.__toAddress, msg) |
269 server.quit() |
269 server.quit() |
270 QApplication.restoreOverrideCursor() |
270 QApplication.restoreOverrideCursor() |
271 except (smtplib.SMTPException, socket.error), e: |
271 except (smtplib.SMTPException, socket.error) as e: |
272 QApplication.restoreOverrideCursor() |
272 QApplication.restoreOverrideCursor() |
273 res = QMessageBox.critical(self, |
273 res = QMessageBox.critical(self, |
274 self.trUtf8("Send bug report"), |
274 self.trUtf8("Send bug report"), |
275 self.trUtf8("""<p>Message could not be sent.<br>Reason: {0}</p>""") |
275 self.trUtf8("""<p>Message could not be sent.<br>Reason: {0}</p>""") |
276 .format(unicode(e)), |
276 .format(str(e)), |
277 QMessageBox.StandardButtons(\ |
277 QMessageBox.StandardButtons(\ |
278 QMessageBox.Abort | \ |
278 QMessageBox.Abort | \ |
279 QMessageBox.Retry), |
279 QMessageBox.Retry), |
280 QMessageBox.Retry) |
280 QMessageBox.Retry) |
281 if res == QMessageBox.Retry: |
281 if res == QMessageBox.Retry: |