File tree Expand file tree Collapse file tree 2 files changed +31
-5
lines changed
Expand file tree Collapse file tree 2 files changed +31
-5
lines changed Original file line number Diff line number Diff line change @@ -2284,11 +2284,7 @@ pub(crate) async fn prefetch_should_download(
22842284 message_id : & str ,
22852285 mut flags : impl Iterator < Item = Flag < ' _ > > ,
22862286) -> Result < bool > {
2287- if message:: rfc724_mid_exists ( context, message_id)
2288- . await ?
2289- . is_some ( )
2290- {
2291- markseen_on_imap_table ( context, message_id) . await ?;
2287+ if message:: downloaded_rfc724_mid_exists ( context, message_id) . await ? {
22922288 return Ok ( false ) ;
22932289 }
22942290
Original file line number Diff line number Diff line change @@ -2176,6 +2176,36 @@ pub(crate) async fn rfc724_mid_exists_ex(
21762176 Ok ( res)
21772177}
21782178
2179+ /// Returns [MsgId] of the most recent message with given `rfc724_mid`
2180+ /// (Message-ID header) and bool `expr` result if such messages exists in the db.
2181+ ///
2182+ /// * `expr`: SQL expression additionally passed into `SELECT`. Evaluated to `true` iff it is true
2183+ /// for all messages with the given `rfc724_mid`.
2184+ pub ( crate ) async fn downloaded_rfc724_mid_exists (
2185+ context : & Context ,
2186+ rfc724_mid : & str ,
2187+ ) -> Result < bool > {
2188+ let rfc724_mid = rfc724_mid. trim_start_matches ( '<' ) . trim_end_matches ( '>' ) ;
2189+ if rfc724_mid. is_empty ( ) {
2190+ warn ! (
2191+ context,
2192+ "Empty rfc724_mid passed to downloaded_rfc724_mid_exists"
2193+ ) ;
2194+ return Ok ( false ) ;
2195+ }
2196+
2197+ let res = context
2198+ . sql
2199+ . exists (
2200+ "SELECT COUNT(*) FROM msgs
2201+ WHERE rfc724_mid=? AND download_state<>?" ,
2202+ ( rfc724_mid, DownloadState :: Available ) ,
2203+ )
2204+ . await ?;
2205+
2206+ Ok ( res)
2207+ }
2208+
21792209/// Given a list of Message-IDs, returns the most relevant message found in the database.
21802210///
21812211/// Relevance here is `(download_state == Done, index)`, where `index` is an index of Message-ID in
You can’t perform that action at this time.
0 commit comments