Skip to content

Commit 492ee4a

Browse files
committed
apply link2xt suggestions
1 parent c6b5386 commit 492ee4a

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

src/client.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
use std::collections::HashSet;
12
use std::fmt;
23
use std::ops::{Deref, DerefMut};
34
use std::pin::Pin;
45
use std::str;
5-
use std::{borrow::Cow, collections::HashSet};
66

77
use async_native_tls::{TlsConnector, TlsStream};
88
use async_std::channel;
@@ -1247,7 +1247,7 @@ impl<T: Read + Write + Unpin + fmt::Debug + Send> Session<T> {
12471247
}
12481248

12491249
/// The [`GETQUOTA` command](https://tools.ietf.org/html/rfc2087#section-4.2)
1250-
pub async fn get_quota(&mut self, quota_root: Cow<'_, str>) -> Result<Quota<'_>> {
1250+
pub async fn get_quota(&mut self, quota_root: &str) -> Result<Quota<'_>> {
12511251
let id = self
12521252
.run_command(format!("GETQUOTA {}", quote!(quota_root)))
12531253
.await?;
@@ -1263,7 +1263,7 @@ impl<T: Read + Write + Unpin + fmt::Debug + Send> Session<T> {
12631263
/// The [`GETQUOTAROOT` command](https://tools.ietf.org/html/rfc2087#section-4.3)
12641264
pub async fn get_quota_root(
12651265
&mut self,
1266-
mailbox_name: Cow<'_, str>,
1266+
mailbox_name: &str,
12671267
) -> Result<(Vec<QuotaRoot<'_>>, Vec<Quota<'_>>)> {
12681268
let id = self
12691269
.run_command(format!("GETQUOTAROOT {}", quote!(mailbox_name)))

src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ pub enum ParseError {
5555
/// The client received data that was not UTF-8 encoded.
5656
#[error("unable to parse data ({0:?}) as UTF-8 text: {1:?}")]
5757
DataNotUtf8(Vec<u8>, #[source] Utf8Error),
58+
/// The expected response for X was not found
59+
#[error("expected response not found for: {0}")]
60+
ExpectedResponseNotFound(String),
5861
}
5962

6063
/// An [invalid character](https://tools.ietf.org/html/rfc3501#section-4.3) was found in an input

src/extensions/quota.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,42 @@ use async_std::prelude::*;
66
use async_std::stream::Stream;
77
use imap_proto::{self, Quota, QuotaRoot, RequestId, Response};
88

9-
use crate::types::ResponseData;
109
use crate::types::*;
1110
use crate::{
1211
error::Result,
1312
parse::{filter_sync, handle_unilateral},
1413
};
14+
use crate::{
15+
error::{Error, ParseError},
16+
types::ResponseData,
17+
};
1518

1619
pub(crate) async fn parse_get_quota<T: Stream<Item = io::Result<ResponseData>> + Unpin>(
1720
stream: &mut T,
1821
unsolicited: channel::Sender<UnsolicitedResponse>,
1922
command_tag: RequestId,
2023
) -> Result<Quota<'_>> {
24+
let mut quota = None;
2125
while let Some(resp) = stream
2226
.take_while(|res| filter_sync(res, &command_tag))
2327
.next()
2428
.await
2529
{
2630
let resp = resp?;
2731
match resp.parsed() {
28-
Response::Quota(q) => {
29-
return Ok(q.clone().into_owned());
30-
}
32+
Response::Quota(q) => quota = Some(q.clone().into_owned()),
3133
_ => {
3234
handle_unilateral(resp, unsolicited.clone()).await;
3335
}
3436
}
3537
}
3638

37-
unreachable!(); // TODO, make this better
39+
match quota {
40+
Some(q) => Ok(q),
41+
None => Err(Error::Parse(ParseError::ExpectedResponseNotFound(
42+
"Quota, no quota response found".to_string(),
43+
))),
44+
}
3845
}
3946

4047
pub(crate) async fn parse_get_quota_root<T: Stream<Item = io::Result<ResponseData>> + Unpin>(

0 commit comments

Comments
 (0)