Beispiel #1
0
    def on_sync_clicked(self):
        self.receive = GetJsonInfo(self.receiveJsonName)
        self.contacts = GetJsonInfo(self.contactsJsonName)
        for item in self.receive:
            if self.receive[item]['fromAddr'] not in self.contacts:
                emailAddr = self.receive[item]['fromAddr']
                temp = {
                    emailAddr: {
                        'fromAddr': emailAddr,
                        'name': self.receive[item]['name']
                    }
                }
                self.contacts.update(temp)
        SaveJsonInfo(self.contactsJsonName, self.contacts)

        self.contactsList.clear()
        for x in self.contacts:
            if x != self.emailInfo['email']:
                item = QtGui.QListWidgetItem()
                item.setTextAlignment(QtCore.Qt.AlignLeading
                                      | QtCore.Qt.AlignVCenter)
                icon3 = QtGui.QIcon()
                num = self.generateNum(x)
                icon3.addPixmap(QtGui.QPixmap(":/avatar/Avatars/%d.jpg" % num),
                                QtGui.QIcon.Normal, QtGui.QIcon.Off)
                item.setIcon(icon3)

                my_contact = self.contacts[x]['name'] + '\n' + self.contacts[
                    x]['fromAddr']
                item.setText(my_contact)
                self.contactsList.addItem(item)

        QMessageBox.information(self, '同步联系人', u'同步成功', 'ok')
Beispiel #2
0
    def on_delContact_clicked(self):
        # 获取邮箱地址
        contEmail = self.contEmail.text()
        if contEmail:
            isDel = QMessageBox.information(self, '删除联系人', u'确定要删除该联系人?',
                                            'Yes', 'Cancel')
            if not isDel:
                # 获取邮箱地址
                contEmail = self.contEmail.text()
                # 获取联系人数据
                self.contacts = GetJsonInfo(self.contactsJsonName)
                self.contacts.pop(contEmail)

                # 联系人数据回写
                SaveJsonInfo(self.contactsJsonName, self.contacts)

                self.contName.setText('')
                self.contEmail.setText('')
                self.contLogo.setStyleSheet("")
                self.contRemarkName.setText('')
                self.contPhone.setText('')
                self.contQQ.setText('')
                self.contWechat.setText('')

                self.contactsList.takeItem(self.contactsList.currentRow())
        else:
            QMessageBox.information(self, '删除联系人', u'请先选择要删除的联系人', 'ok')
Beispiel #3
0
    def on_restoreEmail_clicked(self):
        # Yes:0 Cancel:1
        isRestore = QMessageBox.information(self, '恢复邮件', u'确定要恢复该封邮件?', 'Yes',
                                            'Cancel')
        if not isRestore:
            # 获取主题名
            my_subject = self.contEmailSubject.text()
            self.receive = GetJsonInfo(self.receiveJsonName)
            self.delete = GetJsonInfo(self.deleteJsonName)

            temp = {my_subject: self.delete[my_subject]}
            print(temp)
            # 将删除邮件恢复至receive.json文件中
            self.receive.update(temp)
            # self.isReceived.update(temp)

            # 将邮件从delete.json中去除
            self.delete.pop(my_subject)
            self.isDeleted.pop(my_subject)

            # 数据回写
            SaveJsonInfo(self.receiveJsonName, self.receive)
            SaveJsonInfo(self.deleteJsonName, self.delete)

            self.deleteList.takeItem(self.deleteList.currentRow())
            self.addQList(self.receive, 'emaillist')

            self.contEmail.setText('')
            self.contEmailTime.setText('')
            self.contEmailSubject.setText('')
            self.contName.setText('')
            self.emailShow.setUrl(QtCore.QUrl("qrc:/souce/index.html"))

            self.mainForward.hide()
            self.delEmail.hide()
Beispiel #4
0
    def on_delEmail_clicked(self):
        isDel = QMessageBox.information(self, '删除邮件', u'确定要删除该封邮件?', 'Yes',
                                        'Cancel')
        if self.item_enable_delete:
            if not isDel:
                # 获取主题名
                my_subject = self.contEmailSubject.text()
                self.receive = GetJsonInfo(self.receiveJsonName)
                self.delete = GetJsonInfo(self.deleteJsonName)

                # 将删除邮件存至delete.json文件中
                temp = {my_subject: self.receive[my_subject]}
                print(temp)
                self.delete.update(temp)
                # self.isDeleted.update(temp)

                # 将邮件从receive.json中去除
                self.receive.pop(my_subject)
                self.isReceived.pop(my_subject)

                # 数据回写
                SaveJsonInfo(self.receiveJsonName, self.receive)
                SaveJsonInfo(self.deleteJsonName, self.delete)

                self.contEmail.setText('')
                self.contEmailTime.setText('')
                self.contEmailSubject.setText('')
                self.contName.setText('')
                self.emailShow.setUrl(QtCore.QUrl("qrc:/souce/index.html"))

                self.emaillist.takeItem(self.emaillist.currentRow())
                self.item_enable_delete = False
                self.mainForward.hide()
                self.delEmail.hide()
                self.addQList(self.delete, 'deleteList')
Beispiel #5
0
 def on_mainSearch_clicked(self):
     if self.searchMode.currentText() == '请选择':
         my_alert = QMessageBox.warning(self, '搜索失败', u'请选择一种搜索模式')
     else:
         keyword = self.searchlineEdit.text()  # 获取搜索关键字
         if keyword:
             self.userInfo = GetJsonInfo('conf.json')
             self.receive = GetJsonInfo(self.receiveJsonName)
             self.emaillist.hide()
             self.sentList.hide()
             self.deleteList.hide()
             self.draftList.hide()
             self.searchList.show()
             begin = time.time()
             test = Search()
             test.run(self.userInfo, self.searchMode.currentText(), keyword)
             files = test.getResult()
             while files == None:
                 files = test.getResult()
             print("2", files)
             self.searchList.clear()
             if len(files) > 0:
                 self.addQList(files, 'searchList')
             else:
                 self.addQList(
                     {
                         "搜索结果为空": {
                             "date": "",
                             "subject": "搜索结果为空",
                             "name": ""
                         }
                     }, 'searchList')
             print("耗时啥都不用2:", time.time() - begin)
         else:
             my_alert = QMessageBox.warning(self, '搜索失败', u'搜索内容不能为空!')
Beispiel #6
0
    def on_mainlogin_clicked(self):
        self.hide()
        my_login = Login()
        my_login.exec_()
        self.emailInfo = GetJsonInfo('conf.json')
        if self.emailInfo['status'] == 1:
            self.mainUserName.setText(self.emailInfo['email'])
            self.mainlogin.setText('切换')
            self.emaillist.clear()
            self.login = 1
            self.show()
            # 获取当前文件的绝对路径
            abDir = os.path.abspath(os.path.join(
                os.path.dirname(__file__))).replace('\\', '/')
            dir = "%s/data/%s/" % (abDir, self.emailInfo['email'])
            self.receiveJsonName = dir + "receive.json"
            self.sendJsonName = dir + "send.json"
            self.deleteJsonName = dir + "delete.json"
            self.draftJsonName = dir + "draft.json"
            self.isReceived = {}
            self.isDeleted = {}
            self.isDraft = {}
            self.isSent = {}
            self.addQList(GetJsonInfo(self.receiveJsonName), 'emaillist')

            num = self.generateNum(self.emailInfo['email'])
            self.headlogo.setStyleSheet('''
			background-color: rgb(242, 242, 242);
			border-radius:40px;
			border-image: url(:/avatar/Avatars/%d.jpg);
			''' % num)
Beispiel #7
0
 def on_contSave_clicked(self):
     email = self.contEmail.text()
     name = self.contName.text()
     if email and name:
         remark = self.contRemarkName.text()
         phone = self.contPhone.text()
         qq = self.contQQ.text()
         weChat = self.contWechat.text()
         self.contacts = GetJsonInfo(self.contactsJsonName)
         temp = {
             email: {
                 'name': name,
                 'fromAddr': email,
                 'remark': remark,
                 'phone': phone,
                 'qq': qq,
                 'weChat': weChat
             }
         }
         self.contacts.update(temp)
         SaveJsonInfo(self.contactsJsonName, self.contacts)
         self.createAlert.hide()
         self.must1.hide()
         self.must2.hide()
         QMessageBox.information(self, '保存联系人', u'保存成功', 'ok')
     else:
         QMessageBox.information(self, '保存联系人', u'用户名和邮箱不能为空!', 'ok')
Beispiel #8
0
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.setupUi(self)
        self.setWindowFlags(Qt.FramelessWindowHint | Qt.Dialog)
        # 邮件数量
        self.index = 0
        self.page = 0
        # 判断是否已经的登录邮箱,若已经登录才能进行后续操作
        self.login = 0

        # 登录上次账号
        try:
            start = time.time()
            self.emailInfo = GetJsonInfo('conf.json')
            server = smtplib.SMTP_SSL(self.emailInfo["smtp_server"], 465)
            server.set_debuglevel(1)
            print('\n***************************************\n\n')
            server.login(self.emailInfo["email"], self.emailInfo["pwd"])
            self.emailInfo["status"] = 1
            SaveJsonInfo('conf.json', self.emailInfo)

            end = time.time()
            print('耗时:' + str(end - start))
            self.mainUserName.setText(self.emailInfo['email'])
            self.mainlogin.setText('切换账号')
            self.login = 1

        except Exception as e:
            print(e)
            self.emailInfo = {
                "pop3_server": "",
                "email": "",
                "pwd": "",
                "smtp_server": "",
                "status": 0
            }
            SaveJsonInfo('conf.json', self.emailInfo)

        self.emailInfo = GetJsonInfo('conf.json')
        self.attachList.hide()
        self.mainForward.hide()
        self.delEmail.hide()
        self.mainReply.hide()
        self.mainAttach.hide()

        # 绑定emailList
        self.connect(self.emaillist, SIGNAL('itemClicked(QListWidgetItem *)'),
                     self.emailItemClicked)

        # 绑定attachList
        self.connect(self.attachList, SIGNAL('itemClicked(QListWidgetItem *)'),
                     self.attachItemClicked)

        # 绑定searchList
        self.connect(self.searchList, SIGNAL('itemClicked(QListWidgetItem *)'),
                     self.searchItemClicked)
Beispiel #9
0
    def on_login_clicked(self):
        # 登录
        self.run()

        self.emailInfo = GetJsonInfo('conf.json')
        if self.emailInfo['status'] == 0:
            alert = QMessageBox.warning(self, '登录失败', u'登录失败,请检查配置是否正确!')
            self.resize(500, 370)
        else:
            # 创建一个以邮件命名的文件夹,用于区分用户信息
            dir = '/data/%s' % (self.emailInfo['email'])
            # 获取当前文件的绝对路径
            abDir = os.path.abspath(os.path.join(
                os.path.dirname(__file__))).replace('\\', '/')
            dir = abDir + dir
            if not os.path.exists(dir):
                os.mkdir(dir)
                # 创建用户邮件信息记录文件
                files = ['receive', 'send', 'delete', 'draft', 'contacts']
                for file in files:
                    file = "%s/%s.json" % (dir, file)
                    SaveJsonInfo(file, {})
                os.mkdir(dir + '/receive')
                os.mkdir(dir + '/send')
                os.mkdir(dir + '/draft')
                print("文件夹创建成功:%s" % dir)

            self.close()
Beispiel #10
0
	def __init__(self, parent=None,isForwad=False,ForwardInfo=None,url=None,\
	isReply=False,replyInfo=None):
		super(WriteEmailDialog, self).__init__(parent)
		self.setupUi(self)
		self.emailInfo = GetJsonInfo('conf.json')
		self.email = SendMail(From = self.emailInfo['email'],
						pwd = self.emailInfo['pwd'],
						smtp_server = self.emailInfo['smtp_server'])
		self.isForwad = isForwad
		self.isReply = isReply
		if self.isForwad:
			self.emailText = GetEmailText(url)
			self.formatText = '''\n\n\n\n- 发送自XYZ邮箱 -\n-------- 转发的邮件 --------\n发件人: "%s" %s\n日期: %s\n主题: %s\n'''\
			%(ForwardInfo['email'],
				ForwardInfo['name'],
				ForwardInfo['time'],
				ForwardInfo['subject'])
			self.emailContent.setPlainText(self.formatText)

			# 将转发信息格式化
			str1 = self.formatText.split('-\n')
			str2 = str1[2].split('\n')
			str3 = (str1[0]+'-',str1[1]+'-',str2[0],str2[1],str2[2])
			self.formatText = '<div>%s<br>%s<br>%s<br>%s<br>%s<br><div>\
			</div><div style="clear:both;"></div>'% str3

		if self.isReply:
			self.receiverEdit.setText(replyInfo['reply_addr'])
			self.subjectEdit.setText(replyInfo['reply_subject'])
Beispiel #11
0
    def emailItemClicked(self):
        try:
            self.currentFolder = 'receive'
            self.item_enable_delete = True  # 点击一个元素,可删除
            my_receive = GetJsonInfo(self.receiveJsonName)
            my_currentItem = self.emaillist.currentItem()
            my_text = my_currentItem.text().split('主题:')[1].split('\n')[0]

            url = 'file:///' + os.path.abspath(
                os.path.join(os.path.dirname(__file__))
            ) + r'/data/%s/%s.html' % (self.emailInfo['email'], my_text)
            url = url.replace('\\', '/')
            print(url)

            num = self.generateNum(my_currentItem.text().split('联系人:')[1])
            self.contLogo.setStyleSheet(
                "border-image: url(:/avatar/Avatars/%d.jpg);" % num)

            self.contName.setText(my_receive[my_text]['name'])
            self.contEmail.setText(my_receive[my_text]['fromAddr'])
            self.contEmailTime.setText(my_receive[my_text]['date'])
            self.contEmailSubject.setText(my_text)
            self.mainForward.show()
            self.delEmail.show()
            self.mainReply.show()
            self.mainAttach.show()
            self.emailShow.setUrl(QtCore.QUrl(url))
            self.attachList.hide()
        except Exception as e:
            print(str(e))
Beispiel #12
0
 def searchName(self, name):
     contacts = GetJsonInfo('contacts.json')
     files = {}
     temp = name.lower()
     for item in contacts:
         if temp in contacts[item]['name'].lower():
             files[item] = contacts[item]
     return files
Beispiel #13
0
    def __init__(self, parent=None):
        super(contacts, self).__init__(parent)
        self.setupUi(self)
        self.setWindowFlags(Qt.FramelessWindowHint | Qt.Dialog)
        self.emailInfo = GetJsonInfo('conf.json')
        self.contacts = GetJsonInfo('contacts.json')
        self.contUserMail.setText(self.emailInfo["email"])

        # 绑定QListWidget
        self.connect(self.contactsList,
                     SIGNAL('itemClicked(QListWidgetItem *)'),
                     self.itemClicked)

        for item in self.contacts:
            my_contact = self.contacts[item]['name'] + '\n' + self.contacts[
                item]['fromAddr']
            self.contactsList.addItem(my_contact)
Beispiel #14
0
 def on_delEmail_clicked(self):
     isDel = QMessageBox.information(self, '删除邮件', u'确定要删除该封邮件?', 'Yes',
                                     'Cancel')
     if self.item_enable_delete:
         if not isDel:
             my_subject = self.contEmailSubject.text()
             self.contacts = GetJsonInfo('contacts.json')
             self.contEmail.setText('')
             self.contEmailTime.setText('')
             self.contEmailSubject.setText('')
             self.contName.setText('')
             self.emailShow.setUrl(QtCore.QUrl("qrc:/souce/index.html"))
             self.contacts.pop(my_subject)
             self.emaillist.takeItem(self.emaillist.currentRow())
             self.item_enable_delete = False
             self.mainForward.hide()
             self.delEmail.hide()
Beispiel #15
0
 def searchDate(self, date):
     contacts = GetJsonInfo(self.receiveJsonName)
     files = {}
     temp = date.lower()
     for item in contacts:
         if temp in contacts[item]['date'].lower():
             files[item] = contacts[item]
     return files
Beispiel #16
0
 def searchEmailAddr(self, email):
     contacts = GetJsonInfo(self.receiveJsonName)
     files = {}
     temp = email.lower()
     for item in contacts:
         if temp in contacts[item]['fromAddr'].lower():
             files[item] = contacts[item]
     return files
Beispiel #17
0
    def run(self):
        # 获取登录信息
        self.emailInfo["email"] = self.loginmail.text()
        # 密码加密
        password = self.loginpwd.text()
        self.emailInfo["pwd"] = encrypt(password)

        smtp_server = self.loginsmtp.text()
        pop3_server = self.loginpop.text()

        # 使用上次的服务器地址
        if smtp_server and pop3_server:
            self.emailInfo["smtp_server"] = smtp_server
            self.emailInfo["pop3_server"] = pop3_server
            self.emailInfo["status"] = 0
            SaveJsonInfo('conf.json', self.emailInfo)

        # 若服务器地址为空,则自动获取
        else:
            server = self.loginmail.text().split('@')[1].split('.com')[0]
            if server == 'foxmail':
                server = 'qq'
            smtp_server = 'smtp.%s.com' % server
            pop3_server = 'pop.%s.com' % server

            if 'hust' in server:
                smtp_server = 'mail.hust.edu.cn'
                pop3_server = 'mail.hust.edu.cn'

            self.emailInfo["smtp_server"] = smtp_server
            self.emailInfo["pop3_server"] = pop3_server
            self.emailInfo["status"] = 0
            SaveJsonInfo('conf.json', self.emailInfo)
            self.loginsmtp.setText(smtp_server)
            self.loginpop.setText(pop3_server)

        # 开始登陆
        try:
            start = time.time()
            self.emailInfo = GetJsonInfo('conf.json')
            server = smtplib.SMTP_SSL(smtp_server, 465)
            server.set_debuglevel(1)
            print('\n***************************************\n\n')

            # 密码解密
            password = decrypt(self.emailInfo['pwd'])
            server.login(self.emailInfo["email"], password)
            self.emailInfo["status"] = 1
            SaveJsonInfo('conf.json', self.emailInfo)
            end = time.time()
            print('耗时:' + str(end - start))

        except Exception as e:
            print(type(e))
            print(e)
            self.emailInfo["status"] = 0
            SaveJsonInfo('conf.json', self.emailInfo)
Beispiel #18
0
 def on_mainlogin_clicked(self):
     self.hide()
     my_login = Login()
     my_login.exec_()
     self.emailInfo = GetJsonInfo('conf.json')
     if self.emailInfo['status'] == 1:
         self.mainUserName.setText(self.emailInfo['email'])
         self.mainlogin.setText('切换账号')
         self.emaillist.clear()
         self.login = 1
         self.show()
Beispiel #19
0
 def on_draftBox_clicked(self):
     if self.login == 0:
         my_alert = QMessageBox.warning(self, '操作失败', u'请先登录您的账号!')
     else:
         self.emaillist.hide()
         self.searchList.hide()
         self.sentList.hide()
         self.deleteList.hide()
         self.delEmail.hide()
         self.restoreEmail.hide()
         draftJson = GetJsonInfo(self.draftJsonName)
         self.addQList(draftJson, 'draftList')
         self.draftList.show()
Beispiel #20
0
 def searchSubject(self, subject):
     dir = 'data/%s' % (self.userInfo['email'])
     contacts = GetJsonInfo(self.receiveJsonName)
     files = {}
     subject = subject.lower()
     if os.path.exists(dir):
         for file in os.listdir(dir):
             if os.path.isfile(os.path.join(dir, file)):
                 if subject in file.lower():
                     file = file.replace('.html', '')
                     if file in contacts:
                         files[file] = contacts[file]
     return files
Beispiel #21
0
    def itemClicked(self):
        my_currentItem = self.contactsList.currentItem()
        my_text = my_currentItem.text().split('\n')
        name = my_text[0]
        email = my_text[1]
        self.contacts = GetJsonInfo(self.contactsJsonName)

        qq = self.contacts[email].get('qq', '')
        remark = self.contacts[email].get('remark', '')
        weChat = self.contacts[email].get('weChat', '')
        phone = self.contacts[email].get('phone', '')

        self.contName.setText(name)
        self.contEmail.setText(email)
        self.contRemarkName.setText(remark)
        self.contPhone.setText(phone)
        self.contQQ.setText(qq)
        self.contWechat.setText(weChat)
        num = self.generateNum(email)
        self.contLogo.setStyleSheet(
            "border-image: url(:/avatar/Avatars/%d.jpg);" % num)
        print(self.contName.text())
Beispiel #22
0
    def __init__(self, parent=None):
        super(Login, self).__init__(parent)
        self.setupUi(self)
        self.setWindowFlags(Qt.FramelessWindowHint | Qt.Dialog)
        self.emailInfo = GetJsonInfo('conf.json')

        # 初始化
        if self.emailInfo["email"] and self.emailInfo["pwd"]:
            email = self.emailInfo["email"]
            pwd = self.emailInfo["pwd"]
            self.loginmail.setText(email)
            self.loginpwd.setText(pwd)
            self.loginsmtp.setText(self.emailInfo['smtp_server'])
            self.loginpop.setText(self.emailInfo['pop3_server'])
Beispiel #23
0
 def on_mainSearch_clicked(self):
     if self.searchMode.currentText() == '请选择':
         my_alert = QMessageBox.warning(self, '搜索失败', u'请选择一种搜索模式')
     else:
         keyword = self.searchlineEdit.text()  # 获取搜索关键字
         if keyword:
             self.userInfo = GetJsonInfo('conf.json')
             self.contacts = GetJsonInfo('contacts.json')
             self.emaillist.hide()
             self.sendedList.hide()
             self.searchList.show()
             begin = time.time()
             test = Search()
             test.run(self.userInfo, self.searchMode.currentText(), keyword)
             files = test.getResult()
             while files == None:
                 files = test.getResult()
             print("2", files)
             self.searchList.clear()
             self.addQList(files, 'searchList')
             print("耗时啥都不用2:", time.time() - begin)
         else:
             my_alert = QMessageBox.warning(self, '搜索失败', u'搜索内容不能为空!')
Beispiel #24
0
 def searchEmailContent(self, content):
     content = re.compile(content)
     dir = 'data/%s' % (self.userInfo['email'])
     contacts = GetJsonInfo('contacts.json')
     abDir = os.path.abspath(os.path.join(
         os.path.dirname(__file__))).replace('\\', '/') + "/%s" % dir
     files = {}
     if os.path.exists(dir):
         for file in os.listdir(dir):
             if file[-4:] == 'html':
                 fileDir = "%s/%s" % (abDir, file)
                 with open(fileDir, 'rb') as f:
                     emailContent = f.read().decode('utf-8')
                     if len(content.findall(emailContent)) > 0:
                         files[file] = contacts[file]
     return files
Beispiel #25
0
    def searchEmailContent(self, content):
        contacts = GetJsonInfo(self.receiveJsonName)
        files = {}
        # 遍历邮件文件夹
        if os.path.exists(self.dir):
            for file in os.listdir(self.dir):
                if file[-4:] == 'html':
                    fileDir = "%s/%s" % (self.dir, file)
                    with open(fileDir, 'rb') as f:
                        emailContent = f.read().decode('utf-8')

                        if content in emailContent:
                            subject = file.replace('.html', '')
                            files[subject] = contacts[subject]

        return files
Beispiel #26
0
    def addQListWidgetItem(self):
        dir = 'data/%s' % self.emailInfo['email']
        files = []
        for file in os.listdir(dir):
            print(file)
            if os.path.isfile(os.path.join(dir, file)):
                files.append(file)
        print('****************************\n\n')
        my_contacts = GetJsonInfo('contacts.json')

        for subject in my_contacts:
            filename = subject + '.html'
            if filename in files:
                abstractContent = my_contacts[subject][
                    'date'] + '\n' + subject + '\n' + my_contacts[subject][
                        'name']
                self.emaillist.addItem(abstractContent)
Beispiel #27
0
    def on_login_clicked(self):
        # 登录
        self.run()

        self.emailInfo = GetJsonInfo('conf.json')
        if self.emailInfo['status'] == 0:
            alert = QMessageBox.warning(self, '登录失败', u'登录失败,请检查配置是否正确!')
            self.resize(500, 370)
        else:

            # 创建一个以邮件命名的文件夹,用于区分用户信息
            dir = '/data/%s' % (self.emailInfo['email'])
            # 获取当前文件的绝对路径
            abDir = os.path.abspath(os.path.join(
                os.path.dirname(__file__))).replace('\\', '/')
            dir = ("%s/%s") % (abDir, dir)
            if not os.path.exists(dir):
                os.mkdir(dir)
                print("文件夹创建成功:%s" % dir)

            self.close()
Beispiel #28
0
 def searchItemClicked(self):
     try:
         my_contacts = GetJsonInfo('contacts.json')
         my_currentItem = self.searchList.currentItem()
         my_text = my_currentItem.text().split('\n')[1].split('\n')[0]
         self.url = 'file:///' + os.path.abspath(
             os.path.join(os.path.dirname(__file__))
         ) + r'/data/%s/%s.html' % (self.emailInfo['email'], my_text)
         self.url = self.url.replace('\\', '/')
         print(self.url)
         self.contName.setText(my_contacts[my_text]['name'])
         self.contEmail.setText(my_contacts[my_text]['fromAddr'])
         self.contEmailTime.setText(my_contacts[my_text]['date'])
         self.contEmailSubject.setText(my_text)
         self.mainForward.show()
         self.delEmail.show()
         self.mainReply.show()
         self.mainAttach.show()
         self.emailShow.setUrl(QtCore.QUrl(self.url))
         self.attachList.hide()
     except Exception as e:
         print(str(e))
     print("search")
Beispiel #29
0
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.setupUi(self)
        self.setWindowFlags(Qt.FramelessWindowHint | Qt.Dialog)

        # 导入qss样式表
        # wait

        # 邮件数量
        self.index = 0
        self.page = 0
        self.receiveWay = 0
        # 判断是否已经的登录邮箱,若已经登录才能进行后续操作
        self.login = 0

        # 下面变量用于记录已经添加到列表中的值,从而避免重复添加
        # 已接收邮件记录变量
        self.isReceived = {}
        # 已删除邮件记录变量
        self.isDeleted = {}
        # 草稿箱记录变量
        self.isDraft = {}
        # 已发送邮件记录变量
        self.isSent = {}

        # 指示当前邮件文件夹类型
        self.currentFolder = 'receive'

        # 登录上次账号
        try:
            start = time.time()
            self.emailInfo = GetJsonInfo('conf.json')
            # 获取当前文件的绝对路径
            abDir = os.path.abspath(os.path.join(
                os.path.dirname(__file__))).replace('\\', '/')
            dir = "%s/data/%s" % (abDir, self.emailInfo['email'])
            if os.path.exists(
                    dir) and self.emailInfo['email'] and self.emailInfo['pwd']:
                self.emailInfo["status"] = 1
                SaveJsonInfo('conf.json', self.emailInfo)

                end = time.time()
                print('耗时:' + str(end - start))
                self.mainUserName.setText(self.emailInfo['email'])
                self.mainlogin.setText('切换')
                self.login = 1

                self.receiveJsonName = dir + "receive.json"
                self.sendJsonName = dir + "send.json"
                self.deleteJsonName = dir + "delete.json"
                self.draftJsonName = dir + "draft.json"
                num = self.generateNum(self.emailInfo['email'])
                self.headlogo.setStyleSheet('''
				background-color: rgb(242, 242, 242);
				border-radius:40px;
				border-image: url(:/avatar/Avatars/%d.jpg);
				''' % num)
                # t = threading.Thread(target=self.intervalRec(5))
                # t.start()
                self.addQList(GetJsonInfo(self.receiveJsonName), 'emaillist')

        except Exception as e:
            print(e)
            self.emailInfo = {
                "pop3_server": "",
                "email": "",
                "pwd": "",
                "smtp_server": "",
                "status": 0
            }
            SaveJsonInfo('conf.json', self.emailInfo)

        self.emailInfo = GetJsonInfo('conf.json')
        self.attachList.hide()
        self.mainForward.hide()
        self.delEmail.hide()
        self.mainReply.hide()
        self.mainAttach.hide()
        self.restoreEmail.hide()

        # 绑定emailList
        self.connect(self.emaillist, SIGNAL('itemClicked(QListWidgetItem *)'),
                     self.emailItemClicked)

        # 绑定attachList
        self.connect(self.attachList, SIGNAL('itemClicked(QListWidgetItem *)'),
                     self.attachItemClicked)

        # 绑定searchList
        self.connect(self.searchList, SIGNAL('itemClicked(QListWidgetItem *)'),
                     self.searchItemClicked)

        # 绑定deleteList
        self.connect(self.deleteList, SIGNAL('itemClicked(QListWidgetItem *)'),
                     self.deleteItemClicked)

        # 绑定draftList
        self.connect(self.draftList, SIGNAL('itemClicked(QListWidgetItem *)'),
                     self.draftItemClicked)

        # 绑定sentList
        self.connect(self.sentList, SIGNAL('itemClicked(QListWidgetItem *)'),
                     self.sentItemClicked)
Beispiel #30
0
class MainWindow(QMainWindow, Ui_MainWindow):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.setupUi(self)
        self.setWindowFlags(Qt.FramelessWindowHint | Qt.Dialog)

        # 导入qss样式表
        # wait

        # 邮件数量
        self.index = 0
        self.page = 0
        self.receiveWay = 0
        # 判断是否已经的登录邮箱,若已经登录才能进行后续操作
        self.login = 0

        # 下面变量用于记录已经添加到列表中的值,从而避免重复添加
        # 已接收邮件记录变量
        self.isReceived = {}
        # 已删除邮件记录变量
        self.isDeleted = {}
        # 草稿箱记录变量
        self.isDraft = {}
        # 已发送邮件记录变量
        self.isSent = {}

        # 指示当前邮件文件夹类型
        self.currentFolder = 'receive'

        # 登录上次账号
        try:
            start = time.time()
            self.emailInfo = GetJsonInfo('conf.json')
            # 获取当前文件的绝对路径
            abDir = os.path.abspath(os.path.join(
                os.path.dirname(__file__))).replace('\\', '/')
            dir = "%s/data/%s" % (abDir, self.emailInfo['email'])
            if os.path.exists(
                    dir) and self.emailInfo['email'] and self.emailInfo['pwd']:
                self.emailInfo["status"] = 1
                SaveJsonInfo('conf.json', self.emailInfo)

                end = time.time()
                print('耗时:' + str(end - start))
                self.mainUserName.setText(self.emailInfo['email'])
                self.mainlogin.setText('切换')
                self.login = 1

                self.receiveJsonName = dir + "receive.json"
                self.sendJsonName = dir + "send.json"
                self.deleteJsonName = dir + "delete.json"
                self.draftJsonName = dir + "draft.json"
                num = self.generateNum(self.emailInfo['email'])
                self.headlogo.setStyleSheet('''
				background-color: rgb(242, 242, 242);
				border-radius:40px;
				border-image: url(:/avatar/Avatars/%d.jpg);
				''' % num)
                # t = threading.Thread(target=self.intervalRec(5))
                # t.start()
                self.addQList(GetJsonInfo(self.receiveJsonName), 'emaillist')

        except Exception as e:
            print(e)
            self.emailInfo = {
                "pop3_server": "",
                "email": "",
                "pwd": "",
                "smtp_server": "",
                "status": 0
            }
            SaveJsonInfo('conf.json', self.emailInfo)

        self.emailInfo = GetJsonInfo('conf.json')
        self.attachList.hide()
        self.mainForward.hide()
        self.delEmail.hide()
        self.mainReply.hide()
        self.mainAttach.hide()
        self.restoreEmail.hide()

        # 绑定emailList
        self.connect(self.emaillist, SIGNAL('itemClicked(QListWidgetItem *)'),
                     self.emailItemClicked)

        # 绑定attachList
        self.connect(self.attachList, SIGNAL('itemClicked(QListWidgetItem *)'),
                     self.attachItemClicked)

        # 绑定searchList
        self.connect(self.searchList, SIGNAL('itemClicked(QListWidgetItem *)'),
                     self.searchItemClicked)

        # 绑定deleteList
        self.connect(self.deleteList, SIGNAL('itemClicked(QListWidgetItem *)'),
                     self.deleteItemClicked)

        # 绑定draftList
        self.connect(self.draftList, SIGNAL('itemClicked(QListWidgetItem *)'),
                     self.draftItemClicked)

        # 绑定sentList
        self.connect(self.sentList, SIGNAL('itemClicked(QListWidgetItem *)'),
                     self.sentItemClicked)

    # 无边框设计
    def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton:
            self.dragPosition = event.globalPos() - self.frameGeometry(
            ).topLeft()
            QApplication.postEvent(self, QEvent(174))
            event.accept()

    def mouseMoveEvent(self, event):
        if event.buttons() == Qt.LeftButton:
            self.move(event.globalPos() - self.dragPosition)
            event.accept()

    # 伪随机数
    def generateNum(self, string):
        try:
            num = ord(string[0])
            num = int(num % 30)
            print(num)
            return num
        except Exception as e:
            print(str(e))
            return 1

    # 转发
    @pyqtSlot()
    def on_mainForward_clicked(self):
        if self.login == 0:
            my_alert = QMessageBox.warning(self, '操作失败', u'请先登录您的账号!')
        else:
            # 富文本编辑器html文件路径
            abDir = os.path.abspath(os.path.join(
                os.path.dirname(__file__))).replace('\\', '/')
            self.richEditDir = r'''%s\kindeditor-4.1.7\examples\default.html''' % abDir
            self.richEditDir = self.richEditDir.replace('\\', '/')
            # 获取原编辑器页面html内容
            with open(self.richEditDir, 'rb') as f:
                self.originHtml = f.read()

            my_subject = self.contEmailSubject.text()
            my_name = self.contName.text()
            my_email = self.contEmail.text()
            my_time = self.contEmailTime.text()
            my_forwardInfo = {
                'subject': my_subject,
                'name': my_name,
                'email': my_email,
                'time': my_time
            }
            if self.currentFolder == 'receive':
                dir = "%s/data/%s/" % (abDir, self.emailInfo['email'])
            else:
                dir = "%s/data/%s/%s/" % (abDir, self.emailInfo['email'],
                                          self.currentFolder)
            my_url = dir + my_subject + '.html'

            my_mainForward = WriteEmailDialog(isForwad=True,
                                              ForwardInfo=my_forwardInfo,
                                              url=my_url)
            my_mainForward.exec_()

            # 还原编辑器文件
            with open(self.richEditDir, 'wb') as f:
                f.write(self.originHtml)

    # 回复邮件
    @pyqtSlot()
    def on_mainReply_clicked(self):
        if self.login == 0:
            my_alert = QMessageBox.warning(self, '操作失败', u'请先登录您的账号!')
        else:
            my_subject = self.contEmailSubject.text()
            my_name = self.contName.text()
            my_email = self.contEmail.text()
            my_time = self.contEmailTime.text()
            my_forwardInfo = {
                'subject': my_subject,
                'name': my_name,
                'email': my_email,
                'time': my_time
            }

            abDir = os.path.abspath(os.path.join(
                os.path.dirname(__file__))).replace('\\', '/')

            if self.currentFolder == 'receive':
                dir = "%s/data/%s/" % (abDir, self.emailInfo['email'])
            else:
                dir = "%s/data/%s/%s/" % (abDir, self.emailInfo['email'],
                                          self.currentFolder)

            my_url = dir + my_subject + '.html'

            reply_addr = self.contEmail.text()
            reply_subject = "Reply:" + self.contEmailSubject.text()
            my_replyInfo = {
                "reply_addr": reply_addr,
                "reply_subject": reply_subject
            }

            self.richEditDir = r'''%s\kindeditor-4.1.7\examples\default.html''' % abDir
            self.richEditDir = self.richEditDir.replace('\\', '/')
            # 获取原编辑器页面html内容
            with open(self.richEditDir, 'rb') as f:
                self.originHtml = f.read()

            my_reply = WriteEmailDialog(isForwad=False,
                                        ForwardInfo=my_forwardInfo,
                                        url=my_url,
                                        isReply=True,
                                        replyInfo=my_replyInfo)
            my_reply.exec_()

            # 还原编辑器文件
            with open(self.richEditDir, 'wb') as f:
                f.write(self.originHtml)

    # 查看附件
    @pyqtSlot()
    def on_mainAttach_clicked(self):
        if self.mainAttach.text() == '查看附件':
            my_subject = self.contEmailSubject.text()
            if self.currentFolder == 'receive':
                dir = 'data/%s/%s' % (self.emailInfo['email'], my_subject)
                print(dir)
            else:
                dir = 'data/%s/%s/%s' % (self.emailInfo['email'],
                                         self.currentFolder, my_subject)
                print(dir)
            if os.path.exists(dir):
                self.attachList.clear()
                for file in os.listdir(dir):
                    print(file)
                    if os.path.isfile(os.path.join(dir, file)):
                        self.attachList.addItem(file)
                self.attachList.show()
                self.mainAttach.setText('隐藏附件')
            else:
                my_alert = QMessageBox.warning(self, '操作失败', u'此邮件无附件')

        elif self.mainAttach.text() == "隐藏附件":
            self.attachList.hide()
            self.mainAttach.setText('查看附件')

    # 删除邮件
    @pyqtSlot()
    def on_delEmail_clicked(self):
        isDel = QMessageBox.information(self, '删除邮件', u'确定要删除该封邮件?', 'Yes',
                                        'Cancel')
        if self.item_enable_delete:
            if not isDel:
                # 获取主题名
                my_subject = self.contEmailSubject.text()
                self.receive = GetJsonInfo(self.receiveJsonName)
                self.delete = GetJsonInfo(self.deleteJsonName)

                # 将删除邮件存至delete.json文件中
                temp = {my_subject: self.receive[my_subject]}
                print(temp)
                self.delete.update(temp)
                # self.isDeleted.update(temp)

                # 将邮件从receive.json中去除
                self.receive.pop(my_subject)
                self.isReceived.pop(my_subject)

                # 数据回写
                SaveJsonInfo(self.receiveJsonName, self.receive)
                SaveJsonInfo(self.deleteJsonName, self.delete)

                self.contEmail.setText('')
                self.contEmailTime.setText('')
                self.contEmailSubject.setText('')
                self.contName.setText('')
                self.emailShow.setUrl(QtCore.QUrl("qrc:/souce/index.html"))

                self.emaillist.takeItem(self.emaillist.currentRow())
                self.item_enable_delete = False
                self.mainForward.hide()
                self.delEmail.hide()
                self.addQList(self.delete, 'deleteList')

    # 恢复已删除邮件
    @pyqtSlot()
    def on_restoreEmail_clicked(self):
        # Yes:0 Cancel:1
        isRestore = QMessageBox.information(self, '恢复邮件', u'确定要恢复该封邮件?', 'Yes',
                                            'Cancel')
        if not isRestore:
            # 获取主题名
            my_subject = self.contEmailSubject.text()
            self.receive = GetJsonInfo(self.receiveJsonName)
            self.delete = GetJsonInfo(self.deleteJsonName)

            temp = {my_subject: self.delete[my_subject]}
            print(temp)
            # 将删除邮件恢复至receive.json文件中
            self.receive.update(temp)
            # self.isReceived.update(temp)

            # 将邮件从delete.json中去除
            self.delete.pop(my_subject)
            self.isDeleted.pop(my_subject)

            # 数据回写
            SaveJsonInfo(self.receiveJsonName, self.receive)
            SaveJsonInfo(self.deleteJsonName, self.delete)

            self.deleteList.takeItem(self.deleteList.currentRow())
            self.addQList(self.receive, 'emaillist')

            self.contEmail.setText('')
            self.contEmailTime.setText('')
            self.contEmailSubject.setText('')
            self.contName.setText('')
            self.emailShow.setUrl(QtCore.QUrl("qrc:/souce/index.html"))

            self.mainForward.hide()
            self.delEmail.hide()

    # 查询邮件
    @pyqtSlot()
    def on_mainSearch_clicked(self):
        if self.searchMode.currentText() == '请选择':
            my_alert = QMessageBox.warning(self, '搜索失败', u'请选择一种搜索模式')
        else:
            keyword = self.searchlineEdit.text()  # 获取搜索关键字
            if keyword:
                self.userInfo = GetJsonInfo('conf.json')
                self.receive = GetJsonInfo(self.receiveJsonName)
                self.emaillist.hide()
                self.sentList.hide()
                self.deleteList.hide()
                self.draftList.hide()
                self.searchList.show()
                begin = time.time()
                test = Search()
                test.run(self.userInfo, self.searchMode.currentText(), keyword)
                files = test.getResult()
                while files == None:
                    files = test.getResult()
                print("2", files)
                self.searchList.clear()
                if len(files) > 0:
                    self.addQList(files, 'searchList')
                else:
                    self.addQList(
                        {
                            "搜索结果为空": {
                                "date": "",
                                "subject": "搜索结果为空",
                                "name": ""
                            }
                        }, 'searchList')
                print("耗时啥都不用2:", time.time() - begin)
            else:
                my_alert = QMessageBox.warning(self, '搜索失败', u'搜索内容不能为空!')

    # 选择搜索模式
    @pyqtSlot(str)
    def on_searchMode_currentIndexChanged(self, p0):
        self.Mode = self.searchMode.currentText()
        print(self.Mode)
        if self.Mode == '请选择':
            self.searchlineEdit.setPlaceholderText('请选择一种搜索模式')
        elif self.Mode == '主题':
            self.searchlineEdit.setPlaceholderText('请输入要搜索的主题')
        elif self.Mode == '时间':
            self.searchlineEdit.setPlaceholderText('搜索时间格式为xxxx-xx-xx')
        elif self.Mode == '联系人':
            self.searchlineEdit.setPlaceholderText('请输入要搜索的联系人地址')
        elif self.Mode == '邮件内容':
            self.searchlineEdit.setPlaceholderText('请输入要搜索的邮件内容')

    # 附件列表点击事件
    @pyqtSlot()
    def attachItemClicked(self):
        dir = 'data/%s/%s' % (self.emailInfo['email'],
                              self.contEmailSubject.text())
        my_currentItem = self.attachList.currentItem()
        attachName = my_currentItem.text()
        # 获取当前文件的绝对路径
        abDir = os.path.abspath(os.path.join(
            os.path.dirname(__file__))).replace('\\', '/')
        dir = ("%s/%s/%s") % (abDir, dir, attachName)
        print(dir)
        try:
            os.startfile(dir)
        except Exception as e:
            my_alert = QMessageBox.warning(self, '操作失败', u'此邮件丢失')

    # 垃圾箱列表点击触发显示邮件
    @pyqtSlot()
    def deleteItemClicked(self):
        try:
            self.currentFolder = 'receive'
            self.item_enable_delete = True  # 点击一个元素,可删除
            self.restoreEmail.show()
            my_delete = GetJsonInfo(self.deleteJsonName)
            my_currentItem = self.deleteList.currentItem()
            my_text = my_currentItem.text().split('主题:')[1].split('\n')[0]

            url = 'file:///' + os.path.abspath(
                os.path.join(os.path.dirname(__file__))
            ) + r'/data/%s/%s.html' % (self.emailInfo['email'], my_text)
            url = url.replace('\\', '/')
            print(url)

            num = self.generateNum(my_currentItem.text().split('联系人:')[1])
            self.contLogo.setStyleSheet(
                "border-image: url(:/avatar/Avatars/%d.jpg);" % num)

            self.contName.setText(my_delete[my_text]['name'])
            self.contEmail.setText(my_delete[my_text]['fromAddr'])
            self.contEmailTime.setText(my_delete[my_text]['date'])
            self.contEmailSubject.setText(my_text)
            self.mainForward.show()
            self.delEmail.hide()
            self.mainReply.show()
            self.mainAttach.show()
            self.attachList.hide()
            self.emailShow.setUrl(QtCore.QUrl(url))
        except Exception as e:
            print(str(e))
        print("delete")

    # 发件箱列表点击触发显示邮件
    @pyqtSlot()
    def sentItemClicked(self):
        try:
            self.currentFolder = 'send'
            self.item_enable_delete = True  # 点击一个元素,可删除
            my_sent = GetJsonInfo(self.sendJsonName)
            my_currentItem = self.sentList.currentItem()
            my_text = my_currentItem.text().split('主题:')[1].split('\n')[0]

            url = 'file:///' + os.path.abspath(
                os.path.join(os.path.dirname(__file__))
            ) + r'/data/%s/send/%s.html' % (self.emailInfo['email'], my_text)
            url = url.replace('\\', '/')
            print(url)
            num = self.generateNum(my_currentItem.text().split('联系人:')[1])
            self.contLogo.setStyleSheet(
                "border-image: url(:/avatar/Avatars/%d.jpg);" % num)

            self.contName.setText(my_sent[my_text]['name'])
            self.contEmail.setText(my_sent[my_text]['fromAddr'])
            self.contEmailTime.setText(my_sent[my_text]['date'])
            self.contEmailSubject.setText(my_text)
            self.mainForward.show()
            self.delEmail.hide()
            self.mainReply.show()
            self.mainAttach.show()
            self.emailShow.setUrl(QtCore.QUrl(url))
            self.attachList.hide()
        except Exception as e:
            print(str(e))
        print("sent")

    # 草稿箱列表点击触发显示邮件
    @pyqtSlot()
    def draftItemClicked(self):
        try:
            self.currentFolder = 'draft'
            self.item_enable_delete = True  # 点击一个元素,可删除
            my_draft = GetJsonInfo(self.draftJsonName)
            my_currentItem = self.draftList.currentItem()
            my_text = my_currentItem.text().split('主题:')[1].split('\n')[0]

            url = 'file:///' + os.path.abspath(
                os.path.join(os.path.dirname(__file__))
            ) + r'/data/%s/draft/%s.html' % (self.emailInfo['email'], my_text)
            url = url.replace('\\', '/')
            print(url)
            num = self.generateNum(my_currentItem.text().split('联系人:')[1])
            self.contLogo.setStyleSheet(
                "border-image: url(:/avatar/Avatars/%d.jpg);" % num)

            self.contName.setText(my_draft[my_text]['name'])
            self.contEmail.setText(my_draft[my_text]['fromAddr'])
            self.contEmailTime.setText(my_draft[my_text]['date'])
            self.contEmailSubject.setText(my_text)
            self.mainForward.show()
            self.delEmail.hide()
            self.mainReply.show()
            self.mainAttach.show()
            self.emailShow.setUrl(QtCore.QUrl(url))
            self.attachList.hide()
        except Exception as e:
            print(str(e))
        print("sent")

    # 搜索列表点击触发显示邮件
    @pyqtSlot()
    def searchItemClicked(self):
        try:
            self.currentFolder = 'receive'
            self.item_enable_delete = True  # 点击一个元素,可删除
            my_receive = GetJsonInfo(self.receiveJsonName)
            my_currentItem = self.searchList.currentItem()
            my_text = my_currentItem.text().split('主题:')[1].split('\n')[0]

            url = 'file:///' + os.path.abspath(
                os.path.join(os.path.dirname(__file__))
            ) + r'/data/%s/%s.html' % (self.emailInfo['email'], my_text)
            url = url.replace('\\', '/')
            print(url)

            num = self.generateNum(my_currentItem.text().split('联系人:')[1])
            self.contLogo.setStyleSheet(
                "border-image: url(:/avatar/Avatars/%d.jpg);" % num)

            self.contName.setText(my_receive[my_text]['name'])
            self.contEmail.setText(my_receive[my_text]['fromAddr'])
            self.contEmailTime.setText(my_receive[my_text]['date'])
            self.contEmailSubject.setText(my_text)
            self.mainForward.show()
            self.delEmail.hide()
            self.mainReply.show()
            self.mainAttach.show()
            self.emailShow.setUrl(QtCore.QUrl(url))
            self.attachList.hide()
        except Exception as e:
            print(str(e))
        print("search")

    # 绑定emaillist邮件列表点击事件
    @pyqtSlot()
    def emailItemClicked(self):
        try:
            self.currentFolder = 'receive'
            self.item_enable_delete = True  # 点击一个元素,可删除
            my_receive = GetJsonInfo(self.receiveJsonName)
            my_currentItem = self.emaillist.currentItem()
            my_text = my_currentItem.text().split('主题:')[1].split('\n')[0]

            url = 'file:///' + os.path.abspath(
                os.path.join(os.path.dirname(__file__))
            ) + r'/data/%s/%s.html' % (self.emailInfo['email'], my_text)
            url = url.replace('\\', '/')
            print(url)

            num = self.generateNum(my_currentItem.text().split('联系人:')[1])
            self.contLogo.setStyleSheet(
                "border-image: url(:/avatar/Avatars/%d.jpg);" % num)

            self.contName.setText(my_receive[my_text]['name'])
            self.contEmail.setText(my_receive[my_text]['fromAddr'])
            self.contEmailTime.setText(my_receive[my_text]['date'])
            self.contEmailSubject.setText(my_text)
            self.mainForward.show()
            self.delEmail.show()
            self.mainReply.show()
            self.mainAttach.show()
            self.emailShow.setUrl(QtCore.QUrl(url))
            self.attachList.hide()
        except Exception as e:
            print(str(e))

    # 将信息插入到列表
    # files是存储了邮件摘要信息的字典
    # way则表示要进行操作的列表名
    # 使用getattr()大量缩减了代码量。
    def addQList(self, files, way):
        isAddList = ''
        if way == 'searchList':
            for subject in files:
                if subject != '':
                    abstractContent = '时间:' + files[subject][
                        'date'] + '\n主题:' + subject + '\n联系人:' + files[
                            subject]['name']
                    getattr(self, way).addItem(abstractContent)
        else:
            if way == 'emaillist':
                isAddList = 'isReceived'
            elif way == 'draftList':
                isAddList = 'isDraft'
            elif way == 'deleteList':
                isAddList = 'isDeleted'
            elif way == 'sentList':
                isAddList = 'isSent'
            for subject in files:
                if subject != '' and subject not in getattr(self, isAddList):
                    getattr(self, isAddList).update({subject: files[subject]})
                    abstractContent = '时间:' + files[subject][
                        'date'] + '\n主题:' + subject + '\n联系人:' + files[
                            subject]['name']
                    getattr(self, way).addItem(abstractContent)

    # 定时接收邮件
    def intervalRec(self, interval):
        while True:
            try:
                self.runReceive()
                time.sleep(interval)
            except Exception as e:
                print(str(e))

    # 接收邮件
    def runReceive(self):
        myPop = ReceiveMail()
        self.popServer = myPop.connect()
        self.emailNum = myPop.GetEmailNum()
        # 循环解析邮件
        for i in range(self.emailNum, 0, -1):
            resp, lines, octets = self.popServer.retr(i)
            msg_content = b'\r\n'.join(lines)

            # 稍后解析出邮件:
            msg = BytesParser().parsebytes(msg_content)
            try:
                # 解析邮件基本信息
                currentEmailInfo = myPop.parseEmailInfo(msg)
                for item in currentEmailInfo:
                    # 判断邮件是否已经添加到列表
                    if item not in self.isReceived:
                        # self.isReceived.update(currentEmailInfo)
                        # 解析邮件内容
                        myPop.parseEmailContent(msg)
                        self.addQList(currentEmailInfo, 'emaillist')
            except Exception as e:
                print(str(e))

        myPop.quit()
        self.loading.hide()

    # 接收最新邮件按钮
    @pyqtSlot()
    def on_mainreceiveletter_clicked(self):
        if self.login == 0:
            my_alert = QMessageBox.warning(self, '操作失败', u'请先登录您的账号!')
        else:

            self.loading.show()
            # a =  ' url(:/souce/souce/loading.gif)'
            self.movie = QMovie('souce/loading.gif')
            self.movie.setScaledSize(QSize(20, 20))
            self.loading.setMovie(self.movie)
            self.movie.start()

            self.searchList.hide()
            self.sentList.hide()
            self.emaillist.show()

            self.receiveWay = 0
            p = threading.Thread(target=self.runReceive)
            p.start()

    # 选择邮件列表排序对象
    @pyqtSlot(str)
    def on_itemSortMode_currentIndexChanged(self, p0):
        mode = self.itemSortMode.currentText()
        print(mode)
        self.emaillist.clear()
        self.deleteList.clear()
        self.draftList.clear()
        self.sentList.clear()

        p = threading.Thread(target=self.reBuildList(mode))
        p.start()

    # 重构列表
    def reBuildList(self, mode):
        receiveBox = self.changeItemValue(self.isReceived, mode)
        deleteBox = self.changeItemValue(self.isDeleted, mode)
        draftBox = self.changeItemValue(self.isDraft, mode)
        sentBox = self.changeItemValue(self.isSent, mode)

        for a in receiveBox:
            self.emaillist.addItem(a)
        for b in deleteBox:
            self.deleteList.addItem(b)
        for c in draftBox:
            self.draftList.addItem(c)
        for d in sentBox:
            self.sentList.addItem(d)

    # 修改列表项的值
    def changeItemValue(self, files, mode):
        box = []
        if mode == '按时间排序':
            for subject in files:
                if subject != '':
                    abstractContent = '时间:' + files[subject]['date'] + '\n主题:' + subject + '\n联系人:' + \
                          files[subject]['name']
                    box.append(abstractContent)
        elif mode == "按主题排序":
            for subject in files:
                if subject != '':
                    abstractContent = '主题:' + subject + '\n时间:' + files[subject]['date'] + '\n联系人:' + \
                          files[subject]['name']
                    box.append(abstractContent)
        elif mode == "按联系人排序":
            for subject in files:
                if subject != '':
                    abstractContent = '联系人:' + files[subject]['name'] + '\n主题:' + subject + '\n时间:' + \
                          files[subject]['date']
                    box.append(abstractContent)
        return box

    # 邮件列表排列顺序
    @pyqtSlot(str)
    def on_itemSortOrder_currentIndexChanged(self, p0):
        order = self.itemSortOrder.currentText()
        if order == "升序":
            self.emaillist.sortItems(Qt.AscendingOrder)
            self.searchList.sortItems(Qt.AscendingOrder)
            self.sentList.sortItems(Qt.AscendingOrder)
        elif order == "降序":
            self.emaillist.sortItems(Qt.DescendingOrder)
            self.searchList.sortItems(Qt.DescendingOrder)
            self.sentList.sortItems(Qt.DescendingOrder)

    # 显示联系人界面
    @pyqtSlot()
    def on_addressbook_clicked(self):
        if self.login == 0:
            my_alert = QMessageBox.warning(self, '操作失败', u'请先登录您的账号!')
        else:
            my_contacts = contacts()
            my_contacts.exec_()

    # 登录
    @pyqtSlot()
    def on_mainlogin_clicked(self):
        self.hide()
        my_login = Login()
        my_login.exec_()
        self.emailInfo = GetJsonInfo('conf.json')
        if self.emailInfo['status'] == 1:
            self.mainUserName.setText(self.emailInfo['email'])
            self.mainlogin.setText('切换')
            self.emaillist.clear()
            self.login = 1
            self.show()
            # 获取当前文件的绝对路径
            abDir = os.path.abspath(os.path.join(
                os.path.dirname(__file__))).replace('\\', '/')
            dir = "%s/data/%s/" % (abDir, self.emailInfo['email'])
            self.receiveJsonName = dir + "receive.json"
            self.sendJsonName = dir + "send.json"
            self.deleteJsonName = dir + "delete.json"
            self.draftJsonName = dir + "draft.json"
            self.isReceived = {}
            self.isDeleted = {}
            self.isDraft = {}
            self.isSent = {}
            self.addQList(GetJsonInfo(self.receiveJsonName), 'emaillist')

            num = self.generateNum(self.emailInfo['email'])
            self.headlogo.setStyleSheet('''
			background-color: rgb(242, 242, 242);
			border-radius:40px;
			border-image: url(:/avatar/Avatars/%d.jpg);
			''' % num)

    # 日历
    @pyqtSlot()
    def on_calender_clicked(self):
        my_calender = calenderDialog()
        my_calender.exec_()

    # 写信
    @pyqtSlot()
    def on_mainwriteletter_clicked(self):
        if self.login == 0:
            my_alert = QMessageBox.warning(self, '操作失败', u'请先登录您的账号!')
        else:
            my_writemail = WriteEmailDialog()
            my_writemail.exec_()

    # 已发送邮件箱显示按钮
    @pyqtSlot()
    def on_sentBox_clicked(self):
        if self.login == 0:
            my_alert = QMessageBox.warning(self, '操作失败', u'请先登录您的账号!')
        else:
            self.emaillist.hide()
            self.searchList.hide()
            self.deleteList.hide()
            self.draftList.hide()
            self.restoreEmail.hide()
            self.delEmail.hide()
            sendJson = GetJsonInfo(self.sendJsonName)
            self.addQList(sendJson, 'sentList')
            self.sentList.show()

    # 垃圾箱显示按钮
    @pyqtSlot()
    def on_deleteBox_clicked(self):
        if self.login == 0:
            my_alert = QMessageBox.warning(self, '操作失败', u'请先登录您的账号!')
        else:
            self.emaillist.hide()
            self.searchList.hide()
            self.draftList.hide()
            self.sentList.hide()
            self.delEmail.hide()
            self.restoreEmail.hide()
            deleteJson = GetJsonInfo(self.deleteJsonName)
            self.addQList(deleteJson, 'deleteList')
            self.deleteList.show()

    # 草稿箱显示按钮
    @pyqtSlot()
    def on_draftBox_clicked(self):
        if self.login == 0:
            my_alert = QMessageBox.warning(self, '操作失败', u'请先登录您的账号!')
        else:
            self.emaillist.hide()
            self.searchList.hide()
            self.sentList.hide()
            self.deleteList.hide()
            self.delEmail.hide()
            self.restoreEmail.hide()
            draftJson = GetJsonInfo(self.draftJsonName)
            self.addQList(draftJson, 'draftList')
            self.draftList.show()

    # 收件箱显示按钮
    @pyqtSlot()
    def on_receivedBox_clicked(self):
        if self.login == 0:
            my_alert = QMessageBox.warning(self, '操作失败', u'请先登录您的账号!')
        else:
            self.searchList.hide()
            self.sentList.hide()
            self.deleteList.hide()
            self.draftList.hide()
            self.restoreEmail.hide()
            self.emaillist.show()

    # 关闭
    @pyqtSlot()
    def on_mainclose_clicked(self):
        self.close()

    # 最小化
    @pyqtSlot()
    def on_mainmin_clicked(self):
        self.showMinimized()

    # 关于
    @pyqtSlot()
    def on_about_clicked(self):
        my_about = About()
        my_about.show()
        my_about.exec_()