summaryrefslogtreecommitdiffstats
path: root/melib
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2020-10-13 13:57:04 +0300
committerManos Pitsidianakis <el13635@mail.ntua.gr>2020-10-13 13:57:04 +0300
commitcd68008e670200ac6aa879bbc99a72149789adab (patch)
tree810f4c1c5036b4d8dd2ac07a121c3e5414770b05 /melib
parent19891a304271fb6b1d2240e5222e1ddeb29ff444 (diff)
melib: Implement delete_messages for IMAP, Maildir
Diffstat (limited to 'melib')
-rw-r--r--melib/src/backends.rs14
-rw-r--r--melib/src/backends/imap.rs23
-rw-r--r--melib/src/backends/jmap.rs8
-rw-r--r--melib/src/backends/maildir/backend.rs31
-rw-r--r--melib/src/backends/mbox.rs8
-rw-r--r--melib/src/backends/nntp.rs14
-rw-r--r--melib/src/backends/notmuch.rs8
7 files changed, 94 insertions, 12 deletions
diff --git a/melib/src/backends.rs b/melib/src/backends.rs
index 7d4dda40..d64a008d 100644
--- a/melib/src/backends.rs
+++ b/melib/src/backends.rs
@@ -335,15 +335,11 @@ pub trait MailBackend: ::std::fmt::Debug + Send + Sync {
) -> ResultFuture<()>;
fn delete_messages(
- &self,
- _env_hashes: EnvelopeHashBatch,
- _mailbox_hash: MailboxHash,
- ) -> ResultFuture<()> {
- Err(MeliError::new("Unimplemented."))
- }
- fn delete(&self, _env_hash: EnvelopeHash, _mailbox_hash: MailboxHash) -> ResultFuture<()> {
- Err(MeliError::new("Unimplemented."))
- }
+ &mut self,
+ env_hashes: EnvelopeHashBatch,
+ mailbox_hash: MailboxHash,
+ ) -> ResultFuture<()>;
+
fn tags(&self) -> Option<Arc<RwLock<BTreeMap<u64, String>>>> {
None
}
diff --git a/melib/src/backends/imap.rs b/melib/src/backends/imap.rs
index 8ef7d940..07704f4d 100644
--- a/melib/src/backends/imap.rs
+++ b/melib/src/backends/imap.rs
@@ -807,6 +807,29 @@ impl MailBackend for ImapType {
}))
}
+ fn delete_messages(
+ &mut self,
+ env_hashes: EnvelopeHashBatch,
+ mailbox_hash: MailboxHash,
+ ) -> ResultFuture<()> {
+ let flag_future = self.set_flags(
+ env_hashes,
+ mailbox_hash,
+ smallvec::smallvec![(Ok(Flag::TRASHED), true)],
+ )?;
+ let connection = self.connection.clone();
+ Ok(Box::pin(async move {
+ flag_future.await?;
+ let mut response = Vec::with_capacity(8 * 1024);
+ let mut conn = connection.lock().await;
+ conn.send_command("EXPUNGE".as_bytes()).await?;
+ conn.read_response(&mut response, RequiredResponses::empty())
+ .await?;
+ debug!("EXPUNGE response: {}", &String::from_utf8_lossy(&response));
+ Ok(())
+ }))
+ }
+
fn tags(&self) -> Option<Arc<RwLock<BTreeMap<u64, String>>>> {
Some(self.uid_store.tag_index.clone())
}
diff --git a/melib/src/backends/jmap.rs b/melib/src/backends/jmap.rs
index 2ee314a5..ab3e1dd1 100644
--- a/melib/src/backends/jmap.rs
+++ b/melib/src/backends/jmap.rs
@@ -788,6 +788,14 @@ impl MailBackend for JmapType {
Ok(())
}))
}
+
+ fn delete_messages(
+ &mut self,
+ _env_hashes: EnvelopeHashBatch,
+ _mailbox_hash: MailboxHash,
+ ) -> ResultFuture<()> {
+ Err(MeliError::new("Unimplemented."))
+ }
}
impl JmapType {
diff --git a/melib/src/backends/maildir/backend.rs b/melib/src/backends/maildir/backend.rs
index a0e759c5..422b1d75 100644
--- a/melib/src/backends/maildir/backend.rs
+++ b/melib/src/backends/maildir/backend.rs
@@ -913,6 +913,37 @@ impl MailBackend for MaildirType {
}))
}
+ fn delete_messages(
+ &mut self,
+ env_hashes: EnvelopeHashBatch,
+ mailbox_hash: MailboxHash,
+ ) -> ResultFuture<()> {
+ let hash_index = self.hash_indexes.clone();
+ Ok(Box::pin(async move {
+ let mut hash_indexes_lck = hash_index.lock().unwrap();
+ let hash_index = hash_indexes_lck.entry(mailbox_hash).or_default();
+
+ for env_hash in env_hashes.iter() {
+ let _path = {
+ if !hash_index.contains_key(&env_hash) {
+ continue;
+ }
+ if let Some(modif) = &hash_index[&env_hash].modified {
+ match modif {
+ PathMod::Path(ref path) => path.clone(),
+ PathMod::Hash(hash) => hash_index[&hash].to_path_buf(),
+ }
+ } else {
+ hash_index[&env_hash].to_path_buf()
+ }
+ };
+
+ fs::remove_file(&_path)?;
+ }
+ Ok(())
+ }))
+ }
+
fn copy_messages(
&mut self,
env_hashes: EnvelopeHashBatch,
diff --git a/melib/src/backends/mbox.rs b/melib/src/backends/mbox.rs
index 378ba062..a00af89a 100644
--- a/melib/src/backends/mbox.rs
+++ b/melib/src/backends/mbox.rs
@@ -1012,6 +1012,14 @@ impl MailBackend for MboxType {
Err(MeliError::new("Unimplemented."))
}
+ fn delete_messages(
+ &mut self,
+ _env_hashes: EnvelopeHashBatch,
+ _mailbox_hash: MailboxHash,
+ ) -> ResultFuture<()> {
+ Err(MeliError::new("Unimplemented."))
+ }
+
fn save(
&self,
_bytes: Vec<u8>,
diff --git a/melib/src/backends/nntp.rs b/melib/src/backends/nntp.rs
index 413c2134..48e5c955 100644
--- a/melib/src/backends/nntp.rs
+++ b/melib/src/backends/nntp.rs
@@ -278,7 +278,7 @@ impl MailBackend for NntpType {
_mailbox_hash: MailboxHash,
_flags: Option<Flag>,
) -> ResultFuture<()> {
- Err(MeliError::new("Unimplemented."))
+ Err(MeliError::new("NNTP doesn't support saving."))
}
fn copy_messages(
@@ -288,7 +288,7 @@ impl MailBackend for NntpType {
_destination_mailbox_hash: MailboxHash,
_move_: bool,
) -> ResultFuture<()> {
- Err(MeliError::new("Unimplemented."))
+ Err(MeliError::new("NNTP doesn't support copying/moving."))
}
fn set_flags(
@@ -297,7 +297,15 @@ impl MailBackend for NntpType {
_mailbox_hash: MailboxHash,
_flags: SmallVec<[(std::result::Result<Flag, String>, bool); 8]>,
) -> ResultFuture<()> {
- Err(MeliError::new("Unimplemented."))
+ Err(MeliError::new("NNTP doesn't support flags."))
+ }
+
+ fn delete_messages(
+ &mut self,
+ _env_hashes: EnvelopeHashBatch,
+ _mailbox_hash: MailboxHash,
+ ) -> ResultFuture<()> {
+ Err(MeliError::new("NNTP doesn't support deletion."))
}
fn tags(&self) -> Option<Arc<RwLock<BTreeMap<u64, String>>>> {
diff --git a/melib/src/backends/notmuch.rs b/melib/src/backends/notmuch.rs
index 512fcf00..1d8c48f8 100644
--- a/melib/src/backends/notmuch.rs
+++ b/melib/src/backends/notmuch.rs
@@ -802,6 +802,14 @@ impl MailBackend for NotmuchDb {
}))
}
+ fn delete_messages(
+ &mut self,
+ _env_hashes: EnvelopeHashBatch,
+ _mailbox_hash: MailboxHash,
+ ) -> ResultFuture<()> {
+ Err(MeliError::new("Unimplemented."))
+ }
+
fn search(
&self,
melib_query: crate::search::Query,