Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,28 @@ mod tests {
assert_eq!(fetches[1].header(), None);
}

#[cfg_attr(feature = "runtime-tokio", tokio::test)]
#[cfg_attr(feature = "runtime-async-std", async_std::test)]
async fn parse_fetches_gmail_thread_id() {
let (send, recv) = bounded(10);
let responses = input_stream(&[
"* 24 FETCH (FLAGS (\\Seen) UID 4827943 X-GM-THRID 1278455344230334865)\r\n",
"* 25 FETCH (FLAGS (\\Seen))\r\n",
]);
let mut stream = async_std::stream::from_iter(responses);
let id = RequestId("a".into());

let fetches = parse_fetches(&mut stream, send, id)
.try_collect::<Vec<_>>()
.await
.unwrap();
assert!(recv.is_empty());

assert_eq!(fetches.len(), 2);
assert_eq!(fetches[0].gmail_thread_id(), Some(&1278455344230334865));
assert_eq!(fetches[1].gmail_thread_id(), None);
}

#[cfg_attr(feature = "runtime-tokio", tokio::test)]
#[cfg_attr(feature = "runtime-async-std", async_std::test)]
async fn parse_fetches_w_unilateral() {
Expand Down
16 changes: 16 additions & 0 deletions src/types/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,20 @@ impl Fetch {
unreachable!()
}
}

/// Get the Gmail thread id (X-GM-THRID). Only present if the server
/// returned it (Gmail's X-GM-EXT-1).
pub fn gmail_thread_id(&self) -> Option<&u64> {
if let Response::Fetch(_, attrs) = self.response.parsed() {
attrs
.iter()
.filter_map(|av| match av {
AttributeValue::GmailThrId(id) => Some(id),
_ => None,
})
.next()
} else {
unreachable!()
}
}
}