Merge remote-tracking branch 'upstream/master' into deltalab

This commit is contained in:
adbenitez
2020-08-07 20:41:49 -04:00
3 changed files with 96 additions and 22 deletions
+42
View File
@@ -1652,6 +1652,48 @@ class TestOnlineAccount:
assert "Ephemeral timer: " not in system_message2.get_message_info()
assert chat1.get_ephemeral_timer() == 0
def test_delete_multiple_messages(self, acfactory, lp):
ac1, ac2 = acfactory.get_two_online_accounts()
chat12 = acfactory.get_accepted_chat(ac1, ac2)
lp.sec("ac1: sending seven messages")
texts = ["first", "second", "third", "fourth", "fifth", "sixth", "seventh"]
for text in texts:
chat12.send_text(text)
# Ensure messages are delivered in exactly this order.
ac1._evtracker.get_matching("DC_EVENT_SMTP_MESSAGE_SENT")
ac1._evtracker.get_matching("DC_EVENT_MSG_DELIVERED")
lp.sec("ac2: waiting for all messages on the other side")
to_delete = []
for text in texts:
msg = ac2._evtracker.wait_next_incoming_message()
assert msg.text == text
if text != "third":
to_delete.append(msg)
lp.sec("ac2: deleting all messages except third")
assert len(to_delete) == len(texts) - 1
ac2.delete_messages(to_delete)
for msg in to_delete:
ac2._evtracker.get_matching("DC_EVENT_IMAP_MESSAGE_DELETED")
ac2._evtracker.get_info_contains("close/expunge succeeded")
lp.sec("imap2: test that only one message is left")
imap2 = ac2.direct_imap
# Flush unsolicited responses. IMAPClient has problems
# dealing with them: https://github.com/mjs/imapclient/issues/334
# When this NOOP was introduced, next FETCH returned empty
# result instead of a single message, even though IMAP server
# can only return more untagged responses than required, not
# less.
imap2.conn.noop()
assert len(imap2.get_all_messages()) == 1
class TestGroupStressTests:
def test_group_many_members_add_leave_remove(self, acfactory, lp):
+12 -2
View File
@@ -46,6 +46,12 @@ pub fn dehtml(buf: &str) -> String {
Ok(quick_xml::events::Event::End(ref e)) => dehtml_endtag_cb(e, &mut dehtml),
Ok(quick_xml::events::Event::Text(ref e)) => dehtml_text_cb(e, &mut dehtml),
Ok(quick_xml::events::Event::CData(ref e)) => dehtml_cdata_cb(e, &mut dehtml),
Ok(quick_xml::events::Event::Empty(ref e)) => {
// Handle empty tags as a start tag immediately followed by end tag.
// For example, `<p/>` is treated as `<p></p>`.
dehtml_starttag_cb(e, &mut dehtml, &reader);
dehtml_endtag_cb(&BytesEnd::borrowed(e.name()), &mut dehtml);
}
Err(e) => {
eprintln!(
"Parse html error: Error at position {}: {:?}",
@@ -182,6 +188,10 @@ mod tests {
("&amp; bar", "& bar"),
// Note missing '
("<a href='/foo.png>Hi</a> ", ""),
(
"<a href='https://get.delta.chat/'/>",
"[](https://get.delta.chat/)",
),
("", ""),
];
for (input, output) in cases {
@@ -191,10 +201,10 @@ mod tests {
#[test]
fn test_dehtml_parse_br() {
let html = "\r\r\nline1<br>\r\n\r\n\r\rline2\n\r";
let html = "\r\r\nline1<br>\r\n\r\n\r\rline2<br/>line3\n\r";
let plain = dehtml(html);
assert_eq!(plain, "line1\n\r\r\rline2");
assert_eq!(plain, "line1\n\r\r\rline2\nline3");
}
#[test]
+42 -20
View File
@@ -573,8 +573,14 @@ impl Imap {
let set = format!("{}", mailbox.exists);
match session.fetch(set, JUST_UID).await {
Ok(mut list) => {
if let Some(Ok(msg)) = list.next().await {
msg.uid.unwrap_or_default()
let mut new_last_seen_uid = None;
while let Some(fetch) = list.next().await.transpose()? {
if fetch.message == mailbox.exists && fetch.uid.is_some() {
new_last_seen_uid = fetch.uid;
}
}
if let Some(new_last_seen_uid) = new_last_seen_uid {
new_last_seen_uid
} else {
return Err(Error::Other("failed to fetch".into()));
}
@@ -970,7 +976,11 @@ impl Imap {
if let Some(ref mut session) = &mut self.session {
let query = format!("+FLAGS ({})", flag);
match session.uid_store(uid_set, &query).await {
Ok(_) => {}
Ok(mut responses) => {
while let Some(_response) = responses.next().await {
// Read all the responses
}
}
Err(err) => {
warn!(
context,
@@ -1073,8 +1083,35 @@ impl Imap {
if let Some(ref mut session) = &mut self.session {
match session.uid_fetch(set, DELETE_CHECK_FLAGS).await {
Ok(mut msgs) => {
let fetch = if let Some(Ok(fetch)) = msgs.next().await {
fetch
let mut remote_message_id = None;
while let Some(response) = msgs.next().await {
match response {
Ok(fetch) => {
if fetch.uid == Some(uid) {
remote_message_id = get_fetch_headers(&fetch)
.and_then(|headers| prefetch_get_message_id(&headers))
.ok();
}
}
Err(err) => {
warn!(context, "IMAP fetch error {}", err);
return ImapActionResult::RetryLater;
}
}
}
if let Some(remote_message_id) = remote_message_id {
if remote_message_id != message_id {
warn!(
context,
"Cannot delete on IMAP, {}: remote message-id '{}' != '{}'",
display_imap_id,
remote_message_id,
message_id,
);
return ImapActionResult::Failed;
}
} else {
warn!(
context,
@@ -1083,21 +1120,6 @@ impl Imap {
message_id,
);
return ImapActionResult::AlreadyDone;
};
let remote_message_id = get_fetch_headers(&fetch)
.and_then(|headers| prefetch_get_message_id(&headers))
.unwrap_or_default();
if remote_message_id != message_id {
warn!(
context,
"Cannot delete on IMAP, {}: remote message-id '{}' != '{}'",
display_imap_id,
remote_message_id,
message_id,
);
return ImapActionResult::Failed;
}
}
Err(err) => {