Skip to content

Commit dd11a0e

Browse files
committed
refactor: replace imap:: calls in migration 73 with SQL queries
1 parent 3d86cb5 commit dd11a0e

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

src/imap.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2501,21 +2501,6 @@ pub(crate) async fn get_imap_self_sent_search_command(context: &Context) -> Resu
25012501
Ok(search_command)
25022502
}
25032503

2504-
/// Deprecated, use get_uid_next() and get_uidvalidity()
2505-
pub async fn get_config_last_seen_uid(context: &Context, folder: &str) -> Result<(u32, u32)> {
2506-
let key = format!("imap.mailbox.{folder}");
2507-
if let Some(entry) = context.sql.get_raw_config(&key).await? {
2508-
// the entry has the format `imap.mailbox.<folder>=<uidvalidity>:<lastseenuid>`
2509-
let mut parts = entry.split(':');
2510-
Ok((
2511-
parts.next().unwrap_or_default().parse().unwrap_or(0),
2512-
parts.next().unwrap_or_default().parse().unwrap_or(0),
2513-
))
2514-
} else {
2515-
Ok((0, 0))
2516-
}
2517-
}
2518-
25192504
/// Whether to ignore fetching messages from a folder.
25202505
///
25212506
/// This caters for the [`Config::OnlyFetchMvbox`] setting which means mails from folders

src/sql/migrations.rs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use crate::config::Config;
1414
use crate::configure::EnteredLoginParam;
1515
use crate::constants::ShowEmails;
1616
use crate::context::Context;
17-
use crate::imap;
1817
use crate::key::DcKey;
1918
use crate::log::{info, warn};
2019
use crate::message::MsgId;
@@ -413,11 +412,36 @@ CREATE TABLE imap_sync (folder TEXT PRIMARY KEY, uidvalidity INTEGER DEFAULT 0,
413412
"configured_mvbox_folder",
414413
] {
415414
if let Some(folder) = context.sql.get_raw_config(c).await? {
415+
let key = format!("imap.mailbox.{folder}");
416+
416417
let (uid_validity, last_seen_uid) =
417-
imap::get_config_last_seen_uid(context, &folder).await?;
418+
if let Some(entry) = context.sql.get_raw_config(&key).await? {
419+
// the entry has the format `imap.mailbox.<folder>=<uidvalidity>:<lastseenuid>`
420+
let mut parts = entry.split(':');
421+
(
422+
parts.next().unwrap_or_default().parse().unwrap_or(0),
423+
parts.next().unwrap_or_default().parse().unwrap_or(0),
424+
)
425+
} else {
426+
(0, 0)
427+
};
418428
if last_seen_uid > 0 {
419-
imap::set_uid_next(context, &folder, last_seen_uid + 1).await?;
420-
imap::set_uidvalidity(context, &folder, uid_validity).await?;
429+
context
430+
.sql
431+
.execute(
432+
"INSERT INTO imap_sync (folder, uid_next) VALUES (?,?)
433+
ON CONFLICT(folder) DO UPDATE SET uid_next=excluded.uid_next",
434+
(&folder, last_seen_uid + 1),
435+
)
436+
.await?;
437+
context
438+
.sql
439+
.execute(
440+
"INSERT INTO imap_sync (folder, uidvalidity) VALUES (?,?)
441+
ON CONFLICT(folder) DO UPDATE SET uidvalidity=excluded.uidvalidity",
442+
(&folder, uid_validity),
443+
)
444+
.await?;
421445
}
422446
}
423447
}

0 commit comments

Comments
 (0)