Пример #1
0
    def _get_contacts(self) -> iter:
        url = "https://mail.qq.com/cgi-bin/laddr_list?" \
              "sid={}&operate=view&t=contact&view=normal&loc=frame_html,,,23".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/cgi-bin/frame_html?sid=FknE0k6DwoitPnIu&r=95be65ae9c260d6737411fa709d80de3",
            '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)
            contact_list = response.text
            re_all_name = re.compile(
                "\<span class\=\"name tf\"\>(.+?)\<\/span\>")
            allname = re_all_name.findall(contact_list)
            re_all_email = re.compile(
                "\<span class\=\"email tf\">(.+?)\<\/span\>")
            allemail = re_all_email.findall(contact_list)
            contact_all = CONTACT(self._clientid, self.task, self.task.apptype)
            for c_one in range(len(allname)):
                if c_one == 0:
                    continue
                contact_one = CONTACT_ONE(self._userid, allemail[c_one],
                                          self.task, self.task.apptype)
                contact_one.nickname = allname[c_one]
                contact_one.email = allemail[c_one]
                contact_all.append_innerdata(contact_one)
            if contact_all.innerdata_len > 0:
                yield contact_all
        except Exception:
            self._logger.error(
                f"Get contacts data error, err:{traceback.format_exc()}")
Пример #2
0
 def _get_users(self, sqlpath: str):
     """
     扫描联系人后缀的数据,添加task信息后返回
     :param sqlpath:
     :return:
     """
     limitdata = 1000
     offsetdata = 0
     while True:
         sql = '''SELECT 
         *
         FROM users LIMIT ? OFFSET ?'''
         pars = (
             limitdata,
             offsetdata,
         )
         offsetdata += limitdata
         res = self._select_data(sqlpath, sql, pars)
         if len(res) == 0:
             return
         all_contact = CONTACT(self._clientid, self.task, self.task.apptype)
         for el in res:
             try:
                 # 将为空的字段全部剔除
                 # eldict = {k: v for k, v in el.items() if v is not None}
                 eldict = el
                 if eldict.get('id') is None:
                     continue
                 contact_one = CONTACT_ONE(self._userid, eldict.get('id'),
                                           self.task, self.task.apptype)
                 if eldict.get('phone') is not None:
                     contact_one.phone = self._output_format_str(
                         eldict.pop('phone'))
                 nickname = b''
                 if eldict.get('last_name') is not None:
                     nickname += eldict.pop('last_name')
                 if eldict.get('first_name') is not None:
                     nickname += eldict.pop('first_name')
                 if nickname == b'' and eldict.get('username') is not None:
                     nickname += eldict.pop('username')
                 if nickname != b'':
                     contact_one.nickname = self._output_format_str(
                         nickname)
                 if eldict.get('contact') is not None:
                     contact_one.isfriend = eldict.pop('contact')
                 if eldict.get('mutualContact') is not None:
                     contact_one.bothfriend = eldict.pop('mutualContact')
                 if eldict.get('deleted') is not None:
                     contact_one.isdeleted = eldict.pop('deleted')
                 all_contact.append_innerdata(contact_one)
             except Exception:
                 self._logger.error(
                     f"Get profile error,err:{traceback.format_exc()}")
                 continue
         if all_contact.innerdata_len != 0:
             yield all_contact
         if len(res) < limitdata:
             break
Пример #3
0
 def _get_contact(self, contact_data: json) -> iter:
     contact_all = contact_data.get('linkmanList')
     gname_map: dict = contact_data.get('uuidGuuidGnameMap')
     if contact_all is None or len(contact_all) == 0:
         self._logger.error("No contact in this account.")
         return
     for line_one in contact_all:
         contact_id = line_one.get('uuid')
         data_one = CONTACT_ONE(self._userid, contact_id, self.task, self.task.apptype)
         data_one.phone = line_one.get('mobile')
         data_one.email = line_one.get('email')
         data_one.nickname = line_one.get('name')
         data_one.group = gname_map[contact_id][0][0]['groupName']
         yield data_one
Пример #4
0
 def _get_contacts(self):
     self._headers['Cookie'] = self.task.cookie
     contacturl = 'https://mail.tom.com/webmail/contact/querycontact.action'
     formdata = {'type': 'searchContacts', 'contactname': ''}
     try:
         # r = requests.post(contacturl, headers=self._headers, data=formdata)
         html = self._ha.getstring(
             contacturl,
             req_data="type=searchContacts&contactname=",
             headers="""
         Accept: application/json, text/javascript, */*; q=0.01
         Accept-Encoding: gzip, deflate
         Accept-Language: en-US,en;q=0.9
         Cache-Control: no-cache
         Connection: keep-alive
         Content-Length: 32
         Content-Type: application/x-www-form-urlencoded
         Origin: https://mail.tom.com
         Pragma: no-cache
         Referer: https://mail.tom.com/webmail/main/index.action
         Sec-Fetch-Dest: empty
         Sec-Fetch-Mode: cors
         Sec-Fetch-Site: same-origin
         User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36
         X-Requested-With: XMLHttpRequest""")
         condata = json.loads(html).get('result', {})
         if len(condata) == 0:
             return
         contact = CONTACT(self._clientid, self.task, self.task.apptype)
         for el in condata:
             eldict = {k: v for k, v in el.items() if v is not None}
             contactid = eldict.get('contactId')
             if contactid is not None:
                 contact_one = CONTACT_ONE(self._userid, contactid,
                                           self.task, self.task.apptype)
                 contact_one.nickname = eldict.get('contactName')
                 contact_one.email = eldict.get('contactEmail')
                 contact_one.append_details(eldict)
                 contact.append_innerdata(contact_one)
         if contact.innerdata_len == 0:
             return
         else:
             yield contact
     except Exception:
         self._logger.error("Get contact error, err: {}".format(
             traceback.format_exc()))
         return
Пример #5
0
    def _get_contacts(self) -> iter:
        if self.sid is None:
            self._logger.error("Invalid cookie")
        url = "https://mail.yeah.net/contacts/call.do"

        querystring = {
            "uid": self._userid,
            "sid": self.sid,
            "from": "webmail",
            "cmd": "newapi.getContacts",
            "vcardver": "3.0",
            "ctype": "all",
            "attachinfos": "yellowpage,frequentContacts",
            "freContLim": "20"
        }
        payload = '''order=[{"field":"N","desc":"false"}]'''

        headers = f'''
            Accept: */*
            Accept-Encoding: gzip, deflate, br
            Accept-Language: zh-CN,zh;q=0.9,en;q=0.8
            Cache-Control: no-cache
            Connection: keep-alive
            Content-Length: 36
            Content-type: application/x-www-form-urlencoded
            Host: mail.163.com
            Origin: https://mail.yeah.net
            Pragma: no-cache
            Referer: https://mail.yeah.net/js6/main.jsp?sid={self.sid}&df=mail163_letter
            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_test = self._ha.getstring(url,
                                          req_data=payload,
                                          headers=headers,
                                          params=querystring)

            res_text_json = json.loads(res_test)
            if res_text_json.get('code') != 200:
                self._logger.error(
                    f"Get contacts error, err:{traceback.format_exc()}")
                return
            con_list = res_text_json.get('data').get('contacts')
            if con_list is None or len(con_list) == 0:
                return
            groups_dict = {}
            groups = res_text_json.get('data').get('groups')
            for group in groups:
                group_cid = group['CID']
                group_name = group['N']
                groups_dict[group_cid] = group_name
            con_all = CONTACT(self._clientid, self.task, self.task.apptype)
            for one in con_list:
                name = one.get('FN')
                mail = one.get('EMAIL;type=INTERNET;type=pref')
                con_one = CONTACT_ONE(self._userid, mail, self.task,
                                      self.task.apptype)
                con_one.email = mail
                con_one.nickname = name
                if 'GROUPING' in one:
                    # 一个人可能有多个分组,用空格隔开
                    groupings = one.get('GROUPING').split(';')
                    for i in range(len(groupings)):
                        groupings[i] = groups_dict[groupings[i]]
                    group_names = ' '.join(groupings)
                    con_one.group = '=?utf-8?b?' + str(
                        base64.b64encode(group_names.encode('utf-8')), 'utf-8')
                con_all.append_innerdata(con_one)
            if con_all.innerdata_len > 0:
                yield con_all
        except Exception:
            self._logger.error(
                f"Get contact error, err:{traceback.format_exc()}")
Пример #6
0
    def __get_contacts(self, groupid):
        sid = self._get_cookie_sid()
        if sid is None:
            self._logger.error("Cannot get sid from cookie")
            return
        cguid = self._get_cookie_cguid()
        url = 'https://smsrebuild1.mail.10086.cn/addrsvr/GetContactsList?' \
              'sid={}&formattype=json&&comefrom=54&cguid={}'.format(sid, cguid)
        payload = '<object>\r\n  <string name="GroupId">{}</string>\r\n  <string name="Keyword" />\r\n  ' \
                  '<string name="Letter">All</string>\r\n  <string name="Filter" />\r\n  ' \
                  '<string name="Sort">name</string>\r\n  <string name="SortType" />\r\n ' \
                  ' <string name="Start">0</string>\r\n  <string name="End">1000</string>\r\n' \
                  '</object>'.format(groupid)
        payload = payload.encode('ascii')
        headers = {
            'accept':
            "*/*",
            'accept-encoding':
            "gzip, deflate, br",
            'accept-language':
            "zh-CN,zh;q=0.9,en;q=0.8",
            'cache-control':
            "no-cache,no-cache",
            'content-length':
            "290",
            'Content-Type':
            "text/xml",
            'cookie':
            self.task.cookie,
            'origin':
            "https://smsrebuild1.mail.10086.cn",
            'pragma':
            "no-cache",
            'referer':
            "https://smsrebuild1.mail.10086.cn//proxy.htm",
            'user-agent':
            "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
            "Chrome/70.0.3538.102 Safari/537.36",
        }

        try:
            response = requests.request("POST",
                                        url,
                                        data=payload,
                                        headers=headers)
            res_json = json.loads(response.text)
            if res_json.get('code') == "S_OK":
                for con in res_json.get('var').get('list'):
                    contactid = con.get('serialId')
                    if contactid is not None:
                        contact_one = CONTACT_ONE(self._userid, contactid,
                                                  self.task, self.task.apptype)
                        contact_one.nickname = con.get('name')
                        contact_one.email = con.get('email')
                        if con.get('mobile'
                                   ) is not None and con.get('mobile') != '':
                            contact_one.phone = con.get('mobile')
                        contact_one.append_details(con)
                        yield contact_one
        except Exception as err:
            self._logger.error("Get a contact error, err: {}".format(err))
            return
Пример #7
0
    def _get_contacts(self) -> iter:
        sid = self._get_sid()
        if sid is None:
            self._logger.error("Invalid cookie")
        url = "http://webmail.vip.163.com/contacts/call.do"

        querystring = {
            "uid": self._userid,
            "sid": sid,
            "from": "webmail",
            "cmd": "newapi.getContacts",
            "vcardver": "3.0",
            "ctype": "all",
            "attachinfos": "yellowpage,frequentContacts",
            "freContLim": "20",
            "limitinfo": "get"
        }

        payload = {'order': [{'field': 'N', 'desc': 'false'}]}
        headers = {
            'content-type':
            "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
            'Accept':
            "*/*",
            'Accept-Encoding':
            "gzip, deflate",
            'Accept-Language':
            "zh-CN,zh;q=0.9,en;q=0.8",
            'Cache-Control':
            "no-cache",
            'Content-Length':
            "36",
            'Content-type':
            "application/x-www-form-urlencoded",
            'Cookie':
            self.task.cookie.encode('utf-8'),
            'Host':
            "webmail.vip.163.com",
            'Origin':
            "http://webmail.vip.163.com",
            'Pragma':
            "no-cache",
            'Proxy-Connection':
            "keep-alive",
            'Referer':
            "http://webmail.vip.163.com/js6/main.jsp?sid={}&df=mailvip".format(
                sid),
            '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_text_json = json.loads(response.text)
            if res_text_json.get('code') != 200:
                self._logger.error(
                    f"Get contacts error, err:{traceback.format_exc()}")
                return
            con_list = res_text_json.get('data').get('contacts')
            if con_list is None or len(con_list) == 0:
                return
            con_all = CONTACT(self._clientid, self.task, self.task.apptype)
            for one in con_list:
                name = one.get('FN')
                mail = one.get('EMAIL;type=INTERNET;type=pref')
                con_one = CONTACT_ONE(self._userid, mail, self.task,
                                      self.task.apptype)
                con_one.email = mail
                con_one.nickname = name
                if one.get('TEL;type=CELL;type=VOICE;type=pref') is not None:
                    con_one.phone = one.get(
                        'TEL;type=CELL;type=VOICE;type=pref')
                con_all.append_innerdata(con_one)
            if con_all.innerdata_len > 0:
                yield con_all
        except Exception:
            self._logger.error(
                f"Get contact error, err:{traceback.format_exc()}")
Пример #8
0
 def _get_contacts(self) -> iter:
     url = "http://m0.mail.sina.com.cn/wa.php"
     querystring = {"a": "list_contact"}
     payload = {'gid': '0', 'sort_item': 'letter', 'sort_type': 'desc'}
     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_text = json.loads(response.text)
         if res_json_text.get('errno') != 0:
             self._logger.error("Get contact list error!")
             return
         contacts_data = res_json_text.get('data')
         if contacts_data is None:
             self._logger.error("No contacts data")
             return
         contacts = contacts_data.get('contact')
         if contacts is None or len(contacts) == 0:
             self._logger.error("No contacts data")
             return
         con_all = CONTACT(self._clientid, self.task, self.task.apptype)
         for con in contacts:
             uid = con.get('uid')
             name = con.get('name')
             email = con.get('email')
             con_one = CONTACT_ONE(self._userid, uid, self.task,
                                   self.task.apptype)
             con_one.nickname = name
             con_one.email = email
             con_all.append_innerdata(con_one)
         if con_all.innerdata_len > 0:
             yield con_all
     except Exception:
         self._logger.error(
             f"Got contacts error, err:{traceback.format_exc()}")
Пример #9
0
    def _read_datas(self, dbpath) -> iter:
        """read datas from db"""
        try:
            # 下载数据成功
            sql = '''SELECT * FROM msg
            '''
            res_lines = self._select_data(dbpath, sql)
            if len(res_lines) == 0:
                return
            contacts_all = {}
            logs_all = ICHATLOG(self._clientid, self.task, self.task.apptype)
            for line in res_lines:
                if line.get('content') is None and line.get('content') == '':
                    continue
                try:
                    conversionid = line.get('conversation_id').split(':')
                    if len(conversionid) != 0:
                        if self._userid == '':
                            self._userid = conversionid[-1]
                        contact_id = conversionid[-2]
                        contacts_all[contact_id] = 1
                    else:
                        continue
                    messagetype: EResourceType = self._resources_type.get(
                        line['type'])
                    sessionid = conversionid[-2]
                    messageid = line['msg_uuid']
                    senderid = line['sender']

                    cr_time = time.strftime(
                        '%Y-%m-%d %H:%M:%S',
                        time.localtime(line['created_time'] / 1000))
                    log_one = ICHATLOG_ONE(self.task, self.task.apptype,
                                           self._userid, messagetype.value,
                                           sessionid, 1, messageid, senderid,
                                           cr_time)
                    if messagetype == EResourceType.Picture or messagetype == EResourceType.Audio:
                        for res_file in self._get_resources(line, messagetype):
                            log_one.append_resource(res_file)
                            yield res_file
                    try:
                        json_text = json.loads(line['content'])
                    except Exception as err:
                        self._logger.error(
                            "Content data is not json, err:{}".format(err))
                        continue
                    # 文字
                    if json_text.get('text') is not None:
                        log_one.content = json_text.get('text')
                    logs_all.append_innerdata(log_one)
                except Exception:
                    self._logger.error(
                        "Parse one data line from db error: {} {}".format(
                            self.uname_str, traceback.format_exc()))
            if logs_all.innerdata_len > 0:
                yield logs_all
            if self._userid != '':
                p_data = PROFILE(self._clientid, self.task, self.task.apptype,
                                 self._userid)
                p_data.account = self._phone
                p_data.phone = self._phone
                yield p_data
            if len(contacts_all) != 0:
                ct_all = CONTACT(self._clientid, self.task, self.task.apptype)
                for ct in contacts_all:
                    ct_one = CONTACT_ONE(self._userid, ct, self.task,
                                         self.task.apptype)
                    ct_one.isfriend = 1
                    ct_one.isdeleted = 0
                    ct_all.append_innerdata(ct_one)
                yield ct_all
        except Exception:
            self._logger.error("Read datas from db error: {} {}".format(
                self.uname_str, traceback.format_exc()))