Add helper function to transform a vec of flag strings into a vec of Flags.
Also use it where we were previously iterating manually.
This commit is contained in:
parent
b8bd1e4cc7
commit
e1db863691
3 changed files with 12 additions and 17 deletions
12
src/parse.rs
12
src/parse.rs
|
|
@ -109,9 +109,7 @@ pub fn parse_fetches(
|
|||
use imap_proto::AttributeValue;
|
||||
match attr {
|
||||
AttributeValue::Flags(flags) => {
|
||||
fetch
|
||||
.flags
|
||||
.extend(flags.iter().map(|f| Flag::from(f.to_string())));
|
||||
fetch.flags.extend(Flag::from_vec(flags));
|
||||
}
|
||||
AttributeValue::Uid(uid) => fetch.uid = Some(*uid),
|
||||
AttributeValue::Rfc822Size(sz) => fetch.size = Some(*sz),
|
||||
|
|
@ -271,9 +269,7 @@ pub fn parse_mailbox(
|
|||
mailbox.unseen = Some(n);
|
||||
}
|
||||
Some(ResponseCode::PermanentFlags(flags)) => {
|
||||
mailbox
|
||||
.permanent_flags
|
||||
.extend(flags.into_iter().map(String::from).map(Flag::from));
|
||||
mailbox.permanent_flags.extend(Flag::from_vec(&flags));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
|
@ -297,9 +293,7 @@ pub fn parse_mailbox(
|
|||
mailbox.recent = r;
|
||||
}
|
||||
MailboxDatum::Flags(flags) => {
|
||||
mailbox
|
||||
.flags
|
||||
.extend(flags.into_iter().map(String::from).map(Flag::from));
|
||||
mailbox.flags.extend(Flag::from_vec(&flags));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -168,6 +168,11 @@ impl Flag<'static> {
|
|||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Helper function to transform a [`Vec`] of flag strings into a [`Vec`] of [`Flag`].
|
||||
pub fn from_vec<S: ToString>(v: &[S]) -> Vec<Self> {
|
||||
v.iter().map(|s| Self::from(s.to_string())).collect()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::Display for Flag<'a> {
|
||||
|
|
|
|||
|
|
@ -167,12 +167,9 @@ impl<'a> TryFrom<Response<'a>> for UnsolicitedResponse {
|
|||
})
|
||||
}
|
||||
Response::MailboxData(MailboxDatum::Recent(n)) => Ok(UnsolicitedResponse::Recent(n)),
|
||||
Response::MailboxData(MailboxDatum::Flags(flags)) => Ok(UnsolicitedResponse::Flags(
|
||||
flags
|
||||
.into_iter()
|
||||
.map(|s| Flag::from(s.to_string()))
|
||||
.collect(),
|
||||
)),
|
||||
Response::MailboxData(MailboxDatum::Flags(flags)) => {
|
||||
Ok(UnsolicitedResponse::Flags(Flag::from_vec(&flags)))
|
||||
}
|
||||
Response::MailboxData(MailboxDatum::Exists(n)) => Ok(UnsolicitedResponse::Exists(n)),
|
||||
Response::MailboxData(MailboxDatum::MetadataUnsolicited { mailbox, values }) => {
|
||||
Ok(UnsolicitedResponse::Metadata {
|
||||
|
|
@ -286,8 +283,7 @@ impl<'a> TryFrom<&ImapProtoAttributeValue<'a>> for AttributeValue {
|
|||
fn try_from(val: &ImapProtoAttributeValue<'a>) -> Result<Self, Self::Error> {
|
||||
match val {
|
||||
ImapProtoAttributeValue::Flags(flags) => {
|
||||
let v = flags.iter().map(|v| Flag::from(v.to_string())).collect();
|
||||
Ok(AttributeValue::Flags(v))
|
||||
Ok(AttributeValue::Flags(Flag::from_vec(&flags)))
|
||||
}
|
||||
ImapProtoAttributeValue::ModSeq(seq) => Ok(AttributeValue::ModSeq(*seq)),
|
||||
ImapProtoAttributeValue::Uid(uid) => Ok(AttributeValue::Uid(*uid)),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue