Skip to content
Merged
Changes from 1 commit
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
38 changes: 38 additions & 0 deletions src/types/fetch.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::borrow::Cow;

use chrono::{DateTime, FixedOffset};
use imap_proto::types::{
AttributeValue, BodyStructure, Envelope, MessageSection, Response, SectionPath,
Expand Down Expand Up @@ -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<Cow<'_, str>>> {
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_labels_x-gm-labels)
/// for details.
pub fn gmail_msg_id(&self) -> Option<&u64> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could return just Option<u64>, but this is minor

if let Response::Fetch(_, attrs) = self.response.parsed() {
attrs
.iter()
.filter_map(|av| match av {
AttributeValue::GmailMsgId(id) => Some(id),
_ => None,
})
.next()
} else {
unreachable!()
}
}
}
Loading