diff options
author | Alex Auvolat <alex@adnab.me> | 2022-07-12 16:35:11 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2022-07-12 16:35:11 +0200 |
commit | 46d952598474e851ee528515d7a9ffab88d3ad49 (patch) | |
tree | a062bc94e8a1841f8d017c97cccbebc1d44cf1a4 /src/mail/mailbox.rs | |
parent | d4e0e66581ff785e89edd15e2b8d68640f370a0e (diff) | |
download | aerogramme-46d952598474e851ee528515d7a9ffab88d3ad49.tar.gz aerogramme-46d952598474e851ee528515d7a9ffab88d3ad49.zip |
Implement APPEND
Diffstat (limited to 'src/mail/mailbox.rs')
-rw-r--r-- | src/mail/mailbox.rs | 31 |
1 files changed, 23 insertions, 8 deletions
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<UniqueIdent>) -> Result<()> { - self.mbox.write().await.append(msg, ident).await + pub async fn append<'a>( + &self, + msg: IMF<'a>, + ident: Option<UniqueIdent>, + 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<UniqueIdent>) -> Result<()> { + async fn append( + &mut self, + mail: IMF<'_>, + ident: Option<UniqueIdent>, + 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>( |