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