fixup! add support for the imap quota extension (RFC 2087)
This commit is contained in:
parent
b3529a058f
commit
733aba99fe
2 changed files with 43 additions and 1 deletions
|
|
@ -2450,6 +2450,27 @@ mod tests {
|
|||
assert_quota_resource("a.resources[0], QuotaResourceName::Storage, 500, 10);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_quota_via_quota_resource_limit_new() {
|
||||
let response = b"* QUOTA my_root (STORAGE 10 500)\r\n\
|
||||
a1 OK completed\r\n"
|
||||
.to_vec();
|
||||
let mock_stream = MockStream::new(response);
|
||||
let mut session = mock_session!(mock_stream);
|
||||
let quota = session
|
||||
.set_quota("my_root", &[QuotaResourceLimit::new("STORAGE", 500)])
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
session.stream.get_ref().written_buf,
|
||||
b"a1 SETQUOTA \"my_root\" (STORAGE 500)\r\n".to_vec(),
|
||||
"Invalid setquota command"
|
||||
);
|
||||
let quota = quota.parsed().as_ref().unwrap();
|
||||
assert_eq!(quota.root_name, "my_root");
|
||||
assert_eq!(quota.resources.len(), 1);
|
||||
assert_quota_resource("a.resources[0], QuotaResourceName::Storage, 500, 10);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_quota_no_such_quota_root() {
|
||||
let response = b"a1 NO no such quota root\r\n".to_vec();
|
||||
|
|
|
|||
|
|
@ -21,7 +21,8 @@ pub struct QuotaResourceLimit<'a> {
|
|||
|
||||
impl<'a> QuotaResourceLimit<'a> {
|
||||
/// Creates a new [`QuotaResourceLimit`]
|
||||
pub fn new(name: QuotaResourceName<'a>, amount: u64) -> Self {
|
||||
pub fn new(name: impl Into<QuotaResourceName<'a>>, amount: u64) -> Self {
|
||||
let name = name.into();
|
||||
Self { name, amount }
|
||||
}
|
||||
}
|
||||
|
|
@ -46,6 +47,18 @@ pub enum QuotaResourceName<'a> {
|
|||
Atom(Cow<'a, str>),
|
||||
}
|
||||
|
||||
impl<'a> From<&'a str> for QuotaResourceName<'a> {
|
||||
fn from(input: &'a str) -> Self {
|
||||
if input == "STORAGE" {
|
||||
QuotaResourceName::Storage
|
||||
} else if input == "MESSAGE" {
|
||||
QuotaResourceName::Message
|
||||
} else {
|
||||
QuotaResourceName::Atom(Cow::from(input))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for QuotaResourceName<'_> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
|
|
@ -243,4 +256,12 @@ mod tests {
|
|||
let new_owned = borrowed.into_owned();
|
||||
assert!(matches!(new_owned, QuotaResourceName::Atom(Cow::Owned(_))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_quota_resource_limit_new() {
|
||||
let limit = QuotaResourceLimit::new("STORAGE", 1000);
|
||||
|
||||
assert_eq!(limit.name, QuotaResourceName::Storage);
|
||||
assert_eq!(limit.amount, 1000);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue