mirror of
https://github.com/stalwartlabs/mail-server.git
synced 2025-10-10 04:25:44 +08:00
74 lines
2 KiB
Rust
74 lines
2 KiB
Rust
/*
|
|
* SPDX-FileCopyrightText: 2020 Stalwart Labs Ltd <hello@stalw.art>
|
|
*
|
|
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
|
|
*/
|
|
|
|
use compact_str::ToCompactString;
|
|
|
|
use crate::{
|
|
Command,
|
|
protocol::{ProtocolVersion, delete},
|
|
receiver::{Request, bad},
|
|
utf7::utf7_maybe_decode,
|
|
};
|
|
|
|
impl Request<Command> {
|
|
pub fn parse_delete(self, version: ProtocolVersion) -> trc::Result<delete::Arguments> {
|
|
match self.tokens.len() {
|
|
1 => Ok(delete::Arguments {
|
|
mailbox_name: utf7_maybe_decode(
|
|
self.tokens
|
|
.into_iter()
|
|
.next()
|
|
.unwrap()
|
|
.unwrap_string()
|
|
.map_err(|v| bad(self.tag.to_compact_string(), v))?,
|
|
version,
|
|
),
|
|
tag: self.tag,
|
|
}),
|
|
0 => Err(self.into_error("Missing mailbox name.")),
|
|
_ => Err(self.into_error("Too many arguments.")),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use crate::{
|
|
protocol::{ProtocolVersion, delete},
|
|
receiver::Receiver,
|
|
};
|
|
|
|
#[test]
|
|
fn parse_delete() {
|
|
let mut receiver = Receiver::new();
|
|
|
|
for (command, arguments) in [
|
|
(
|
|
"A142 DELETE INBOX\r\n",
|
|
delete::Arguments {
|
|
mailbox_name: "INBOX".into(),
|
|
tag: "A142".into(),
|
|
},
|
|
),
|
|
(
|
|
"A142 DELETE \"my funky mailbox\"\r\n",
|
|
delete::Arguments {
|
|
mailbox_name: "my funky mailbox".into(),
|
|
tag: "A142".into(),
|
|
},
|
|
),
|
|
] {
|
|
assert_eq!(
|
|
receiver
|
|
.parse(&mut command.as_bytes().iter())
|
|
.unwrap()
|
|
.parse_delete(ProtocolVersion::Rev2)
|
|
.unwrap(),
|
|
arguments
|
|
);
|
|
}
|
|
}
|
|
}
|