UI/EmailDialog.py

changeset 6828
bb6667ea9ae7
parent 6825
e659bb96cdfa
child 6834
ae1e7530c854
equal deleted inserted replaced
6825:e659bb96cdfa 6828:bb6667ea9ae7
58 msg.set_payload(encdata) 58 msg.set_payload(encdata)
59 msg['Content-Transfer-Encoding'] = 'base64' 59 msg['Content-Transfer-Encoding'] = 'base64'
60 60
61 encoders.encode_base64 = _encode_base64 61 encoders.encode_base64 = _encode_base64
62 # WORK AROUND: implement our corrected encoder 62 # WORK AROUND: implement our corrected encoder
63 # TODO: check, if this work-around is still needed
63 64
64 65
65 class EmailDialog(QDialog, Ui_EmailDialog): 66 class EmailDialog(QDialog, Ui_EmailDialog):
66 """ 67 """
67 Class implementing a dialog to send bug reports or feature requests. 68 Class implementing a dialog to send bug reports or feature requests.
121 self.message.ensureCursorVisible() 122 self.message.ensureCursorVisible()
122 123
123 self.__deleteFiles = [] 124 self.__deleteFiles = []
124 125
125 self.__helpDialog = None 126 self.__helpDialog = None
127 self.__googleMail = None
126 128
127 def keyPressEvent(self, ev): 129 def keyPressEvent(self, ev):
128 """ 130 """
129 Protected method to handle the user pressing the escape key. 131 Protected method to handle the user pressing the escape key.
130 132
168 if self.__helpDialog is None: 170 if self.__helpDialog is None:
169 try: 171 try:
170 from E5Network.E5GoogleMail import GoogleMailHelp 172 from E5Network.E5GoogleMail import GoogleMailHelp
171 helpStr = GoogleMailHelp() 173 helpStr = GoogleMailHelp()
172 except ImportError: 174 except ImportError:
175 from E5Network.E5GoogleMailHelpers import getInstallCommand
173 helpStr = self.tr( 176 helpStr = self.tr(
174 "<p>The Google Mail Client API is not installed." 177 "<p>The Google Mail Client API is not installed."
175 " Use <code>pip install --upgrade google-api-python-client" 178 " Use <code>{0}</code> to install it.</p>"
176 " google-auth-oauthlib</code> to install it.</p>") 179 ).format(getInstallCommand())
177 180
178 from E5Gui.E5SimpleHelpDialog import E5SimpleHelpDialog 181 from E5Gui.E5SimpleHelpDialog import E5SimpleHelpDialog
179 self.__helpDialog = E5SimpleHelpDialog( 182 self.__helpDialog = E5SimpleHelpDialog(
180 title=self.tr("Gmail API Help"), 183 title=self.tr("Gmail API Help"),
181 helpStr=helpStr, parent=self) 184 helpStr=helpStr, parent=self)
191 msg = self.__createMultipartMail() 194 msg = self.__createMultipartMail()
192 else: 195 else:
193 msg = self.__createSimpleMail() 196 msg = self.__createSimpleMail()
194 197
195 if Preferences.getUser("UseGoogleMailOAuth2"): 198 if Preferences.getUser("UseGoogleMailOAuth2"):
196 ok = self.__sendmailGoogle(msg) 199 self.__sendmailGoogle(msg)
197 else: 200 else:
198 ok = self.__sendmail(msg.as_string()) 201 ok = self.__sendmail(msg.as_string())
199 202 if ok:
200 if ok: 203 self.__deleteAttachedFiles()
201 for f in self.__deleteFiles: 204 self.accept()
202 try: 205
203 os.remove(f) 206 def __deleteAttachedFiles(self):
204 except OSError: 207 """
205 pass 208 Private method to delete attached files.
206 self.accept() 209 """
207 210 for f in self.__deleteFiles:
211 try:
212 os.remove(f)
213 except OSError:
214 pass
215
208 def __encodedText(self, txt): 216 def __encodedText(self, txt):
209 """ 217 """
210 Private method to create a MIMEText message with correct encoding. 218 Private method to create a MIMEText message with correct encoding.
211 219
212 @param txt text to be put into the MIMEText object (string) 220 @param txt text to be put into the MIMEText object (string)
399 """ 407 """
400 Private method to actually send the message via Google Mail. 408 Private method to actually send the message via Google Mail.
401 409
402 @param msg email message to be sent 410 @param msg email message to be sent
403 @type email.mime.text.MIMEBase 411 @type email.mime.text.MIMEBase
404 @return flag indicating success 412 """
405 @rtype bool 413 from E5Network.E5GoogleMail import E5GoogleMail
406 """ 414
407 from E5Network.E5GoogleMail import GoogleMailSendMessage 415 if self.__googleMail is None:
408 QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) 416 self.__googleMail = E5GoogleMail(self)
409 QApplication.processEvents() 417 self.__googleMail.sendResult.connect(self.__gmailSendResult)
410 ok, result = GoogleMailSendMessage(msg) 418
411 QApplication.restoreOverrideCursor() 419 self.__googleMail.sendMessage(msg)
412 if not ok: 420
421 @pyqtSlot(bool, str)
422 def __gmailSendResult(self, ok, message):
423 """
424 Private slot handling the send result reported by the Google Mail
425 interface.
426
427 @param ok flag indicating success
428 @type bool
429 @param message message from the interface
430 @type str
431 """
432 if ok:
433 self.__deleteAttachedFiles()
434 self.accept()
435 else:
413 # we got an error 436 # we got an error
414 E5MessageBox.critical( 437 E5MessageBox.critical(
415 self, 438 self,
416 self.tr("Send Message"), 439 self.tr("Send Message via Gmail"),
417 self.tr( 440 self.tr(
418 """<p>Message could not be sent.<br>Reason: {0}</p>""") 441 """<p>Message could not be sent.<br>Reason: {0}</p>""")
419 .format(result) 442 .format(message)
420 ) 443 )
421
422 return ok
423 444
424 @pyqtSlot() 445 @pyqtSlot()
425 def on_addButton_clicked(self): 446 def on_addButton_clicked(self):
426 """ 447 """
427 Private slot to handle the Add... button. 448 Private slot to handle the Add... button.

eric ide

mercurial