예제 #1
0
 def _get_folders(self) -> iter:
     folderurl = 'https://mail.tom.com/webmail/query/folderinfo.action?type=all_brief'
     try:
         html = self._ha.getstring(folderurl,
                                   headers="""
         Accept: application/json, text/javascript, */*; q=0.01
         Accept-Encoding: gzip, deflate
         Accept-Language: zh-CN,zh;q=0.9
         Connection: keep-alive
         Host: mail.tom.com
         Referer: http://mail.tom.com/webmail/main/index.action
         User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.193 Safari/537.36
         X-Requested-With: XMLHttpRequest""")
         result = json.loads(html).get('result')
         if result is None or not result.__contains__('mailList'):
             return
         maillist: list = result['mailList']
         if len(maillist) == 0:
             return
         for mailbox in maillist:
             f = Folder()
             f.name = mailbox['viewName']
             f.mailcount = mailbox['msgCount']
             yield f
     except Exception:
         self._logger.error("Get folder error, err: {}".format(
             traceback.format_exc()))
         return
예제 #2
0
    def _get_folders(self) -> iter:
        try:
            if self._html is None:
                # sid = self._get_sid()
                if self.sid is None:
                    self._logger.error("Invalid cookie")
                url = "https://mail.163.com/js6/main.jsp"

                querystring = {"sid": self.sid, "df": "mail163_letter"}
                headers = '''
                    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
                    Accept-Encoding: gzip, deflate, br
                    Accept-Language: zh-CN,zh;q=0.9,en;q=0.8
                    Cache-Control: no-cache
                    Connection: keep-alive
                    Host: mail.163.com
                    Pragma: no-cache
                    Upgrade-Insecure-Requests: 1
                    User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36
                '''
                # response = requests.request("GET", url, headers=headers, params=querystring)
                res_text = self._ha.getstring(url, headers=headers, params=querystring)
                if "已发送" in res_text:
                    self._html = res_text
            re_id = re.compile("'id':(\d+),")
            ids_all = re_id.findall(self._html)
            re_name = re.compile("'name':'(.+?)',")
            name_all = re_name.findall(self._html)
            for folder_num in range(len(ids_all)):
                folder = Folder()
                folder.folderid = ids_all[folder_num]
                folder.name = name_all[folder_num]
                yield folder
        except Exception:
            self._logger.error(f"Get folder info error, err:{traceback.format_exc()}")
예제 #3
0
 def _get_folders(self) -> iter:
     try:
         re_folder_all = re.compile('<option value="(\d+)">(\w+)</option>')
         if self._index_html is None:
             start_url = 'https://webmail30.189.cn/w2/'
             s = requests.session()
             s.headers.update(self._headers)
             s.get(start_url)
             login_url = 'https://webmail30.189.cn/w2/logon/signOn.do'
             s.headers.update({'Cookie': self.task.cookie})
             r = s.get(login_url)
             res_text = r.text
             if '收件箱' in res_text and 'window.globalValues=' in res_text and '"code":0' in res_text:
                 self._index_html = res_text
         if self._index_html is None or self._index_html == '':
             return
         folder_all = re_folder_all.findall(self._index_html)
         if len(folder_all) == 0:
             return
         for folder_one in folder_all:
             fone = Folder()
             fone.name = folder_one[1]
             fone.folderid = folder_one[0]
             yield fone
     except Exception:
         self._logger.error(f'Get folder error, err:{traceback.format_exc()}')
         return
예제 #4
0
 def _get_folders(self) -> iter:
     url = "http://m0.mail.sina.com.cn/wa.php"
     querystring = {"a": "list_folder", "calltype": "auto"}
     payload = {'sactioncount': 'AppMailIndex5_lt1:1, mailList_new_20: 431'}
     headers = {
         'Accept':
         "*/*",
         'Accept-Encoding':
         "gzip, deflate",
         'Accept-Language':
         "zh-CN,zh;q=0.9,en;q=0.8",
         'Cache-Control':
         "no-cache",
         'Content-type':
         "application/x-www-form-urlencoded;charset=UTF-8",
         'Cookie':
         self.task.cookie,
         'Host':
         "m0.mail.sina.com.cn",
         'Origin':
         "http://m0.mail.sina.com.cn",
         'Pragma':
         "no-cache",
         'Proxy-Connection':
         "keep-alive",
         'Referer':
         "http://m0.mail.sina.com.cn/classic/index.php",
         'User-Agent':
         "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
         "Chrome/71.0.3578.98 Safari/537.36"
     }
     try:
         response = requests.request("POST",
                                     url,
                                     data=payload,
                                     headers=headers,
                                     params=querystring)
         res_json = json.loads(response.text)
         if res_json.get('errno') != 0:
             self._logger.error("Got folder errror!")
             return
         folders_data = res_json.get('data')
         for folder in folders_data:
             id = folder.get('id')
             fname = folder.get('fname')
             if id == 'all':
                 # 分了文件夹就不用再下载所有邮件了
                 continue
             f = Folder()
             f.name = repr(fname)
             f.folderid = id
             yield f
     except Exception:
         self._logger.error(
             f"Get folder info error, err:{traceback.format_exc()}")
예제 #5
0
 def _get_folder(self, folder_jsondata):
     if folder_jsondata is None or folder_jsondata == '':
         return
     folder_list = folder_jsondata['var']['folderList']
     for folder in folder_list:
         if folder['stats']['messageCount'] == 0:
             continue
         f_one = Folder()
         f_one.name = folder['name']
         f_one.folderid = folder['fid']
         yield f_one
예제 #6
0
 def _get_folders(self) -> iter:
     try:
         if self._html is None:
             sid = self._get_sid()
             if sid is None:
                 self._logger.error("Invalid cookie")
             url = f"http://webmail.vip.163.com/js6/main.jsp?sid={sid}&df=mailvip"
             headers = {
                 'Accept':
                 "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
                 'Accept-Encoding':
                 "gzip, deflate",
                 'Accept-Language':
                 "zh-CN,zh;q=0.9,en;q=0.8",
                 'Cache-Control':
                 "no-cache",
                 'Cookie':
                 self.task.cookie.encode('utf-8'),
                 'Host':
                 "webmail.vip.163.com",
                 'Pragma':
                 "no-cache",
                 'Proxy-Connection':
                 "keep-alive",
                 'Referer':
                 "http://webmail.vip.163.com/js6/main.jsp?sid=BAsnkgKKqetoFpUtUVKKteyfONhRRwgX&df=mailvip",
                 'Upgrade-Insecure-Requests':
                 "1",
                 'User-Agent':
                 "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36"
             }
             response = requests.get(url, headers=headers)
             res_text = response.text
             if "已发送" in res_text:
                 self._html = res_text
         re_id = re.compile("'id':(\d+),")
         ids_all = re_id.findall(self._html)
         re_name = re.compile("'name':'(.+?)',")
         name_all = re_name.findall(self._html)
         for folder_num in range(len(ids_all)):
             folder = Folder()
             folder.folderid = ids_all[folder_num]
             folder.name = name_all[folder_num]
             yield folder
     except Exception:
         self._logger.error(
             f"Get folder info error, err:{traceback.format_exc()}")
예제 #7
0
 def _get_folders(self) -> iter:
     url = "https://mail.qq.com/cgi-bin/folderlist?t=folderlist_setting&s=null&info=true&sid={}".format(
         self._sid)
     headers = {
         'accept':
         "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
         'accept-encoding':
         "gzip, deflate, br",
         'accept-language':
         "zh-CN,zh;q=0.9,en;q=0.8",
         'cache-control':
         "no-cache,no-cache",
         'cookie':
         self.task.cookie,
         'pragma':
         "no-cache",
         'referer':
         "https://mail.qq.com/",
         'upgrade-insecure-requests':
         "1",
         'user-agent':
         "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36",
     }
     try:
         response = requests.request("GET", url, headers=headers)
         re_allfolder = re.compile(
             '<span\s*?id="folder_(\d+?)_[^"]*?"\s*?>\s*?(.*?)</span')
         all_folder = re_allfolder.findall(response.text)
         for folderinfo in all_folder:
             id = folderinfo[0]
             if id == '11':
                 continue
             name = folderinfo[1]
             folder_one = Folder()
             folder_one.folderid = id
             folder_one.name = name
             yield folder_one
     except Exception:
         self._logger.error(
             f"Get folder data error, err:{traceback.format_exc()}")
예제 #8
0
    def _get_folders(self) -> iter:
        try:
            url = "https://outlook.live.com/owa/sessiondata.ashx?appcacheclient=0"
            headers = """
        Accept:*/*
        Accept-Encoding:gzip, deflate
        Accept-Language:zh-CN,zh;q=0.8
        Cache-Control:max-age=0
        Connection:keep-alive
        Content-Length:0
        Origin:https://outlook.live.com
        Referer:https://outlook.live.com/
        User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36
        X-OWA-SmimeInstalled:1"""
            html = self._ha.getstring(url, headers=headers, req_data='')
            if not html.__contains__('findFolders'):
                self._logger.info('Got folder list fail!')
                return
            jshtml = json.loads(html)
            respMsgs = jshtml["findFolders"]["Body"]["ResponseMessages"][
                "Items"]
            if not respMsgs:
                self._logger.info('Folder list is none!')
                return
            for msg in respMsgs:
                items = msg['RootFolder']['Folders']
                for item in items:

                    try:
                        displayName = item["DisplayName"]
                        totalCount = item["TotalCount"]
                        if 'DistinguishedFolderId' in item.keys():
                            isDistingFolder = True
                            folderId = item["DistinguishedFolderId"]
                        else:
                            isDistingFolder = False
                            if totalCount < 1:
                                continue
                            elif 'FolderId' in item.keys(
                            ) and 'Id' in item["FolderId"].keys():
                                folderId = item["FolderId"]["Id"]
                            else:
                                continue
                        fo = Folder()
                        fo.folderid = folderId
                        fo.name = displayName
                        fo.mailcount = totalCount
                        fo.other = isDistingFolder
                        yield fo
                    except Exception:
                        self._logger.error('Got folder id fail: {}'.format(
                            traceback.format_exc()))

        except Exception:
            self._logger.error('Got folder fail: {}'.format(
                traceback.format_exc()))