def test_link_threads_part3(gm_client, msgs): gm_client.add_emails([ {}, {'refs': '<none-two@mlr>'}, {'refs': '<none@mlr>'}, {'refs': '<none@mlr> <102@mlr>'} ]) refs = [ '<*****@*****.**>', '<*****@*****.**> <none-two@mlr>', '<*****@*****.**> <none@mlr>', '<*****@*****.**> <none@mlr> <102@mlr>' ] assert local.search_thrs('all') == ['4', '3', '1'] assert local.data_threads.get()[1] == { '1': ['1'], '3': ['3'], '4': ['2', '4'] } res = msgs(local.SRC) assert [i['body']['references'] for i in res] == [ None, '<none-two@mlr>', '<none@mlr>', '<none@mlr> <102@mlr>', ] res = msgs() assert [i['body']['references'] for i in res] == refs local.link_threads(['1', '3', '4']) assert local.search_thrs('all') == ['4'] assert local.data_threads.get()[1] == {'4': ['1', '2', '3', '4']} res = msgs() assert [i['body']['references'] for i in res] == refs assert local.search_thrs('uid 1') == [i[0] for i in local.thrs_info(['1'])]
def test_thrid_header(gm_client, msgs): def raw(num, refs=None): refs = ('\r\nReferences: %s' % refs) if refs else '' return '\r\n'.join([ 'X-Thread-ID: <mlr/thrid/[email protected]>', 'Date: Wed, 07 Jan 2015 13:23:{num:02d} +0000', 'From: [email protected]', 'To: [email protected]', 'MIME-Version: 1.0', 'Content-type: text/html; charset=utf-8', 'Content-Transfer-Encoding: 8bit', 'Message-ID: <thrid-{num:02d}@mlr>', 'Subject: thrid' + refs, '' 'thrid', ]).format(num=num, refs=refs).encode() gm_client.add_emails([{'raw': raw(i)} for i in range(3)]) assert local.search_thrs('all') == ['3'] assert local.data_threads.get()[1] == {'3': ['1', '2', '3']} assert [i[0] for i in local.thrs_info(['1'])] == ['3'] gm_client.add_emails([{'refs': '<thrid-01@mlr> <thrid-04@mlr>'}]) assert local.search_thrs('all') == ['4'] assert local.data_threads.get()[1] == {'4': ['1', '2', '3', '4']} assert [i[0] for i in local.thrs_info(['1'])] == ['4'] gm_client.add_emails([{'raw': raw(4)}]) assert local.search_thrs('all') == ['5'] assert local.data_threads.get()[1] == {'5': ['1', '2', '3', '4', '5']} assert [i[0] for i in local.thrs_info(['1'])] == ['5'] gm_client.add_emails([{'raw': raw(5, '<thrid-03@mlr> <thrid-06@mlr>')}]) assert local.search_thrs('all') == ['6'] assert local.data_threads.get()[1] == {'6': ['1', '2', '3', '4', '5', '6']} assert [i[0] for i in local.thrs_info(['1'])] == ['6'] gm_client.add_emails([{ 'from': '*****@*****.**', 'to': 'Test <*****@*****.**>', 'subj': 'Same aubject' }] * 2) assert local.search_thrs('all') == ['8', '6'] assert local.data_threads.get()[1] == { '6': ['1', '2', '3', '4', '5', '6'], '8': ['7', '8'], } assert [i['body']['X-Thread-ID'] for i in msgs() ][-2:] == ['<*****@*****.**>'] * 2
def test_thrid_header(gm_client, msgs): def raw(num, refs=None): refs = ('\r\nReferences: %s' % refs) if refs else '' return '\r\n'.join([ 'X-Thread-ID: <mlr/thrid/[email protected]>', 'Date: Wed, 07 Jan 2015 13:23:{num:02d} +0000', 'From: [email protected]', 'To: [email protected]', 'MIME-Version: 1.0', 'Content-type: text/html; charset=utf-8', 'Content-Transfer-Encoding: 8bit', 'Message-ID: <thrid-{num:02d}@mlr>', 'Subject: thrid' + refs, '' 'thrid', ]).format(num=num, refs=refs).encode() gm_client.add_emails([{'raw': raw(i)} for i in range(3)]) assert local.search_thrs('all') == ['3'] assert local.data_threads.get()[1] == {'3': ['1', '2', '3']} assert [i[0] for i in local.thrs_info(['1'])] == ['3'] gm_client.add_emails([{'refs': '<thrid-01@mlr> <thrid-04@mlr>'}]) assert local.search_thrs('all') == ['4'] assert local.data_threads.get()[1] == {'4': ['1', '2', '3', '4']} assert [i[0] for i in local.thrs_info(['1'])] == ['4'] gm_client.add_emails([{'raw': raw(4)}]) assert local.search_thrs('all') == ['5'] assert local.data_threads.get()[1] == {'5': ['1', '2', '3', '4', '5']} assert [i[0] for i in local.thrs_info(['1'])] == ['5'] gm_client.add_emails([{'raw': raw(5, '<thrid-03@mlr> <thrid-06@mlr>')}]) assert local.search_thrs('all') == ['6'] assert local.data_threads.get()[1] == {'6': ['1', '2', '3', '4', '5', '6']} assert [i[0] for i in local.thrs_info(['1'])] == ['6'] gm_client.add_emails([ {'from': '*****@*****.**', 'to': 'Test <*****@*****.**>', 'subj': 'Same aubject'} ] * 2) assert local.search_thrs('all') == ['8', '6'] assert local.data_threads.get()[1] == { '6': ['1', '2', '3', '4', '5', '6'], '8': ['7', '8'], } assert [i['body']['X-Thread-ID'] for i in msgs()][-2:] == [ '<*****@*****.**>' ] * 2
def test_link_threads_part3(gm_client, msgs): gm_client.add_emails([{}, { 'refs': '<non-exist-two@mlr>' }, { 'refs': '<non-exist@mlr>' }, { 'refs': '<non-exist@mlr> <102@mlr>' }]) res = msgs(local.SRC) assert thread() == ( ('1', ), ('3', ), ('2', '4'), ) assert [i['flags'] for i in res] == ['', '', '', ''] assert [i['body']['references'] for i in res] == [ None, '<non-exist-two@mlr>', '<non-exist@mlr>', '<non-exist@mlr> <102@mlr>', ] res = msgs() assert [i['uid'] for i in res] == ['1', '2', '3', '4'] assert [i['flags'] for i in res] == ['#latest', '', '#latest', '#latest'] assert [i['body']['references'] for i in res] == [ '<*****@*****.**>', '<*****@*****.**>', '<*****@*****.**>', '<102@mlr>' ] local.link_threads(['1', '3', '4']) res = msgs(local.SRC) assert [i['flags'] for i in res] == ['', '', '', '', '\\Seen #link'] assert [i['body']['references'] for i in res] == [ None, '<non-exist-two@mlr>', '<non-exist@mlr>', '<non-exist@mlr> <102@mlr>', ('<*****@*****.**> <101@mlr> ' '<*****@*****.**> <102@mlr> ' '<*****@*****.**> <103@mlr> ' '<104@mlr>') ] res = msgs() assert [i['uid'] for i in res] == ['1', '2', '3', '4', '5'] assert [i['flags'] for i in res] == ['', '', '', '#latest', '\\Seen #link'] assert [i['body']['references'] for i in res] == [ '<*****@*****.**>', '<*****@*****.**>', '<*****@*****.**>', '<102@mlr>', ('<*****@*****.**> <101@mlr> ' '<*****@*****.**> <102@mlr> ' '<*****@*****.**> <103@mlr> ' '<104@mlr>') ] assert local.search_thrs('uid 1') == [i[0] for i in local.thrs_info(['1'])]
def test_link_threads_part1(gm_client, msgs): gm_client.add_emails([{}, {}]) res = msgs() assert ['1', '2'] == [i['uid'] for i in res] assert ['#latest', '#latest'] == [i['flags'] for i in res] assert [i['body']['references'] for i in res] == [ '<*****@*****.**>', '<*****@*****.**>' ] local.link_threads(['1', '2']) res = msgs(local.SRC) assert (('1', '2', '3'), ) == thread() assert ['', '', '\\Seen #link'] == [i['flags'] for i in res] assert [i['body']['references'] for i in res] == [ None, None, ('<*****@*****.**> <101@mlr> ' '<*****@*****.**> <102@mlr>') ] res = msgs() assert ['1', '2', '3'] == [i['uid'] for i in res] assert ['', '#latest', '\\Seen #link'] == [i['flags'] for i in res] assert [i['body']['references'] for i in res] == [ '<*****@*****.**>', '<*****@*****.**>', ('<*****@*****.**> <101@mlr> ' '<*****@*****.**> <102@mlr>') ] local.parse('all') res = msgs(local.SRC) assert (('1', '2', '3'), ) == thread() assert ['', '', '\\Seen #link'] == [i['flags'] for i in res] res = msgs() assert ['4', '5', '6'] == [i['uid'] for i in res] assert ['', '#latest', '\\Seen #link'] == [i['flags'] for i in res] assert [i['body']['references'] for i in res] == [ '<*****@*****.**>', '<*****@*****.**>', ('<*****@*****.**> <101@mlr> ' '<*****@*****.**> <102@mlr>') ] gm_client.add_emails([{}]) local.link_threads(['4', '7']) res = msgs(local.SRC) assert (('1', '2', '4', '5'), ) == thread() assert ['1', '2', '4', '5'] == [i['uid'] for i in res] assert [i['flags'] for i in res] == ['', '', '', '\\Seen #link'] assert [i['body']['references'] for i in res] == [ None, None, None, ('<*****@*****.**> <101@mlr> ' '<*****@*****.**> <102@mlr> ' '<*****@*****.**> <103@mlr>') ] res = msgs() assert ['4', '5', '7', '8'] == [i['uid'] for i in res] assert ['', '', '#latest', '\\Seen #link'] == [i['flags'] for i in res] assert [i['body']['references'] for i in res] == [ '<*****@*****.**>', '<*****@*****.**>', '<*****@*****.**>', ('<*****@*****.**> <101@mlr> ' '<*****@*****.**> <102@mlr> ' '<*****@*****.**> <103@mlr>') ] gm_client.add_emails([{'refs': '<101@mlr>'}]) res = msgs(local.SRC) assert (('1', '2', '4', '5', '6'), ) == thread() assert ['1', '2', '4', '5', '6'] == [i['uid'] for i in res] assert [i['flags'] for i in res] == ['', '', '', '\\Seen #link', ''] assert [i['body']['references'] for i in res] == [ None, None, None, ('<*****@*****.**> <101@mlr> ' '<*****@*****.**> <102@mlr> ' '<*****@*****.**> <103@mlr>'), '<101@mlr>' ] res = msgs() assert ['4', '5', '7', '8', '9'] == [i['uid'] for i in res] assert [i['flags'] for i in res] == ['', '', '', '\\Seen #link', '#latest'] assert [i['body']['references'] for i in res] == [ '<*****@*****.**>', '<*****@*****.**>', '<*****@*****.**>', ('<*****@*****.**> <101@mlr> ' '<*****@*****.**> <102@mlr> ' '<*****@*****.**> <103@mlr>'), '<101@mlr>' ] assert local.search_thrs('uid 4') == [i[0] for i in local.thrs_info(['4'])] local.update_links() res = msgs(local.SRC) assert (('1', '2', '4', '6', '7'), ) == thread() assert ['1', '2', '4', '6', '7'] == [i['uid'] for i in res] assert [i['flags'] for i in res] == ['', '', '', '', '\\Seen #link'] res = msgs() assert ['4', '5', '7', '9', '10'] == [i['uid'] for i in res] assert [i['flags'] for i in res] == ['', '', '', '#latest', '\\Seen #link']
def test_data_threads(gm_client): gm_client.add_emails([{'subj': 'new subj'}]) assert local.data_threads.get()[1] == {'1': ['1']} assert local.search_thrs('all') == ['1'] local.parse('all') assert local.data_threads.get()[1] == {'2': ['2']} assert local.search_thrs('all') == ['2'] gm_client.add_emails([{'subj': 'new subj'}]) assert local.data_threads.get()[1] == {'3': ['2', '3']} assert local.search_thrs('all') == ['3'] gm_client.add_emails([{'in_reply_to': '<101@mlr>'}]) assert local.data_threads.get()[1] == {'4': ['2', '3', '4']} assert local.search_thrs('all') == ['4'] gm_client.add_emails([{'refs': '<101@mlr> <102@mlr>'}]) assert local.data_threads.get()[1] == {'5': ['2', '3', '4', '5']} assert local.search_thrs('all') == ['5'] local.parse('all') assert local.data_threads.get()[1] == {'9': ['6', '7', '8', '9']} assert local.search_thrs('all') == ['9'] local.parse('uid *') assert local.data_threads.get()[1] == {'10': ['6', '7', '8', '10']} assert local.search_thrs('all') == ['10'] local.update_threads('1:*') assert local.data_threads.get()[1] == {'10': ['6', '7', '8', '10']} assert local.search_thrs('all') == ['10'] local.update_threads('1') assert local.data_threads.get()[1] == {'10': ['6', '7', '8', '10']} assert local.search_thrs('all') == ['10'] local.update_threads('1:*') assert local.data_threads.get()[1] == {'10': ['6', '7', '8', '10']} assert local.search_thrs('all') == ['10'] gm_client.add_emails([ {'refs': '<non-exist@mlr>'}, {'refs': '<non-exist@mlr> <101@mlr>'} ]) assert local.data_threads.get()[1] == { '11': ['11'], '12': ['6', '7', '8', '10', '12'] } assert local.search_thrs('all') == ['12', '11'] gm_client.add_emails([{'labels': 't1'}, {'labels': 't2'}], parse=False) local.parse('UID 6:*') assert local.data_threads.get()[1] == { '11': ['11'], '13': ['6', '7', '8', '10', '13'], '14': ['14'], '15': ['15'] } assert local.search_thrs('all') == ['15', '14', '13', '11'] local.update_threads('*') assert local.data_threads.get()[1] == { '11': ['11'], '13': ['6', '7', '8', '10', '13'], '14': ['14'], '15': ['15'] } assert local.search_thrs('all') == ['15', '14', '13', '11']