Skip to content

Commit 8b28ada

Browse files
authored
feat: expose gmail labels and msg id (#124)
1 parent c5eeb0b commit 8b28ada

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/types/fetch.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::borrow::Cow;
2+
13
use chrono::{DateTime, FixedOffset};
24
use imap_proto::types::{
35
AttributeValue, BodyStructure, Envelope, MessageSection, Response, SectionPath,
@@ -228,4 +230,40 @@ impl Fetch {
228230
unreachable!()
229231
}
230232
}
233+
234+
/// Extract the `X-GM-LABELS` of a `FETCH` response
235+
///
236+
/// See [Access to Gmail labels: X-GM-LABELS](https://developers.google.com/gmail/imap/imap-extensions#access_to_labels_x-gm-labels)
237+
/// for details.
238+
pub fn gmail_labels(&self) -> Option<&Vec<Cow<'_, str>>> {
239+
if let Response::Fetch(_, attrs) = self.response.parsed() {
240+
attrs
241+
.iter()
242+
.filter_map(|av| match av {
243+
AttributeValue::GmailLabels(gl) => Some(gl),
244+
_ => None,
245+
})
246+
.next()
247+
} else {
248+
unreachable!()
249+
}
250+
}
251+
252+
/// Extract the `X-GM-MSGID` of a `FETCH` response
253+
///
254+
/// 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)
255+
/// for details.
256+
pub fn gmail_msg_id(&self) -> Option<&u64> {
257+
if let Response::Fetch(_, attrs) = self.response.parsed() {
258+
attrs
259+
.iter()
260+
.filter_map(|av| match av {
261+
AttributeValue::GmailMsgId(id) => Some(id),
262+
_ => None,
263+
})
264+
.next()
265+
} else {
266+
unreachable!()
267+
}
268+
}
231269
}

0 commit comments

Comments
 (0)