Skip to content
Merged
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
1 change: 1 addition & 0 deletions imap-proto/src/builders/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ fn push_attr(cmd: &mut Vec<u8>, attr: Attribute) {
Attribute::Uid => "UID",
Attribute::GmailLabels => "X-GM-LABELS",
Attribute::GmailMsgId => "X-GM-MSGID",
Attribute::GmailThrId => "X-GM-THRID",
}
.as_bytes(),
);
Expand Down
30 changes: 30 additions & 0 deletions imap-proto/src/parser/gmail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ pub(crate) fn mailbox_data_gmail_msgid(i: &[u8]) -> IResult<&[u8], MailboxDatum>
map(gmail_msgid, MailboxDatum::GmailMsgId)(i)
}

pub(crate) fn gmail_thrid(i: &[u8]) -> IResult<&[u8], u64> {
preceded(tag_no_case("X-GM-THRID "), number_64)(i)
}

pub(crate) fn msg_att_gmail_thrid(i: &[u8]) -> IResult<&[u8], AttributeValue> {
map(gmail_thrid, AttributeValue::GmailThrId)(i)
}

pub(crate) fn mailbox_data_gmail_thrid(i: &[u8]) -> IResult<&[u8], MailboxDatum> {
map(gmail_thrid, MailboxDatum::GmailThrId)(i)
}

#[cfg(test)]
mod tests {
use crate::types::*;
Expand Down Expand Up @@ -79,4 +91,22 @@ mod tests {
}
}
}

#[test]
fn test_gmail_thrid() {
let env = br#"X-GM-THRID 1278455344230334865 "#;
match super::msg_att_gmail_thrid(env) {
Ok((_, AttributeValue::GmailThrId(thrid))) => {
println!("{thrid:?}");
assert_eq!(1278455344230334865, thrid);
}
rsp => {
let e = rsp.unwrap_err();
if let nom::Err::Error(i) = &e {
println!("{:?}", std::str::from_utf8(i.input));
}
panic!("unexpected response {e:?}");
}
}
}
}
2 changes: 2 additions & 0 deletions imap-proto/src/parser/rfc3501/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ fn mailbox_data(i: &[u8]) -> IResult<&[u8], MailboxDatum> {
mailbox_data_search,
gmail::mailbox_data_gmail_labels,
gmail::mailbox_data_gmail_msgid,
gmail::mailbox_data_gmail_thrid,
rfc5256::mailbox_data_sort,
))(i)
}
Expand Down Expand Up @@ -574,6 +575,7 @@ fn msg_att(i: &[u8]) -> IResult<&[u8], AttributeValue> {
msg_att_uid,
gmail::msg_att_gmail_labels,
gmail::msg_att_gmail_msgid,
gmail::msg_att_gmail_thrid,
))(i)
}

Expand Down
5 changes: 5 additions & 0 deletions imap-proto/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ pub enum MailboxDatum<'a> {
},
GmailLabels(Vec<Cow<'a, str>>),
GmailMsgId(u64),
GmailThrId(u64),
}

impl<'a> MailboxDatum<'a> {
Expand Down Expand Up @@ -282,6 +283,7 @@ impl<'a> MailboxDatum<'a> {
MailboxDatum::GmailLabels(labels.into_iter().map(to_owned_cow).collect())
}
MailboxDatum::GmailMsgId(msgid) => MailboxDatum::GmailMsgId(msgid),
MailboxDatum::GmailThrId(thrid) => MailboxDatum::GmailThrId(thrid),
}
}
}
Expand Down Expand Up @@ -318,6 +320,7 @@ pub enum Attribute {
/// https://developers.google.com/gmail/imap/imap-extensions#access_to_gmail_labels_x-gm-labels
GmailLabels,
GmailMsgId,
GmailThrId,
}

#[derive(Debug, Eq, PartialEq)]
Expand Down Expand Up @@ -355,6 +358,7 @@ pub enum AttributeValue<'a> {
/// https://developers.google.com/gmail/imap/imap-extensions#access_to_gmail_labels_x-gm-labels
GmailLabels(Vec<Cow<'a, str>>),
GmailMsgId(u64),
GmailThrId(u64),
}

impl<'a> AttributeValue<'a> {
Expand Down Expand Up @@ -385,6 +389,7 @@ impl<'a> AttributeValue<'a> {
AttributeValue::GmailLabels(v.into_iter().map(to_owned_cow).collect())
}
AttributeValue::GmailMsgId(v) => AttributeValue::GmailMsgId(v),
AttributeValue::GmailThrId(v) => AttributeValue::GmailThrId(v),
}
}
}
Expand Down