mirror of
https://github.com/chatmail/core.git
synced 2026-04-06 07:32:12 +03:00
fixing imap interactions
This commit is contained in:
@@ -1,93 +1,63 @@
|
||||
import sys
|
||||
import time
|
||||
|
||||
from deltachat.direct_imap import SEEN, FLAGS, FETCH
|
||||
|
||||
|
||||
def test_basic_message_seen(acfactory, tmpdir):
|
||||
def test_basic_imap_api(acfactory, tmpdir):
|
||||
ac1, ac2 = acfactory.get_two_online_accounts()
|
||||
chat12 = acfactory.get_chat(ac1, ac2)
|
||||
|
||||
imap2 = acfactory.new_imap_conn(ac2)
|
||||
|
||||
imap2.idle()
|
||||
chat12.send_text("hello")
|
||||
ac2._evtracker.wait_next_incoming_message()
|
||||
|
||||
imap2 = acfactory.new_imap_conn(ac2)
|
||||
imap2.dump_imap_structures(tmpdir, logfile=sys.stdout)
|
||||
imap2.idle_check(terminate=True)
|
||||
assert imap2.get_unread_cnt() == 1
|
||||
imap2.mark_all_read()
|
||||
assert imap2.get_unread_cnt() == 0
|
||||
|
||||
imap2.dump_imap_structures(tmpdir, logfile=sys.stdout)
|
||||
imap2.shutdown()
|
||||
|
||||
|
||||
class TestDirectImap:
|
||||
def test_mark_read_on_server(self, acfactory, lp):
|
||||
ac1 = acfactory.get_online_configuring_account()
|
||||
ac2 = acfactory.get_online_configuring_account(mvbox=True, move=True)
|
||||
ac1, ac2 = acfactory.get_two_online_accounts(move=False)
|
||||
|
||||
ac1.wait_configure_finish()
|
||||
ac1.start_io()
|
||||
ac2.wait_configure_finish()
|
||||
ac2.start_io()
|
||||
imap1 = acfactory.new_imap_conn(ac1, config_folder="inbox")
|
||||
assert imap1.get_unread_cnt() == 0
|
||||
chat12, chat21 = acfactory.get_chats(ac1, ac2)
|
||||
|
||||
imap2 = acfactory.new_imap_conn(ac2, config_folder="mvbox")
|
||||
imap2.mark_all_read()
|
||||
assert imap2.get_unread_cnt() == 0
|
||||
# send a message and check IMAP read flag
|
||||
imap1.idle()
|
||||
chat21.send_text("Text message")
|
||||
|
||||
chat, chat_on_ac2 = acfactory.get_chats(ac1, ac2)
|
||||
msg_in = ac1._evtracker.wait_next_incoming_message()
|
||||
assert list(ac1.get_fresh_messages())
|
||||
|
||||
chat.send_text("Text message")
|
||||
|
||||
incoming_on_ac2 = ac2._evtracker.wait_next_incoming_message()
|
||||
lp.sec("Incoming: "+incoming_on_ac2.text)
|
||||
|
||||
assert list(ac2.get_fresh_messages())
|
||||
|
||||
for i in range(0, 20):
|
||||
if imap2.get_unread_cnt() == 1:
|
||||
break
|
||||
time.sleep(1) # We might need to wait because Imaplib is slower than DC-Core
|
||||
assert imap2.get_unread_cnt() == 1
|
||||
|
||||
chat_on_ac2.mark_noticed()
|
||||
incoming_on_ac2.mark_seen()
|
||||
ac2._evtracker.wait_next_messages_changed()
|
||||
|
||||
assert not list(ac2.get_fresh_messages())
|
||||
|
||||
# The new messages should be seen now.
|
||||
for i in range(0, 20):
|
||||
if imap2.get_unread_cnt() == 0:
|
||||
break
|
||||
time.sleep(1) # We might need to wait because Imaplib is slower than DC-Core
|
||||
assert imap2.get_unread_cnt() == 0
|
||||
imap1.idle_check()
|
||||
msg_in.mark_seen()
|
||||
imap1.idle_check(terminate=True)
|
||||
assert imap1.get_unread_cnt() == 0
|
||||
|
||||
def test_mark_bcc_read_on_server(self, acfactory, lp):
|
||||
ac1 = acfactory.get_online_configuring_account(mvbox=True, move=True)
|
||||
ac2 = acfactory.get_online_configuring_account()
|
||||
ac1, ac2 = acfactory.get_two_online_accounts(move=True)
|
||||
|
||||
ac1.wait_configure_finish()
|
||||
ac1.start_io()
|
||||
ac2.wait_configure_finish()
|
||||
ac2.start_io()
|
||||
|
||||
imap1 = acfactory.new_imap_conn(ac1, config_folder="mvbox")
|
||||
imap1.mark_all_read()
|
||||
assert imap1.get_unread_cnt() == 0
|
||||
imap1_mvbox = acfactory.new_imap_conn(ac1, config_folder="mvbox")
|
||||
|
||||
chat = acfactory.get_chat(ac1, ac2)
|
||||
|
||||
ac1.set_config("bcc_self", "1")
|
||||
# wait for seen/read message to appear in mvbox
|
||||
imap1_mvbox.idle()
|
||||
chat.send_text("Text message")
|
||||
|
||||
ac1._evtracker.get_matching("DC_EVENT_SMTP_MESSAGE_SENT")
|
||||
|
||||
for i in range(0, 20):
|
||||
if imap1.get_new_email_cnt() == 1:
|
||||
break
|
||||
time.sleep(1) # We might need to wait because Imaplib is slower than DC-Core
|
||||
assert imap1.get_new_email_cnt() == 1
|
||||
|
||||
for i in range(0, 20):
|
||||
if imap1.get_unread_cnt() == 0:
|
||||
break
|
||||
time.sleep(1) # We might need to wait because Imaplib is slower than DC-Core
|
||||
|
||||
assert imap1.get_unread_cnt() == 0
|
||||
while 1:
|
||||
res = imap1_mvbox.idle_check()
|
||||
for item in res:
|
||||
uid = item[0]
|
||||
if item[1] == FETCH:
|
||||
if item[2][0] == FLAGS and SEEN in item[2][1]:
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user