aboutsummaryrefslogtreecommitdiff
path: root/src/mail/mailbox.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-06-30 10:59:42 +0200
committerAlex Auvolat <alex@adnab.me>2022-06-30 10:59:42 +0200
commit4adaa988aa775b0b5303501b3c8c23921b13f76b (patch)
treed0c1cc42527352780446a1363eb7b91b1f5cb469 /src/mail/mailbox.rs
parent27e3d7a0a28f042aea329f7f77f30756019a0c0b (diff)
downloadaerogramme-4adaa988aa775b0b5303501b3c8c23921b13f76b.tar.gz
aerogramme-4adaa988aa775b0b5303501b3c8c23921b13f76b.zip
Add prototypes for mailbox functions
Diffstat (limited to 'src/mail/mailbox.rs')
-rw-r--r--src/mail/mailbox.rs61
1 files changed, 48 insertions, 13 deletions
diff --git a/src/mail/mailbox.rs b/src/mail/mailbox.rs
index 479021d..8057fe7 100644
--- a/src/mail/mailbox.rs
+++ b/src/mail/mailbox.rs
@@ -45,15 +45,45 @@ impl Mailbox {
self.mbox.write().await.sync().await
}
+ // ---- Functions for reading the mailbox ----
+
/// Get a clone of the current UID Index of this mailbox
/// (cloning is cheap so don't hesitate to use this)
pub async fn current_uid_index(&self) -> UidIndex {
self.mbox.read().await.uid_index.state().clone()
}
- /// Insert an email in the mailbox
- pub async fn append<'a>(&self, msg: IMF<'a>) -> Result<()> {
- self.mbox.write().await.append(msg, None).await
+ /// Fetch the metadata (headers + some more info) of the specified
+ /// mail IDs
+ pub async fn fetch_meta(&self, ids: &[UniqueIdent]) -> Result<Vec<MailMeta>> {
+ self.mbox.read().await.fetch_meta(ids).await
+ }
+
+ /// Fetch an entire e-mail
+ pub async fn fetch_full(&self, id: UniqueIdent, message_key: &Key) -> Result<Vec<u8>> {
+ self.mbox.read().await.fetch_full(id, message_key).await
+ }
+
+ // ---- Functions for changing the mailbox ----
+
+ /// Add flags to message
+ pub async fn add_flags<'a>(&self, id: UniqueIdent, flags: &[Flag]) -> Result<()> {
+ self.mbox.write().await.add_flags(id, flags).await
+ }
+
+ /// Delete flags from message
+ pub async fn del_flags<'a>(&self, id: UniqueIdent, flags: &[Flag]) -> Result<()> {
+ self.mbox.write().await.del_flags(id, flags).await
+ }
+
+ /// Insert an email into the mailbox
+ pub async fn append<'a>(&self, msg: IMF<'a>, ident: Option<UniqueIdent>) -> Result<()> {
+ self.mbox.write().await.append(msg, ident).await
+ }
+
+ /// Delete a message definitively from the mailbox
+ pub async fn delete<'a>(&self, id: UniqueIdent) -> Result<()> {
+ self.mbox.write().await.delete(id).await
}
/// Copy an email from an other Mailbox to this mailbox
@@ -68,16 +98,7 @@ impl Mailbox {
unimplemented!()
}
- /// Fetch the metadata (headers + some more info) of the specified
- /// mail IDs
- pub async fn fetch_meta(&self, ids: &[UniqueIdent]) -> Result<Vec<MailMeta>> {
- self.mbox.read().await.fetch_meta(ids).await
- }
-
- /// Fetch an entire e-mail
- pub async fn fetch_full(&self, id: UniqueIdent, message_key: &Key) -> Result<Vec<u8>> {
- self.mbox.read().await.fetch_full(id, message_key).await
- }
+ // ----
/// Test procedure TODO WILL REMOVE THIS
pub async fn test(&self) -> Result<()> {
@@ -107,6 +128,8 @@ impl MailboxInternal {
Ok(())
}
+ // ---- Functions for reading the mailbox ----
+
async fn fetch_meta(&self, ids: &[UniqueIdent]) -> Result<Vec<MailMeta>> {
let ids = ids.iter().map(|x| x.to_string()).collect::<Vec<_>>();
let ops = ids
@@ -162,6 +185,18 @@ impl MailboxInternal {
Ok(cryptoblob::open(&buf, &message_key)?)
}
+ // ---- Functions for changing the mailbox ----
+
+ async fn add_flags(&mut self, ident: UniqueIdent, flags: &[Flag]) -> Result<()> {
+ let add_flag_op = self.uid_index.state().op_flag_add(ident, flags.to_vec());
+ self.uid_index.push(add_flag_op).await
+ }
+
+ async fn del_flags(&mut self, ident: UniqueIdent, flags: &[Flag]) -> Result<()> {
+ let del_flag_op = self.uid_index.state().op_flag_del(ident, flags.to_vec());
+ self.uid_index.push(del_flag_op).await
+ }
+
async fn append(&mut self, mail: IMF<'_>, ident: Option<UniqueIdent>) -> Result<()> {
let ident = ident.unwrap_or_else(|| gen_ident());
let message_key = gen_key();