Make UID and UID validity 32bits to match the RFC

In the RFC it says they both add up to 64 bits. Previously they were
type aliases for usize,  which on 64 bit platforms will be 64 bits. As a
consequence, adding up these two data types would amount to 128 bits,
not 64 bits.
imap-connection-changes
Andrei Zisu 3 years ago committed by Manos Pitsidianakis
parent c7208a168c
commit 5dd3ead89b
No known key found for this signature in database
GPG Key ID: 7729C7707F7E09D0

@ -51,6 +51,7 @@ use futures::stream::Stream;
use std::collections::hash_map::DefaultHasher;
use std::collections::{BTreeSet, HashMap, HashSet};
use std::convert::TryFrom;
use std::convert::TryInto;
use std::hash::Hasher;
use std::pin::Pin;
use std::str::FromStr;
@ -58,8 +59,9 @@ use std::sync::{Arc, Mutex};
use std::time::{Duration, SystemTime};
pub type ImapNum = usize;
pub type UID = ImapNum;
pub type UIDVALIDITY = UID;
// Data type for UID and UIDVALIDITY defined in RFC 3501 2.3.1.1
pub type UID = u32;
pub type UIDVALIDITY = u32;
pub type MessageSequenceNumber = ImapNum;
pub static SUPPORTED_CAPABILITIES: &[&str] = &[
@ -1773,9 +1775,9 @@ async fn fetch_hlpr(state: &mut FetchState) -> Result<Vec<Envelope>> {
let mut conn = connection.lock().await;
let mut response = Vec::with_capacity(8 * 1024);
let max_uid_left = max_uid;
let chunk_size = 250;
let chunk_size: UID = 250;
let mut envelopes = Vec::with_capacity(chunk_size);
let mut envelopes = Vec::with_capacity(chunk_size.try_into().unwrap_or_default());
conn.examine_mailbox(mailbox_hash, &mut response, false)
.await?;
if max_uid_left > 0 {

@ -1008,20 +1008,20 @@ fn test_imap_fetch_response() {
);
}
pub fn search_results<'a>(input: &'a [u8]) -> IResult<&'a [u8], Vec<ImapNum>> {
pub fn search_results<'a>(input: &'a [u8]) -> IResult<&'a [u8], Vec<UID>> {
alt((
|input: &'a [u8]| -> IResult<&'a [u8], Vec<ImapNum>> {
|input: &'a [u8]| -> IResult<&'a [u8], Vec<UID>> {
let (input, _) = tag("* SEARCH ")(input)?;
let (input, list) = separated_list1(
tag(b" "),
map_res(is_not(" \r\n"), |s: &[u8]| {
ImapNum::from_str(unsafe { std::str::from_utf8_unchecked(s) })
UID::from_str(unsafe { std::str::from_utf8_unchecked(s) })
}),
)(input)?;
let (input, _) = tag("\r\n")(input)?;
Ok((input, list))
},
|input: &'a [u8]| -> IResult<&'a [u8], Vec<ImapNum>> {
|input: &'a [u8]| -> IResult<&'a [u8], Vec<UID>> {
let (input, _) = tag("* SEARCH\r\n")(input)?;
Ok((input, vec![]))
},
@ -1759,7 +1759,7 @@ fn ctl(input: &[u8]) -> IResult<&[u8], u8> {
pub fn generate_envelope_hash(mailbox_path: &str, uid: &UID) -> EnvelopeHash {
let mut h = DefaultHasher::new();
h.write_usize(*uid);
h.write_u32(*uid);
h.write(mailbox_path.as_bytes());
EnvelopeHash(h.finish())
}

Loading…
Cancel
Save