aboutsummaryrefslogtreecommitdiff
path: root/src/imap/command/examined.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-07-12 16:35:11 +0200
committerAlex Auvolat <alex@adnab.me>2022-07-12 16:35:11 +0200
commit46d952598474e851ee528515d7a9ffab88d3ad49 (patch)
treea062bc94e8a1841f8d017c97cccbebc1d44cf1a4 /src/imap/command/examined.rs
parentd4e0e66581ff785e89edd15e2b8d68640f370a0e (diff)
downloadaerogramme-46d952598474e851ee528515d7a9ffab88d3ad49.tar.gz
aerogramme-46d952598474e851ee528515d7a9ffab88d3ad49.zip
Implement APPEND
Diffstat (limited to 'src/imap/command/examined.rs')
-rw-r--r--src/imap/command/examined.rs43
1 files changed, 42 insertions, 1 deletions
diff --git a/src/imap/command/examined.rs b/src/imap/command/examined.rs
index 9dba680..ea773de 100644
--- a/src/imap/command/examined.rs
+++ b/src/imap/command/examined.rs
@@ -5,14 +5,19 @@ use boitalettres::proto::Request;
use boitalettres::proto::Response;
use imap_codec::types::command::{CommandBody, SearchKey};
use imap_codec::types::core::Charset;
+use imap_codec::types::core::NonZeroBytes;
+use imap_codec::types::datetime::MyDateTime;
use imap_codec::types::fetch_attributes::MacroOrFetchAttributes;
-
+use imap_codec::types::flag::{Flag, FlagNameAttribute};
+use imap_codec::types::mailbox::{ListMailbox, Mailbox as MailboxCodec};
+use imap_codec::types::response::{Code, Data, StatusAttributeValue};
use imap_codec::types::sequence::SequenceSet;
use crate::imap::command::authenticated;
use crate::imap::flow;
use crate::imap::mailbox_view::MailboxView;
+use crate::mail::uidindex::*;
use crate::mail::user::User;
pub struct ExaminedContext<'a> {
@@ -37,6 +42,12 @@ pub async fn dispatch<'a>(ctx: ExaminedContext<'a>) -> Result<(Response, flow::T
uid,
} => ctx.search(charset, criteria, uid).await,
CommandBody::Noop => ctx.noop().await,
+ CommandBody::Append {
+ mailbox,
+ flags,
+ date,
+ message,
+ } => ctx.append(mailbox, flags, date, message).await,
_ => {
let ctx = authenticated::AuthenticatedContext {
req: ctx.req,
@@ -85,4 +96,34 @@ impl<'a> ExaminedContext<'a> {
flow::Transition::None,
))
}
+
+ async fn append(
+ self,
+ mailbox: &MailboxCodec,
+ flags: &[Flag],
+ date: &Option<MyDateTime>,
+ message: &NonZeroBytes,
+ ) -> Result<(Response, flow::Transition)> {
+ let ctx2 = authenticated::AuthenticatedContext {
+ req: self.req,
+ user: self.user,
+ };
+
+ match ctx2.append_internal(mailbox, flags, date, message).await {
+ Ok((mb, uidvalidity, uid)) => {
+ let resp = Response::ok("APPEND completed")?.with_extra_code(Code::Other(
+ "APPENDUID".try_into().unwrap(),
+ Some(format!("{} {}", uidvalidity, uid)),
+ ));
+
+ if Arc::ptr_eq(&mb, &self.mailbox.mailbox) {
+ let data = self.mailbox.update().await?;
+ Ok((resp.with_body(data), flow::Transition::None))
+ } else {
+ Ok((resp, flow::Transition::None))
+ }
+ }
+ Err(e) => Ok((Response::no(&e.to_string())?, flow::Transition::None)),
+ }
+ }
}