Merge pull request #1549 from deltachat/fix-reconnect-logic

This commit is contained in:
Friedel Ziegelmayer
2020-06-03 16:17:15 +02:00
committed by GitHub
3 changed files with 24 additions and 53 deletions

View File

@@ -978,15 +978,15 @@ class TestOnlineAccount:
msg_out = chat.send_text(text1)
assert not msg_out.is_encrypted()
lp.sec("wait for ac2 to receive multi-line non-unicode message")
msg_in = ac2._evtracker.wait_next_incoming_message()
assert msg_in.text == text1
lp.sec("sending multi-line unicode text message from ac1 to ac2")
text2 = "äalis\nthis is ßßÄ"
msg_out = chat.send_text(text2)
assert not msg_out.is_encrypted()
lp.sec("wait for ac2 to receive multi-line non-unicode message")
msg_in = ac2._evtracker.wait_next_incoming_message()
assert msg_in.text == text1
lp.sec("wait for ac2 to receive multi-line unicode message")
msg_in = ac2._evtracker.wait_next_incoming_message()
assert msg_in.text == text2

View File

@@ -295,6 +295,8 @@ impl Imap {
match login_res {
Ok(session) => {
// needs to be set here to ensure it is set on reconnects.
self.connected = true;
self.session = Some(session);
Ok(())
}

View File

@@ -77,13 +77,14 @@ async fn inbox_loop(ctx: Context, started: Sender<()>, inbox_handlers: ImapConne
let ctx1 = ctx.clone();
let fut = async move {
started.send(()).await;
let ctx = ctx1;
if let Err(err) = connection.connect_configured(&ctx).await {
error!(ctx, "{}", err);
return;
}
started.send(()).await;
// track number of continously executed jobs
let mut jobs_loaded = 0;
let mut probe_network = false;
@@ -102,7 +103,8 @@ async fn inbox_loop(ctx: Context, started: Sender<()>, inbox_handlers: ImapConne
}
None => {
jobs_loaded = 0;
probe_network = fetch_idle(&ctx, &mut connection).await;
probe_network =
fetch_idle(&ctx, &mut connection, "configured_inbox_folder").await;
}
}
}
@@ -122,12 +124,10 @@ async fn fetch(ctx: &Context, connection: &mut Imap) {
match get_watch_folder(&ctx, "configured_inbox_folder").await {
Some(watch_folder) => {
// fetch
connection
.fetch(&ctx, &watch_folder)
.await
.unwrap_or_else(|err| {
error!(ctx, "{}", err);
});
if let Err(err) = connection.fetch(&ctx, &watch_folder).await {
connection.trigger_reconnect();
error!(ctx, "{}", err);
}
}
None => {
warn!(ctx, "Can not fetch inbox folder, not set");
@@ -136,16 +136,14 @@ async fn fetch(ctx: &Context, connection: &mut Imap) {
}
}
async fn fetch_idle(ctx: &Context, connection: &mut Imap) -> bool {
match get_watch_folder(&ctx, "configured_inbox_folder").await {
async fn fetch_idle(ctx: &Context, connection: &mut Imap, folder: &str) -> bool {
match get_watch_folder(&ctx, folder).await {
Some(watch_folder) => {
// fetch
connection
.fetch(&ctx, &watch_folder)
.await
.unwrap_or_else(|err| {
error!(ctx, "{}", err);
});
if let Err(err) = connection.fetch(&ctx, &watch_folder).await {
connection.trigger_reconnect();
error!(ctx, "{}", err);
}
// idle
if connection.can_idle() {
@@ -153,6 +151,7 @@ async fn fetch_idle(ctx: &Context, connection: &mut Imap) -> bool {
.idle(&ctx, Some(watch_folder))
.await
.unwrap_or_else(|err| {
connection.trigger_reconnect();
error!(ctx, "{}", err);
false
})
@@ -185,46 +184,16 @@ async fn simple_imap_loop(
let ctx1 = ctx.clone();
let fut = async move {
started.send(()).await;
let ctx = ctx1;
if let Err(err) = connection.connect_configured(&ctx).await {
error!(ctx, "{}", err);
return;
}
loop {
match get_watch_folder(&ctx, folder.as_ref()).await {
Some(watch_folder) => {
// fetch
connection
.fetch(&ctx, &watch_folder)
.await
.unwrap_or_else(|err| {
error!(ctx, "{}", err);
});
started.send(()).await;
// idle
if connection.can_idle() {
connection
.idle(&ctx, Some(watch_folder))
.await
.unwrap_or_else(|err| {
error!(ctx, "{}", err);
false
});
} else {
connection.fake_idle(&ctx, Some(watch_folder)).await;
}
}
None => {
warn!(
&ctx,
"No watch folder found for {}, skipping",
folder.as_ref()
);
connection.fake_idle(&ctx, None).await;
}
}
loop {
fetch_idle(&ctx, &mut connection, folder.as_ref()).await;
}
};