11 import mimetypes |
11 import mimetypes |
12 import smtplib |
12 import smtplib |
13 import socket |
13 import socket |
14 |
14 |
15 from PyQt4.QtCore import Qt, pyqtSlot, qVersion |
15 from PyQt4.QtCore import Qt, pyqtSlot, qVersion |
16 from PyQt4.QtGui import QCursor, QHeaderView, QLineEdit, QDialog, QInputDialog, \ |
16 from PyQt4.QtGui import QCursor, QHeaderView, QLineEdit, QDialog, \ |
17 QApplication, QDialogButtonBox, QTreeWidgetItem |
17 QInputDialog, QApplication, QDialogButtonBox, QTreeWidgetItem |
18 |
18 |
19 from E5Gui import E5MessageBox, E5FileDialog |
19 from E5Gui import E5MessageBox, E5FileDialog |
20 |
20 |
21 from .Ui_EmailDialog import Ui_EmailDialog |
21 from .Ui_EmailDialog import Ui_EmailDialog |
22 |
22 |
51 orig = msg.get_payload() |
51 orig = msg.get_payload() |
52 encdata = str(_bencode(orig), "ASCII") |
52 encdata = str(_bencode(orig), "ASCII") |
53 msg.set_payload(encdata) |
53 msg.set_payload(encdata) |
54 msg['Content-Transfer-Encoding'] = 'base64' |
54 msg['Content-Transfer-Encoding'] = 'base64' |
55 |
55 |
56 encoders.encode_base64 = _encode_base64 # WORK AROUND: implement our corrected encoder |
56 encoders.encode_base64 = _encode_base64 # WORK AROUND: implement our |
|
57 # corrected encoder |
57 |
58 |
58 |
59 |
59 class EmailDialog(QDialog, Ui_EmailDialog): |
60 class EmailDialog(QDialog, Ui_EmailDialog): |
60 """ |
61 """ |
61 Class implementing a dialog to send bug reports. |
62 Class implementing a dialog to send bug reports. |
82 self.msgLabel.setText(self.trUtf8( |
83 self.msgLabel.setText(self.trUtf8( |
83 "Enter your &bug description below." |
84 "Enter your &bug description below." |
84 " Version information is added automatically.")) |
85 " Version information is added automatically.")) |
85 self.__toAddress = BugAddress |
86 self.__toAddress = BugAddress |
86 |
87 |
87 self.sendButton = \ |
88 self.sendButton = self.buttonBox.addButton( |
88 self.buttonBox.addButton(self.trUtf8("Send"), QDialogButtonBox.ActionRole) |
89 self.trUtf8("Send"), QDialogButtonBox.ActionRole) |
89 self.sendButton.setEnabled(False) |
90 self.sendButton.setEnabled(False) |
90 self.sendButton.setDefault(True) |
91 self.sendButton.setDefault(True) |
91 |
92 |
92 height = self.height() |
93 height = self.height() |
93 self.mainSplitter.setSizes([int(0.7 * height), int(0.3 * height)]) |
94 self.mainSplitter.setSizes([int(0.7 * height), int(0.3 * height)]) |
94 |
95 |
95 self.attachments.headerItem().setText(self.attachments.columnCount(), "") |
96 self.attachments.headerItem().setText( |
|
97 self.attachments.columnCount(), "") |
96 if qVersion() >= "5.0.0": |
98 if qVersion() >= "5.0.0": |
97 self.attachments.header().setSectionResizeMode(QHeaderView.Interactive) |
99 self.attachments.header().setSectionResizeMode( |
|
100 QHeaderView.Interactive) |
98 else: |
101 else: |
99 self.attachments.header().setResizeMode(QHeaderView.Interactive) |
102 self.attachments.header().setResizeMode(QHeaderView.Interactive) |
100 |
103 |
101 sig = Preferences.getUser("Signature") |
104 sig = Preferences.getUser("Signature") |
102 if sig: |
105 if sig: |
249 try: |
252 try: |
250 txt.encode("us-ascii") |
253 txt.encode("us-ascii") |
251 att = MIMEText(txt, _subtype=subtype) |
254 att = MIMEText(txt, _subtype=subtype) |
252 except UnicodeEncodeError: |
255 except UnicodeEncodeError: |
253 att = MIMEText( |
256 att = MIMEText( |
254 txt.encode("utf-8"), _subtype=subtype, _charset="utf-8") |
257 txt.encode("utf-8"), _subtype=subtype, |
|
258 _charset="utf-8") |
255 elif maintype == 'image': |
259 elif maintype == 'image': |
256 att = MIMEImage(open(fname, 'rb').read(), _subtype=subtype) |
260 att = MIMEImage(open(fname, 'rb').read(), _subtype=subtype) |
257 elif maintype == 'audio': |
261 elif maintype == 'audio': |
258 att = MIMEAudio(open(fname, 'rb').read(), _subtype=subtype) |
262 att = MIMEAudio(open(fname, 'rb').read(), _subtype=subtype) |
259 else: |
263 else: |
297 errorStr = e[1] |
301 errorStr = e[1] |
298 else: |
302 else: |
299 errorStr = str(e) |
303 errorStr = str(e) |
300 res = E5MessageBox.retryAbort(self, |
304 res = E5MessageBox.retryAbort(self, |
301 self.trUtf8("Send bug report"), |
305 self.trUtf8("Send bug report"), |
302 self.trUtf8("""<p>Authentication failed.<br>Reason: {0}</p>""") |
306 self.trUtf8( |
|
307 """<p>Authentication failed.<br>Reason: {0}</p>""") |
303 .format(errorStr), |
308 .format(errorStr), |
304 E5MessageBox.Critical) |
309 E5MessageBox.Critical) |
305 if res: |
310 if res: |
306 return self.__sendmail(msg) |
311 return self.__sendmail(msg) |
307 else: |
312 else: |
308 return False |
313 return False |
309 |
314 |
310 QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) |
315 QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) |
311 QApplication.processEvents() |
316 QApplication.processEvents() |
312 server.sendmail(Preferences.getUser("Email"), self.__toAddress, msg) |
317 server.sendmail(Preferences.getUser("Email"), self.__toAddress, |
|
318 msg) |
313 server.quit() |
319 server.quit() |
314 QApplication.restoreOverrideCursor() |
320 QApplication.restoreOverrideCursor() |
315 except (smtplib.SMTPException, socket.error) as e: |
321 except (smtplib.SMTPException, socket.error) as e: |
316 QApplication.restoreOverrideCursor() |
322 QApplication.restoreOverrideCursor() |
317 if isinstance(e, smtplib.SMTPResponseException): |
323 if isinstance(e, smtplib.SMTPResponseException): |
320 errorStr = e[1] |
326 errorStr = e[1] |
321 else: |
327 else: |
322 errorStr = str(e) |
328 errorStr = str(e) |
323 res = E5MessageBox.retryAbort(self, |
329 res = E5MessageBox.retryAbort(self, |
324 self.trUtf8("Send bug report"), |
330 self.trUtf8("Send bug report"), |
325 self.trUtf8("""<p>Message could not be sent.<br>Reason: {0}</p>""") |
331 self.trUtf8( |
|
332 """<p>Message could not be sent.<br>Reason: {0}</p>""") |
326 .format(errorStr), |
333 .format(errorStr), |
327 E5MessageBox.Critical) |
334 E5MessageBox.Critical) |
328 if res: |
335 if res: |
329 return self.__sendmail(msg) |
336 return self.__sendmail(msg) |
330 else: |
337 else: |