mirror of
https://github.com/stalwartlabs/mail-server.git
synced 2025-10-09 12:05:49 +08:00
Fix flag parsing (closes #1138)
This commit is contained in:
parent
cac9152d27
commit
1a10a4e911
2 changed files with 26 additions and 22 deletions
|
@ -152,34 +152,38 @@ impl Flag {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_datetime(value: &[u8]) -> Result<i64> {
|
pub fn parse_datetime(value: &[u8]) -> Result<i64> {
|
||||||
let datetime = std::str::from_utf8(value)
|
std::str::from_utf8(value)
|
||||||
.map_err(|_| Cow::from("Expected date/time, found an invalid UTF-8 string."))?
|
.map_err(|_| Cow::from("Expected date/time, found an invalid UTF-8 string."))
|
||||||
.trim();
|
.and_then(|datetime| {
|
||||||
DateTime::parse_from_str(datetime, "%d-%b-%Y %H:%M:%S %z")
|
DateTime::parse_from_str(datetime.trim(), "%d-%b-%Y %H:%M:%S %z")
|
||||||
.map_err(|_| Cow::from(format!("Failed to parse date/time '{}'.", datetime)))
|
.map_err(|_| Cow::from(format!("Failed to parse date/time '{}'.", datetime)))
|
||||||
.map(|dt| dt.timestamp())
|
.map(|dt| dt.timestamp())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_date(value: &[u8]) -> Result<i64> {
|
pub fn parse_date(value: &[u8]) -> Result<i64> {
|
||||||
let date = std::str::from_utf8(value)
|
std::str::from_utf8(value)
|
||||||
.map_err(|_| Cow::from("Expected date, found an invalid UTF-8 string."))?
|
.map_err(|_| Cow::from("Expected date, found an invalid UTF-8 string."))
|
||||||
.trim();
|
.and_then(|date| {
|
||||||
NaiveDate::parse_from_str(date, "%d-%b-%Y")
|
NaiveDate::parse_from_str(date.trim(), "%d-%b-%Y")
|
||||||
.map_err(|_| Cow::from(format!("Failed to parse date '{}'.", date)))
|
.map_err(|_| Cow::from(format!("Failed to parse date '{}'.", date)))
|
||||||
.map(|dt| {
|
.map(|dt| {
|
||||||
dt.and_hms_opt(0, 0, 0)
|
dt.and_hms_opt(0, 0, 0)
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.and_utc()
|
.and_utc()
|
||||||
.timestamp()
|
.timestamp()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_number<T: FromStr>(value: &[u8]) -> Result<T> {
|
pub fn parse_number<T: FromStr>(value: &[u8]) -> Result<T> {
|
||||||
let string = std::str::from_utf8(value)
|
std::str::from_utf8(value)
|
||||||
.map_err(|_| Cow::from("Expected a number, found an invalid UTF-8 string."))?;
|
.map_err(|_| Cow::from("Expected a number, found an invalid UTF-8 string."))
|
||||||
string
|
.and_then(|string| {
|
||||||
.parse::<T>()
|
string
|
||||||
.map_err(|_| Cow::from(format!("Expected a number, found {:?}.", string)))
|
.parse::<T>()
|
||||||
|
.map_err(|_| Cow::from(format!("Expected a number, found {:?}.", string)))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_sequence_set(value: &[u8]) -> Result<Sequence> {
|
pub fn parse_sequence_set(value: &[u8]) -> Result<Sequence> {
|
||||||
|
|
|
@ -64,7 +64,7 @@ impl Request<Command> {
|
||||||
.next()
|
.next()
|
||||||
.ok_or_else(|| bad(self.tag.to_string(), "Missing message data item name."))?
|
.ok_or_else(|| bad(self.tag.to_string(), "Missing message data item name."))?
|
||||||
.unwrap_bytes();
|
.unwrap_bytes();
|
||||||
let (is_silent, operation) = hashify::tiny_map!(operation.as_slice(),
|
let (is_silent, operation) = hashify::tiny_map_ignore_case!(operation.as_slice(),
|
||||||
"FLAGS" => (false, Operation::Set),
|
"FLAGS" => (false, Operation::Set),
|
||||||
"FLAGS.SILENT" => (true, Operation::Set),
|
"FLAGS.SILENT" => (true, Operation::Set),
|
||||||
"+FLAGS" => (false, Operation::Add),
|
"+FLAGS" => (false, Operation::Add),
|
||||||
|
|
Loading…
Add table
Reference in a new issue