From 4adaa988aa775b0b5303501b3c8c23921b13f76b Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Thu, 30 Jun 2022 10:59:42 +0200 Subject: Add prototypes for mailbox functions --- src/mail/mailbox.rs | 61 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 48 insertions(+), 13 deletions(-) (limited to 'src/mail') 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> { + 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> { + 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) -> 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> { - 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> { - 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> { let ids = ids.iter().map(|x| x.to_string()).collect::>(); 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) -> Result<()> { let ident = ident.unwrap_or_else(|| gen_ident()); let message_key = gen_key(); -- cgit v1.2.3