diff --git a/src/types/fetch.rs b/src/types/fetch.rs index f5e8ad7..433002f 100644 --- a/src/types/fetch.rs +++ b/src/types/fetch.rs @@ -1,3 +1,5 @@ +use std::borrow::Cow; + use chrono::{DateTime, FixedOffset}; use imap_proto::types::{ AttributeValue, BodyStructure, Envelope, MessageSection, Response, SectionPath, @@ -228,4 +230,40 @@ impl Fetch { unreachable!() } } + + /// Extract the `X-GM-LABELS` of a `FETCH` response + /// + /// See [Access to Gmail labels: X-GM-LABELS](https://developers.google.com/gmail/imap/imap-extensions#access_to_labels_x-gm-labels) + /// for details. + pub fn gmail_labels(&self) -> Option<&Vec>> { + if let Response::Fetch(_, attrs) = self.response.parsed() { + attrs + .iter() + .filter_map(|av| match av { + AttributeValue::GmailLabels(gl) => Some(gl), + _ => None, + }) + .next() + } else { + unreachable!() + } + } + + /// Extract the `X-GM-MSGID` of a `FETCH` response + /// + /// See [Access to the Gmail unique message ID: X-GM-MSGID](https://developers.google.com/workspace/gmail/imap/imap-extensions#access_to_the_unique_message_id_x-gm-msgid) + /// for details. + pub fn gmail_msg_id(&self) -> Option<&u64> { + if let Response::Fetch(_, attrs) = self.response.parsed() { + attrs + .iter() + .filter_map(|av| match av { + AttributeValue::GmailMsgId(id) => Some(id), + _ => None, + }) + .next() + } else { + unreachable!() + } + } }