コード例 #1
0
ファイル: push_sender.py プロジェクト: mathlover777/cron_jobs
def get_deltas_to_push(email_id, token, all_delta_info_list, white_list):
	# print all_delta_info_list
	delta_info_list = filter(lambda x:x["unread"],all_delta_info_list)
	request_set = set([])
	for delta_info in delta_info_list:
		plist = delta_info["participants"]
		# print plist
		for participant in plist:
			request_set.add(participant["email"])
	score_dict = token_store.get_contact_score_list(email_id,list(request_set))
	blacklist = token_store.get_blacklist(email_id)
	old_time = token_store.get_last_updated_time_stamp(email_id)
	# print score_dict

	good_deltas = filter( lambda x:nylas_helper.is_object_important(x, blacklist, old_time, email_id, white_list,score_dict,[y['email'] for y in x['participants']]) , delta_info_list)
	# print good_deltas

	return good_deltas
コード例 #2
0
ファイル: push_sender.py プロジェクト: mathlover777/cron_jobs
def get_deltas_to_push(email_id, token, all_delta_info_list, white_list):
    # print all_delta_info_list
    delta_info_list = filter(lambda x: x["unread"], all_delta_info_list)
    request_set = set([])
    for delta_info in delta_info_list:
        plist = delta_info["participants"]
        # print plist
        for participant in plist:
            request_set.add(participant["email"])
    score_dict = token_store.get_contact_score_list(email_id,
                                                    list(request_set))
    blacklist = token_store.get_blacklist(email_id)
    old_time = token_store.get_last_updated_time_stamp(email_id)
    # print score_dict

    good_deltas = filter(
        lambda x: nylas_helper.is_object_important(
            x, blacklist, old_time, email_id, white_list, score_dict,
            [y['email'] for y in x['participants']]), delta_info_list)
    # print good_deltas

    return good_deltas
コード例 #3
0
def tag_unread_mails_in_time_range(email_id,
                                   token,
                                   now_time,
                                   old_time,
                                   white_list,
                                   social_list=[],
                                   use_psync=False):
    if use_psync:
        client = nylas.APIClient(PLANCK_APP_ID,
                                 PLANCK_APP_SECRET,
                                 token,
                                 api_server=psync_url)
    else:
        client = nylas.APIClient(APP_ID, APP_SECRET, token)
    ns = client

    recent_threads = ns.threads.where(
        **{
            'last_message_after': old_time - 600,
            'last_message_before': now_time,
            'in': 'inbox'
        })
    # recent_threads = ns.threads.where(**{'from':'*****@*****.**', 'in':'inbox'})
    recent_threads_list = [x for x in recent_threads]

    request_set = set([])
    for thread in recent_threads_list:
        # print thread['participants']
        plist = get_other_participants_in_thread(thread, email_id)
        for participant in plist:
            request_set.add(participant)

    score_dict = token_store.get_contact_score_list(email_id,
                                                    list(request_set))

    if use_labels(ns):
        inbox_id = get_id(ns, 'Inbox')
        read_now_id = get_id(ns, 'Read Now')
        read_later_id = get_id(ns, 'Read Later')
        if read_later_id is None:
            read_later_id = get_id(ns, 'Read Later')
        social_id = get_id(ns, 'Social')
        if social_id is None:
            social_id = add_label(ns, 'Social')
        #as per new rules, mails from blacklisted email ids should be deleted.
        blacklist_id = get_id(ns, 'Trash')
        label_flag = True
    else:
        inbox_id = get_folder_id(ns, 'Inbox')
        read_now_id = get_folder_id(ns, 'Read Now')
        read_later_id = get_folder_id(ns, 'Read Later')
        if read_later_id is None:
            read_later_id = add_folder(ns, 'Read Later')
        social_id = get_folder_id(ns, 'Social')
        if social_id is None:
            social_id = add_folder(ns, 'Social')

        blacklist_id = get_folder_id(client, 'Trash')
        if blacklist_id is None:
            blacklist_id = get_folder_id(client, 'Deleted Items')
            if blacklist_id is None:
                blacklist_id = add_folder(client, 'Trash')
                print 'Created Trash folder for', email_id

        label_flag = False

    for thread in recent_threads_list:
        # TODO refactor using is_object_important
        plist = get_other_participants_in_thread(thread, email_id)

        blacklist = token_store.get_blacklist(email_id)
        blacklist_flag = False
        if overlap(plist, blacklist) > 0:
            blacklist_flag = True

        if (blacklist_flag):
            # print 'INFO:', email_id, thread['id'], "B"
            add_thread_to_blacklist(thread, label_flag, blacklist_id)
            continue

        social_list_flag = is_social_mail(email_id, thread['subject'],
                                          thread['participants'], social_list)

        important_flag = is_from_planck(plist)
        if not important_flag:
            important_flag = is_white_listed_mail(thread['subject'],
                                                  white_list)
        if not important_flag:
            important_flag = contains_contact(email_id, plist)
        if not important_flag:
            for p_id in plist:
                important_flag = is_new_contact(ns, old_time - 600, p_id,
                                                thread)
                if important_flag:
                    break

        score = 0.0
        for participant in plist:
            score += score_dict[participant.encode('ascii', 'ignore').lower()]

        if score > 0 or important_flag:
            #TODO: check if the email is not marked as something else
            add_thread_to_readnow(thread, label_flag, inbox_id, read_now_id,
                                  read_later_id)
            # print 'INFO:',email_id, thread['id'],"N"
        else:
            if (social_list_flag):
                # print 'INFO:',email_id,thread['id'],"S",
                add_thread_to_social(thread, label_flag, inbox_id, read_now_id,
                                     social_id)
                continue
            add_thread_to_clutter(thread, label_flag, inbox_id, read_now_id,
                                  read_later_id)
            # tag_thread_given_condition(thread,label_flag,read_now_id,read_later_id,score,boolean_flags)
            # print 'INFO:',email_id, thread['id'],"L"
    return
コード例 #4
0
def tag_unread_mails_in_time_range(email_id,token,now_time,old_time,white_list, social_list=[], use_psync=False):
	if use_psync:
		client = nylas.APIClient(PLANCK_APP_ID, PLANCK_APP_SECRET, token, api_server=psync_url)
	else:
		client = nylas.APIClient(APP_ID, APP_SECRET, token)
	ns = client

	recent_threads = ns.threads.where(**{'last_message_after':old_time-600,'last_message_before' :now_time, 'in':'inbox'})
	# recent_threads = ns.threads.where(**{'from':'*****@*****.**', 'in':'inbox'})
	recent_threads_list = [x for x in recent_threads]

	request_set = set([])
	for thread in recent_threads_list:
		# print thread['participants']
		plist = get_other_participants_in_thread(thread,email_id)
		for participant in plist:
			request_set.add(participant)
	
	score_dict = token_store.get_contact_score_list(email_id,list(request_set))

	if use_labels(ns):
		inbox_id = get_id(ns, 'Inbox')
		read_now_id = get_id(ns,'Read Now')
		read_later_id = get_id(ns,'Read Later')
		if read_later_id is None:
			read_later_id = get_id(ns, 'Read Later')
		social_id = get_id(ns, 'Social')
		if social_id is None:
			social_id = add_label(ns, 'Social')
		#as per new rules, mails from blacklisted email ids should be deleted.
		blacklist_id = get_id(ns, 'Trash')
		label_flag = True
	else:
		inbox_id = get_folder_id(ns, 'Inbox')
		read_now_id = get_folder_id(ns,'Read Now')
		read_later_id = get_folder_id(ns,'Read Later')
		if read_later_id is None:
			read_later_id = add_folder(ns, 'Read Later')
		social_id = get_folder_id(ns, 'Social')
		if social_id is None:
			social_id = add_folder(ns, 'Social')

		blacklist_id = get_folder_id(client, 'Trash')
		if blacklist_id is None:
			blacklist_id = get_folder_id(client, 'Deleted Items')
			if blacklist_id is None:
				blacklist_id = add_folder(client, 'Trash')
				print 'Created Trash folder for',email_id

		label_flag = False
	
	for thread in recent_threads_list:
		# TODO refactor using is_object_important
		plist = get_other_participants_in_thread(thread,email_id)
		
		blacklist = token_store.get_blacklist(email_id)
		blacklist_flag = False
		if overlap(plist, blacklist) > 0:
			blacklist_flag = True

		if(blacklist_flag):
			# print 'INFO:', email_id, thread['id'], "B"
			add_thread_to_blacklist(thread, label_flag, blacklist_id)
			continue

		social_list_flag = is_social_mail(email_id, thread['subject'], thread['participants'], social_list)

		important_flag = is_from_planck(plist)
		if not important_flag:
			important_flag = is_white_listed_mail(thread['subject'],white_list)
		if not important_flag:
			important_flag = contains_contact(email_id, plist)
		if not important_flag:
			for p_id in plist:
				important_flag = is_new_contact(ns, old_time-600, p_id, thread)
				if important_flag:
					break

		score = 0.0
		for participant in plist:
			score += score_dict[participant.encode('ascii','ignore').lower()]

		if score > 0 or important_flag:
			#TODO: check if the email is not marked as something else
			add_thread_to_readnow(thread, label_flag, inbox_id, read_now_id, read_later_id)
			# print 'INFO:',email_id, thread['id'],"N"
		else:
			if(social_list_flag):
				# print 'INFO:',email_id,thread['id'],"S", 
				add_thread_to_social(thread, label_flag, inbox_id, read_now_id, social_id)
				continue
			add_thread_to_clutter(thread, label_flag, inbox_id, read_now_id, read_later_id)
			# tag_thread_given_condition(thread,label_flag,read_now_id,read_later_id,score,boolean_flags)
			# print 'INFO:',email_id, thread['id'],"L"
	return