Skip to content

Commit 238cb95

Browse files
kiawindjc
authored andcommitted
Add support for x-gm-thrid
1 parent 4102cd6 commit 238cb95

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

imap-proto/src/builders/command.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ fn push_attr(cmd: &mut Vec<u8>, attr: Attribute) {
255255
Attribute::Uid => "UID",
256256
Attribute::GmailLabels => "X-GM-LABELS",
257257
Attribute::GmailMsgId => "X-GM-MSGID",
258+
Attribute::GmailThrId => "X-GM-THRID",
258259
}
259260
.as_bytes(),
260261
);

imap-proto/src/parser/gmail.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ pub(crate) fn mailbox_data_gmail_msgid(i: &[u8]) -> IResult<&[u8], MailboxDatum>
3838
map(gmail_msgid, MailboxDatum::GmailMsgId)(i)
3939
}
4040

41+
pub(crate) fn gmail_thrid(i: &[u8]) -> IResult<&[u8], u64> {
42+
preceded(tag_no_case("X-GM-THRID "), number_64)(i)
43+
}
44+
45+
pub(crate) fn msg_att_gmail_thrid(i: &[u8]) -> IResult<&[u8], AttributeValue> {
46+
map(gmail_thrid, AttributeValue::GmailThrId)(i)
47+
}
48+
49+
pub(crate) fn mailbox_data_gmail_thrid(i: &[u8]) -> IResult<&[u8], MailboxDatum> {
50+
map(gmail_thrid, MailboxDatum::GmailThrId)(i)
51+
}
52+
4153
#[cfg(test)]
4254
mod tests {
4355
use crate::types::*;
@@ -79,4 +91,22 @@ mod tests {
7991
}
8092
}
8193
}
94+
95+
#[test]
96+
fn test_gmail_thrid() {
97+
let env = br#"X-GM-THRID 1278455344230334865 "#;
98+
match super::msg_att_gmail_thrid(env) {
99+
Ok((_, AttributeValue::GmailThrId(thrid))) => {
100+
println!("{thrid:?}");
101+
assert_eq!(1278455344230334865, thrid);
102+
}
103+
rsp => {
104+
let e = rsp.unwrap_err();
105+
if let nom::Err::Error(i) = &e {
106+
println!("{:?}", std::str::from_utf8(i.input));
107+
}
108+
panic!("unexpected response {e:?}");
109+
}
110+
}
111+
}
82112
}

imap-proto/src/parser/rfc3501/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ fn mailbox_data(i: &[u8]) -> IResult<&[u8], MailboxDatum> {
383383
mailbox_data_search,
384384
gmail::mailbox_data_gmail_labels,
385385
gmail::mailbox_data_gmail_msgid,
386+
gmail::mailbox_data_gmail_thrid,
386387
rfc5256::mailbox_data_sort,
387388
))(i)
388389
}
@@ -579,6 +580,7 @@ fn msg_att(i: &[u8]) -> IResult<&[u8], AttributeValue> {
579580
msg_att_uid,
580581
gmail::msg_att_gmail_labels,
581582
gmail::msg_att_gmail_msgid,
583+
gmail::msg_att_gmail_thrid,
582584
))(i)
583585
}
584586

imap-proto/src/types.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ pub enum MailboxDatum<'a> {
238238
},
239239
GmailLabels(Vec<Cow<'a, str>>),
240240
GmailMsgId(u64),
241+
GmailThrId(u64),
241242
}
242243

243244
impl<'a> MailboxDatum<'a> {
@@ -282,6 +283,7 @@ impl<'a> MailboxDatum<'a> {
282283
MailboxDatum::GmailLabels(labels.into_iter().map(to_owned_cow).collect())
283284
}
284285
MailboxDatum::GmailMsgId(msgid) => MailboxDatum::GmailMsgId(msgid),
286+
MailboxDatum::GmailThrId(thrid) => MailboxDatum::GmailThrId(thrid),
285287
}
286288
}
287289
}
@@ -318,6 +320,7 @@ pub enum Attribute {
318320
/// https://developers.google.com/gmail/imap/imap-extensions#access_to_gmail_labels_x-gm-labels
319321
GmailLabels,
320322
GmailMsgId,
323+
GmailThrId,
321324
}
322325

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

360364
impl<'a> AttributeValue<'a> {
@@ -385,6 +389,7 @@ impl<'a> AttributeValue<'a> {
385389
AttributeValue::GmailLabels(v.into_iter().map(to_owned_cow).collect())
386390
}
387391
AttributeValue::GmailMsgId(v) => AttributeValue::GmailMsgId(v),
392+
AttributeValue::GmailThrId(v) => AttributeValue::GmailThrId(v),
388393
}
389394
}
390395
}

0 commit comments

Comments
 (0)