Skip to content

Commit 609f30a

Browse files
committed
test: port test_dont_show_emails() from CFFI to JSON-RPC Python
1 parent 1cb0a25 commit 609f30a

File tree

2 files changed

+140
-134
lines changed

2 files changed

+140
-134
lines changed

deltachat-rpc-client/tests/test_something.py

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,3 +1012,143 @@ def check_account(ac, contact, inviter_side, please_wait_info_msg=False):
10121012
bob2.wait_for_event(EventType.CHAT_MODIFIED)
10131013

10141014
check_account(bob2, bob2.create_contact(alice), inviter_side=False)
1015+
1016+
1017+
def test_dont_show_emails(acfactory, direct_imap, log):
1018+
"""Most mailboxes have a "Drafts" folder where constantly new emails appear but we don't actually want to show them.
1019+
So: If it's outgoing AND there is no Received header, then ignore the email.
1020+
1021+
If the draft email is sent out and received later (i.e. it's in "Inbox"), it must be shown.
1022+
1023+
Also, test that unknown emails in the Spam folder are not shown."""
1024+
ac1 = acfactory.new_configured_account()
1025+
ac1.stop_io()
1026+
ac1.set_config("show_emails", "2")
1027+
1028+
ac1.create_contact("[email protected]").create_chat()
1029+
1030+
ac1_direct_imap = direct_imap(ac1)
1031+
ac1_direct_imap.create_folder("Drafts")
1032+
ac1_direct_imap.create_folder("Spam")
1033+
ac1_direct_imap.create_folder("Junk")
1034+
1035+
# Learn UID validity for all folders.
1036+
ac1.set_config("scan_all_folders_debounce_secs", "0")
1037+
ac1.start_io()
1038+
ac1.wait_for_event(EventType.IMAP_INBOX_IDLE)
1039+
ac1.stop_io()
1040+
1041+
ac1_direct_imap.append(
1042+
"Drafts",
1043+
"""
1044+
From: ac1 <{}>
1045+
Subject: subj
1046+
1047+
Message-ID: <[email protected]>
1048+
Content-Type: text/plain; charset=utf-8
1049+
1050+
message in Drafts received later
1051+
""".format(
1052+
ac1.get_config("configured_addr"),
1053+
),
1054+
)
1055+
ac1_direct_imap.append(
1056+
"Spam",
1057+
"""
1058+
1059+
Subject: subj
1060+
To: {}
1061+
Message-ID: <[email protected]>
1062+
Content-Type: text/plain; charset=utf-8
1063+
1064+
Unknown message in Spam
1065+
""".format(
1066+
ac1.get_config("configured_addr"),
1067+
),
1068+
)
1069+
ac1_direct_imap.append(
1070+
"Spam",
1071+
"""
1072+
1073+
Subject: subj
1074+
To: {}
1075+
Message-ID: <[email protected]>
1076+
Content-Type: text/plain; charset=utf-8
1077+
1078+
Unknown & malformed message in Spam
1079+
""".format(
1080+
ac1.get_config("configured_addr"),
1081+
),
1082+
)
1083+
ac1_direct_imap.append(
1084+
"Spam",
1085+
"""
1086+
From: delta<address: [email protected]>
1087+
Subject: subj
1088+
To: {}
1089+
Message-ID: <[email protected]>
1090+
Content-Type: text/plain; charset=utf-8
1091+
1092+
Unknown & malformed message in Spam
1093+
""".format(
1094+
ac1.get_config("configured_addr"),
1095+
),
1096+
)
1097+
ac1_direct_imap.append(
1098+
"Spam",
1099+
"""
1100+
1101+
Subject: subj
1102+
To: {}
1103+
Message-ID: <[email protected]>
1104+
Content-Type: text/plain; charset=utf-8
1105+
1106+
Actually interesting message in Spam
1107+
""".format(
1108+
ac1.get_config("configured_addr"),
1109+
),
1110+
)
1111+
ac1_direct_imap.append(
1112+
"Junk",
1113+
"""
1114+
1115+
Subject: subj
1116+
To: {}
1117+
Message-ID: <[email protected]>
1118+
Content-Type: text/plain; charset=utf-8
1119+
1120+
Unknown message in Junk
1121+
""".format(
1122+
ac1.get_config("configured_addr"),
1123+
),
1124+
)
1125+
1126+
ac1.set_config("scan_all_folders_debounce_secs", "0")
1127+
log.section("All prepared, now let DC find the message")
1128+
ac1.start_io()
1129+
1130+
# Wait until each folder was scanned, this is necessary for this test to test what it should test:
1131+
ac1.wait_for_event(EventType.IMAP_INBOX_IDLE)
1132+
1133+
fresh_msgs = list(ac1.get_fresh_messages())
1134+
msg = fresh_msgs[0].get_snapshot()
1135+
chat_msgs = msg.chat.get_messages()
1136+
assert len(chat_msgs) == 1
1137+
assert msg.text == "subj – Actually interesting message in Spam"
1138+
1139+
assert not any("unknown.address" in c.get_full_snapshot().name for c in ac1.get_chatlist())
1140+
ac1_direct_imap.select_folder("Spam")
1141+
assert ac1_direct_imap.get_uid_by_message_id("[email protected]")
1142+
1143+
ac1.stop_io()
1144+
log.section("'Send out' the draft by moving it to Inbox, and wait for DC to display it this time")
1145+
ac1_direct_imap.select_folder("Drafts")
1146+
uid = ac1_direct_imap.get_uid_by_message_id("[email protected]")
1147+
ac1_direct_imap.conn.move(uid, "Inbox")
1148+
1149+
ac1.start_io()
1150+
event = ac1.wait_for_event(EventType.MSGS_CHANGED)
1151+
msg2 = Message(ac1, event.msg_id).get_snapshot()
1152+
1153+
assert msg2.text == "subj – message in Drafts received later"
1154+
assert len(msg.chat.get_messages()) == 2

python/tests/test_1_online.py

Lines changed: 0 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -853,140 +853,6 @@ def test_no_draft_if_cant_send(acfactory):
853853
assert device_chat.get_draft() is None
854854

855855

856-
def test_dont_show_emails(acfactory, lp):
857-
"""Most mailboxes have a "Drafts" folder where constantly new emails appear but we don't actually want to show them.
858-
So: If it's outgoing AND there is no Received header, then ignore the email.
859-
860-
If the draft email is sent out and received later (i.e. it's in "Inbox"), it must be shown.
861-
862-
Also, test that unknown emails in the Spam folder are not shown."""
863-
ac1 = acfactory.new_online_configuring_account()
864-
ac1.set_config("show_emails", "2")
865-
ac1.create_contact("[email protected]").create_chat()
866-
867-
acfactory.wait_configured(ac1)
868-
ac1.direct_imap.create_folder("Drafts")
869-
ac1.direct_imap.create_folder("Spam")
870-
ac1.direct_imap.create_folder("Junk")
871-
872-
acfactory.bring_accounts_online()
873-
ac1.stop_io()
874-
875-
ac1.direct_imap.append(
876-
"Drafts",
877-
"""
878-
From: ac1 <{}>
879-
Subject: subj
880-
881-
Message-ID: <[email protected]>
882-
Content-Type: text/plain; charset=utf-8
883-
884-
message in Drafts received later
885-
""".format(
886-
ac1.get_config("configured_addr"),
887-
),
888-
)
889-
ac1.direct_imap.append(
890-
"Spam",
891-
"""
892-
893-
Subject: subj
894-
To: {}
895-
Message-ID: <[email protected]>
896-
Content-Type: text/plain; charset=utf-8
897-
898-
Unknown message in Spam
899-
""".format(
900-
ac1.get_config("configured_addr"),
901-
),
902-
)
903-
ac1.direct_imap.append(
904-
"Spam",
905-
"""
906-
907-
Subject: subj
908-
To: {}
909-
Message-ID: <[email protected]>
910-
Content-Type: text/plain; charset=utf-8
911-
912-
Unknown & malformed message in Spam
913-
""".format(
914-
ac1.get_config("configured_addr"),
915-
),
916-
)
917-
ac1.direct_imap.append(
918-
"Spam",
919-
"""
920-
From: delta<address: [email protected]>
921-
Subject: subj
922-
To: {}
923-
Message-ID: <[email protected]>
924-
Content-Type: text/plain; charset=utf-8
925-
926-
Unknown & malformed message in Spam
927-
""".format(
928-
ac1.get_config("configured_addr"),
929-
),
930-
)
931-
ac1.direct_imap.append(
932-
"Spam",
933-
"""
934-
935-
Subject: subj
936-
To: {}
937-
Message-ID: <[email protected]>
938-
Content-Type: text/plain; charset=utf-8
939-
940-
Actually interesting message in Spam
941-
""".format(
942-
ac1.get_config("configured_addr"),
943-
),
944-
)
945-
ac1.direct_imap.append(
946-
"Junk",
947-
"""
948-
949-
Subject: subj
950-
To: {}
951-
Message-ID: <[email protected]>
952-
Content-Type: text/plain; charset=utf-8
953-
954-
Unknown message in Junk
955-
""".format(
956-
ac1.get_config("configured_addr"),
957-
),
958-
)
959-
960-
ac1.set_config("scan_all_folders_debounce_secs", "0")
961-
lp.sec("All prepared, now let DC find the message")
962-
ac1.start_io()
963-
964-
# Wait until each folder was scanned, this is necessary for this test to test what it should test:
965-
ac1._evtracker.wait_idle_inbox_ready()
966-
967-
fresh_msgs = list(ac1.get_fresh_messages())
968-
msg = fresh_msgs[0]
969-
chat_msgs = msg.chat.get_messages()
970-
assert len(chat_msgs) == 1
971-
assert any(msg.text == "subj – Actually interesting message in Spam" for msg in chat_msgs)
972-
973-
assert not any("unknown.address" in c.get_name() for c in ac1.get_chats())
974-
ac1.direct_imap.select_folder("Spam")
975-
assert ac1.direct_imap.get_uid_by_message_id("[email protected]")
976-
977-
ac1.stop_io()
978-
lp.sec("'Send out' the draft by moving it to Inbox, and wait for DC to display it this time")
979-
ac1.direct_imap.select_folder("Drafts")
980-
uid = ac1.direct_imap.get_uid_by_message_id("[email protected]")
981-
ac1.direct_imap.conn.move(uid, "Inbox")
982-
983-
ac1.start_io()
984-
msg2 = ac1._evtracker.wait_next_messages_changed()
985-
986-
assert msg2.text == "subj – message in Drafts received later"
987-
assert len(msg.chat.get_messages()) == 2
988-
989-
990856
def test_bot(acfactory, lp):
991857
"""Test that bot messages can be identified as such"""
992858
ac1, ac2 = acfactory.get_online_accounts(2)

0 commit comments

Comments
 (0)