UI/EmailDialog.py

changeset 97
c4086afea02b
parent 45
9a18f4dbb493
child 119
071ac17b8179
equal deleted inserted replaced
96:9624a110667d 97:c4086afea02b
5 5
6 """ 6 """
7 Module implementing a dialog to send bug reports. 7 Module implementing a dialog to send bug reports.
8 """ 8 """
9 9
10 import sys
11 import os 10 import os
12 import mimetypes 11 import mimetypes
13 import smtplib 12 import smtplib
14 import socket 13 import socket
15 14
16 from PyQt4.QtCore import * 15 from PyQt4.QtCore import *
17 from PyQt4.QtGui import * 16 from PyQt4.QtGui import *
18 17
19 from .Ui_EmailDialog import Ui_EmailDialog 18 from .Ui_EmailDialog import Ui_EmailDialog
20 19
21 from .Info import Program, Version, BugAddress, FeatureAddress 20 from .Info import BugAddress, FeatureAddress
22 import Preferences 21 import Preferences
23 import Utilities 22 import Utilities
24 23
25 ############################################################ 24 ############################################################
26 ## This code is to work around a bug in the Python email ## 25 ## This code is to work around a bug in the Python email ##
161 """ 160 """
162 Private method to create a simple mail message. 161 Private method to create a simple mail message.
163 162
164 @return string containing the mail message 163 @return string containing the mail message
165 """ 164 """
166 try:
167 import sipconfig
168 sip_version_str = sipconfig.Configuration().sip_version_str
169 except ImportError:
170 sip_version_str = "sip version not available"
171
172 msgtext = "%s\r\n----\r\n%s----\r\n%s----\r\n%s" % \ 165 msgtext = "%s\r\n----\r\n%s----\r\n%s----\r\n%s" % \
173 (self.message.toPlainText(), 166 (self.message.toPlainText(),
174 Utilities.generateVersionInfo("\r\n"), 167 Utilities.generateVersionInfo("\r\n"),
175 Utilities.generatePluginsVersionInfo("\r\n"), 168 Utilities.generatePluginsVersionInfo("\r\n"),
176 Utilities.generateDistroInfo("\r\n")) 169 Utilities.generateDistroInfo("\r\n"))
187 """ 180 """
188 Private method to create a multipart mail message. 181 Private method to create a multipart mail message.
189 182
190 @return string containing the mail message 183 @return string containing the mail message
191 """ 184 """
192 try:
193 import sipconfig
194 sip_version_str = sipconfig.Configuration().sip_version_str
195 except ImportError:
196 sip_version_str = "sip version not available"
197
198 mpPreamble = ("This is a MIME-encoded message with attachments. " 185 mpPreamble = ("This is a MIME-encoded message with attachments. "
199 "If you see this message, your mail client is not " 186 "If you see this message, your mail client is not "
200 "capable of displaying the attachments.") 187 "capable of displaying the attachments.")
201 188
202 msgtext = "%s\r\n----\r\n%s----\r\n%s----\r\n%s" % \ 189 msgtext = "%s\r\n----\r\n%s----\r\n%s----\r\n%s" % \
234 att = MIMEAudio(open(fname, 'rb').read(), _subtype = subtype) 221 att = MIMEAudio(open(fname, 'rb').read(), _subtype = subtype)
235 else: 222 else:
236 att = MIMEBase(maintype, subtype) 223 att = MIMEBase(maintype, subtype)
237 att.set_payload(open(fname, 'rb').read()) 224 att.set_payload(open(fname, 'rb').read())
238 encoders.encode_base64(att) 225 encoders.encode_base64(att)
239 att.add_header('Content-Disposition', 'attachment', filename = fname) 226 att.add_header('Content-Disposition', 'attachment', filename = name)
240 msg.attach(att) 227 msg.attach(att)
241 228
242 return msg.as_string() 229 return msg.as_string()
243 230
244 def __sendmail(self, msg): 231 def __sendmail(self, msg):
282 else: 269 else:
283 return False 270 return False
284 271
285 QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) 272 QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
286 QApplication.processEvents() 273 QApplication.processEvents()
287 result = server.sendmail(Preferences.getUser("Email"), 274 server.sendmail(Preferences.getUser("Email"), self.__toAddress, msg)
288 self.__toAddress, msg)
289 server.quit() 275 server.quit()
290 QApplication.restoreOverrideCursor() 276 QApplication.restoreOverrideCursor()
291 except (smtplib.SMTPException, socket.error) as e: 277 except (smtplib.SMTPException, socket.error) as e:
292 QApplication.restoreOverrideCursor() 278 QApplication.restoreOverrideCursor()
293 res = QMessageBox.critical(self, 279 res = QMessageBox.critical(self,
324 been sent (boolean) 310 been sent (boolean)
325 """ 311 """
326 type = mimetypes.guess_type(fname)[0] 312 type = mimetypes.guess_type(fname)[0]
327 if not type: 313 if not type:
328 type = "application/octet-stream" 314 type = "application/octet-stream"
329 itm = QTreeWidgetItem(self.attachments, [fname, type]) 315 QTreeWidgetItem(self.attachments, [fname, type])
330 self.attachments.header().resizeSections(QHeaderView.ResizeToContents) 316 self.attachments.header().resizeSections(QHeaderView.ResizeToContents)
331 self.attachments.header().setStretchLastSection(True) 317 self.attachments.header().setStretchLastSection(True)
332 318
333 if deleteFile: 319 if deleteFile:
334 self.__deleteFiles.append(fname) 320 self.__deleteFiles.append(fname)

eric ide

mercurial