Browse Source

melib/imap: check if FETCH reply was intended for us

After sending a FETCH, the command results might be mixed with
unsolicited FETCH replies. Check if that happens.
tags/alpha-0.6.2
Manos Pitsidianakis 1 month ago
parent
commit
28deba708c
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS. GPG Key ID: 73627C2F690DF710
4 changed files with 19 additions and 2 deletions
  1. +10
    -0
      melib/src/backends/imap.rs
  2. +1
    -0
      melib/src/backends/imap/cache.rs
  3. +7
    -2
      melib/src/backends/imap/protocol_parser.rs
  4. +1
    -0
      melib/src/backends/imap/untagged.rs

+ 10
- 0
melib/src/backends/imap.rs View File

@ -1695,9 +1695,19 @@ async fn fetch_hlpr(state: &mut FetchState) -> Result> {
ref uid,
ref mut envelope,
ref mut flags,
ref raw_fetch_value,
..
} in v.iter_mut()
{
if uid.is_none() || envelope.is_none() || flags.is_none() {
debug!("in fetch is none");
debug!(uid);
debug!(envelope);
debug!(flags);
debug!("response was: {}", String::from_utf8_lossy(&response));
debug!(conn.process_untagged(raw_fetch_value).await)?;
continue;
}
let uid = uid.unwrap();
let env = envelope.as_mut().unwrap();
env.set_hash(generate_envelope_hash(&mailbox_path, &uid));

+ 1
- 0
melib/src/backends/imap/cache.rs View File

@ -446,6 +446,7 @@ mod sqlite3_m {
flags: _,
body: _,
envelope: Some(envelope),
raw_fetch_value: _,
} = item
{
max_uid = std::cmp::max(max_uid, *uid);

+ 7
- 2
melib/src/backends/imap/protocol_parser.rs View File

@ -465,6 +465,7 @@ pub struct FetchResponse<'a> {
pub flags: Option<(Flag, Vec<String>)>,
pub body: Option<&'a [u8]>,
pub envelope: Option<Envelope>,
pub raw_fetch_value: &'a [u8],
}
pub fn fetch_response(input: &[u8]) -> ImapParseResult<FetchResponse<'_>> {
@ -520,6 +521,7 @@ pub fn fetch_response(input: &[u8]) -> ImapParseResult> {
flags: None,
body: None,
envelope: None,
raw_fetch_value: &[],
};
while input[i].is_ascii_digit() {
@ -629,6 +631,7 @@ pub fn fetch_response(input: &[u8]) -> ImapParseResult> {
))));
}
}
ret.raw_fetch_value = &input[..i];
if let Some(env) = ret.envelope.as_mut() {
env.set_has_attachments(has_attachments);
@ -877,7 +880,8 @@ fn test_untagged_responses() {
modseq: Some(ModSequence(std::num::NonZeroU64::new(1365_u64).unwrap())),
flags: Some((Flag::SEEN, vec![])),
body: None,
envelope: None
envelope: None,
raw_fetch_value: &b"* 1079 FETCH (UID 1103 MODSEQ (1365) FLAGS (\\Seen))\r\n"[..],
})
);
assert_eq!(
@ -891,7 +895,8 @@ fn test_untagged_responses() {
modseq: None,
flags: Some((Flag::SEEN, vec![])),
body: None,
envelope: None
envelope: None,
raw_fetch_value: &b"* 1 FETCH (FLAGS (\\Seen))\r\n"[..],
})
);
}

+ 1
- 0
melib/src/backends/imap/untagged.rs View File

@ -357,6 +357,7 @@ impl ImapConnection {
flags,
body: _,
envelope: _,
raw_fetch_value: _,
}) => {
if let Some(flags) = flags {
let uid = if let Some(uid) = uid {

Loading…
Cancel
Save