From 46d952598474e851ee528515d7a9ffab88d3ad49 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Tue, 12 Jul 2022 16:35:11 +0200 Subject: Implement APPEND --- src/mail/mailbox.rs | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'src/mail') diff --git a/src/mail/mailbox.rs b/src/mail/mailbox.rs index e80fa34..0e8af70 100644 --- a/src/mail/mailbox.rs +++ b/src/mail/mailbox.rs @@ -96,8 +96,13 @@ impl Mailbox { } /// 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 + pub async fn append<'a>( + &self, + msg: IMF<'a>, + ident: Option, + flags: &[Flag], + ) -> Result<(ImapUidvalidity, ImapUid)> { + self.mbox.write().await.append(msg, ident, flags).await } /// Insert an email into the mailbox, copying it from an existing S3 object @@ -260,7 +265,12 @@ impl MailboxInternal { self.uid_index.push(del_flag_op).await } - async fn append(&mut self, mail: IMF<'_>, ident: Option) -> Result<()> { + async fn append( + &mut self, + mail: IMF<'_>, + ident: Option, + flags: &[Flag], + ) -> Result<(ImapUidvalidity, ImapUid)> { let ident = ident.unwrap_or_else(|| gen_ident()); let message_key = gen_key(); @@ -292,13 +302,18 @@ impl MailboxInternal { )?; // Add mail to Bayou mail index - let add_mail_op = self - .uid_index - .state() - .op_mail_add(ident, vec!["\\Unseen".into()]); + let uid_state = self.uid_index.state(); + let add_mail_op = uid_state.op_mail_add(ident, flags.to_vec()); + + let uidvalidity = uid_state.uidvalidity; + let uid = match add_mail_op { + UidIndexOp::MailAdd(_, uid, _) => uid, + _ => unreachable!(), + }; + self.uid_index.push(add_mail_op).await?; - Ok(()) + Ok((uidvalidity, uid)) } async fn append_from_s3<'a>( -- cgit v1.2.3