summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2020-03-24 23:05:29 +0100
committerMatthias Beyer <mail@beyermatthias.de>2020-06-01 14:00:20 +0200
commit884521221c741f99602fd565b99a7717d7c123f5 (patch)
tree8f93977a5ebda9b456b73b6ec6eb080dceacd571
parentd53d0938cf8d06b3649643f58ca16d3cb0d37f4c (diff)
Add `quick` parameter to MailStoreWithConnection::import_with_query()
See the newly introduced comment. Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--lib/domain/libimagmail/src/store.rs20
1 files changed, 18 insertions, 2 deletions
diff --git a/lib/domain/libimagmail/src/store.rs b/lib/domain/libimagmail/src/store.rs
index 262af9cd..2e1077d4 100644
--- a/lib/domain/libimagmail/src/store.rs
+++ b/lib/domain/libimagmail/src/store.rs
@@ -66,7 +66,16 @@ impl<'a> Deref for MailStoreWithConnection<'a> {
}
impl<'a> MailStoreWithConnection<'a> {
- pub fn import_with_query(&self, q: &str, tag_as_mail: Option<String>, import_tags: bool) -> Result<Vec<FileLockEntry<'a>>> {
+ /// Import by asking notmuch for a list of messages
+ ///
+ /// This function uses the passed notmuch query to get a list of mails from the notmuch
+ /// database. Each message is then imported to the imag store.
+ ///
+ /// If `import_tags` is true, the message tags are imported as well.
+ /// If `quick` is true and the message id already exists in the imag database, the entry is not
+ /// imported. This might result in not syncronized tags.
+ ///
+ pub fn import_with_query(&self, q: &str, tag_as_mail: Option<String>, import_tags: bool, quick: bool) -> Result<Vec<FileLockEntry<'a>>> {
let mut new_entries = vec![];
self.connection
@@ -75,7 +84,14 @@ impl<'a> MailStoreWithConnection<'a> {
query
.search_messages()?
.map(|message| {
- let mut entry = self.retrieve_entry_for_id(message.id())?;
+ let mid = message.id();
+
+ // short circuit if we want this to be fast (`quick` is true)
+ if quick && self.entry_exists_by_id(&mid)? {
+ return Ok(())
+ }
+
+ let mut entry = self.retrieve_entry_for_id(mid)?;
if let Some(tag_as_mail) = tag_as_mail.as_ref() {
entry.add_tag(tag_as_mail.clone())?;
}