diff --git a/src/message.rs b/src/message.rs index a1ee437da1..cf6adf94f2 100644 --- a/src/message.rs +++ b/src/message.rs @@ -2618,12 +2618,29 @@ mod tests { ); alice.set_config(Config::DownloadLimit, None).await?; - let msg = alice.recv_msg(&sent_msg).await; + // Simulate that the message is even marked as `\Seen` on IMAP. + let rcvd_msg = receive_imf(alice, sent_msg.payload().as_bytes(), true) + .await + .unwrap() + .unwrap(); + assert_eq!(rcvd_msg.chat_id, msg.chat_id); + let msg = Message::load_from_db(alice, *rcvd_msg.msg_ids.last().unwrap()) + .await + .unwrap(); assert_eq!(msg.download_state, DownloadState::Done); assert!(msg.param.get_bool(Param::WantsMdn).unwrap_or_default()); assert!(msg.get_showpadlock()); + assert_eq!(msg.state, MessageState::InNoticed); + markseen_msgs(alice, vec![msg.id]).await?; + let msg = Message::load_from_db(alice, msg.id).await?; assert_eq!(msg.state, MessageState::InSeen); - + assert_eq!( + alice + .sql + .count("SELECT COUNT(*) FROM smtp_mdns", ()) + .await?, + 1 + ); Ok(()) } diff --git a/src/receive_imf.rs b/src/receive_imf.rs index e19696a284..aabfdd20b2 100644 --- a/src/receive_imf.rs +++ b/src/receive_imf.rs @@ -1014,13 +1014,15 @@ async fn add_parts( } } - state = if seen + state = if (seen && replace_msg_id.is_none()) || fetching_existing_messages || is_mdn || is_reaction || chat_id_blocked == Blocked::Yes { MessageState::InSeen + } else if seen { + MessageState::InNoticed } else { MessageState::InFresh }; @@ -1562,7 +1564,7 @@ INSERT INTO msgs ON CONFLICT (id) DO UPDATE SET rfc724_mid=excluded.rfc724_mid, chat_id=excluded.chat_id, from_id=excluded.from_id, to_id=excluded.to_id, timestamp_sent=excluded.timestamp_sent, - type=excluded.type, msgrmsg=excluded.msgrmsg, + type=excluded.type, state=min(state,max(excluded.state,13)), msgrmsg=excluded.msgrmsg, txt=excluded.txt, txt_normalized=excluded.txt_normalized, subject=excluded.subject, txt_raw=excluded.txt_raw, param=excluded.param, hidden=excluded.hidden,bytes=excluded.bytes, mime_headers=excluded.mime_headers,