Skip to content

Commit 54273ab

Browse files
avitexdjc
authored andcommitted
Make token matches case-insensitive
1 parent aa3bbe6 commit 54273ab

File tree

5 files changed

+63
-60
lines changed

5 files changed

+63
-60
lines changed

imap-proto/src/body.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,14 @@ named!(pub section_part<Vec<u32>>, do_parse!(
1414
})
1515
));
1616

17-
named!(pub section_msgtext<MessageSection>, map!(
18-
alt!(tag!("HEADER") | tag!("TEXT")),
19-
|s| match s {
20-
b"HEADER" => MessageSection::Header,
21-
b"TEXT" => MessageSection::Text,
22-
_ => panic!("cannot happen"),
23-
}
17+
named!(pub section_msgtext<MessageSection>, alt!(
18+
do_parse!(tag_no_case!("HEADER") >> (MessageSection::Header)) |
19+
do_parse!(tag_no_case!("TEXT") >> (MessageSection::Text))
2420
));
2521

2622
named!(pub section_text<MessageSection>, alt!(
2723
section_msgtext |
28-
do_parse!(tag!("MIME") >> (MessageSection::Mime))
24+
do_parse!(tag_no_case!("MIME") >> (MessageSection::Mime))
2925
));
3026

3127
named!(pub section_spec<SectionPath>, alt!(
@@ -49,7 +45,7 @@ named!(pub section<Option<SectionPath>>, do_parse!(
4945
));
5046

5147
named!(pub msg_att_body_section<AttributeValue>, do_parse!(
52-
tag!("BODY") >>
48+
tag_no_case!("BODY") >>
5349
section: section >>
5450
index: opt!(do_parse!(
5551
tag!("<") >>

imap-proto/src/body_structure.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ named!(pub(crate) body<BodyStructure>, paren_delimited!(
229229
));
230230

231231
named!(pub(crate) msg_att_body_structure<AttributeValue>, do_parse!(
232-
tag!("BODYSTRUCTURE ") >>
232+
tag_no_case!("BODYSTRUCTURE ") >>
233233
body: body >>
234234
(AttributeValue::BodyStructure(body))
235235
));

imap-proto/src/core.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn atom_char(c: u8) -> bool {
3535
}
3636

3737
// nil = "NIL"
38-
named!(pub nil, tag!("NIL"));
38+
named!(pub nil, tag_no_case!("NIL"));
3939

4040
// ASTRING-CHAR = ATOM-CHAR / resp-specials
4141
pub fn astring_char(c: u8) -> bool {

imap-proto/src/parser/rfc3501.rs

Lines changed: 53 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ named!(flag_perm<&str>, alt!(
7373
));
7474

7575
named!(resp_text_code_alert<ResponseCode>, do_parse!(
76-
tag!("ALERT") >>
76+
tag_no_case!("ALERT") >>
7777
(ResponseCode::Alert)
7878
));
7979

8080
named!(resp_text_code_badcharset<ResponseCode>, do_parse!(
81-
tag!("BADCHARSET") >>
81+
tag_no_case!("BADCHARSET") >>
8282
ch: opt!(do_parse!(
8383
tag!(" ") >>
8484
charsets: parenthesized_nonempty_list!(astring_utf8) >>
@@ -93,45 +93,45 @@ named!(resp_text_code_capability<ResponseCode>, map!(
9393
));
9494

9595
named!(resp_text_code_parse<ResponseCode>, do_parse!(
96-
tag!("PARSE") >>
96+
tag_no_case!("PARSE") >>
9797
(ResponseCode::Parse)
9898
));
9999

100100
named!(resp_text_code_permanent_flags<ResponseCode>, do_parse!(
101-
tag!("PERMANENTFLAGS ") >>
101+
tag_no_case!("PERMANENTFLAGS ") >>
102102
flags: parenthesized_list!(flag_perm) >>
103103
(ResponseCode::PermanentFlags(flags))
104104
));
105105

106106
named!(resp_text_code_read_only<ResponseCode>, do_parse!(
107-
tag!("READ-ONLY") >>
107+
tag_no_case!("READ-ONLY") >>
108108
(ResponseCode::ReadOnly)
109109
));
110110

111111
named!(resp_text_code_read_write<ResponseCode>, do_parse!(
112-
tag!("READ-WRITE") >>
112+
tag_no_case!("READ-WRITE") >>
113113
(ResponseCode::ReadWrite)
114114
));
115115

116116
named!(resp_text_code_try_create<ResponseCode>, do_parse!(
117-
tag!("TRYCREATE") >>
117+
tag_no_case!("TRYCREATE") >>
118118
(ResponseCode::TryCreate)
119119
));
120120

121121
named!(resp_text_code_uid_validity<ResponseCode>, do_parse!(
122-
tag!("UIDVALIDITY ") >>
122+
tag_no_case!("UIDVALIDITY ") >>
123123
num: number >>
124124
(ResponseCode::UidValidity(num))
125125
));
126126

127127
named!(resp_text_code_uid_next<ResponseCode>, do_parse!(
128-
tag!("UIDNEXT ") >>
128+
tag_no_case!("UIDNEXT ") >>
129129
num: number >>
130130
(ResponseCode::UidNext(num))
131131
));
132132

133133
named!(resp_text_code_unseen<ResponseCode>, do_parse!(
134-
tag!("UNSEEN ") >>
134+
tag_no_case!("UNSEEN ") >>
135135
num: number >>
136136
(ResponseCode::Unseen(num))
137137
));
@@ -159,8 +159,8 @@ named!(resp_text_code<ResponseCode>, do_parse!(
159159
));
160160

161161
named!(capability<Capability>, alt!(
162-
map!(tag!("IMAP4rev1"), |_| Capability::Imap4rev1) |
163-
map!(preceded!(tag!("AUTH="), atom), |a| Capability::Auth(a)) |
162+
map!(tag_no_case!("IMAP4rev1"), |_| Capability::Imap4rev1) |
163+
map!(preceded!(tag_no_case!("AUTH="), atom), |a| Capability::Auth(a)) |
164164
map!(atom, |a| Capability::Atom(a))
165165
));
166166

@@ -174,7 +174,7 @@ fn ensure_capabilities_contains_imap4rev<'a>(capabilities: Vec<Capability<'a>>)
174174

175175
named!(capability_data<Vec<Capability>>, map_res!(
176176
do_parse!(
177-
tag!("CAPABILITY") >>
177+
tag_no_case!("CAPABILITY") >>
178178
capabilities: many0!(preceded!(char!(' '), capability)) >>
179179
(capabilities)
180180
),
@@ -187,7 +187,7 @@ named!(resp_capability<Response>, map!(
187187
));
188188

189189
named!(mailbox_data_search<Response>, do_parse!(
190-
tag!("SEARCH") >>
190+
tag_no_case!("SEARCH") >>
191191
ids: many0!(do_parse!(
192192
tag!(" ") >>
193193
id: number >>
@@ -197,14 +197,14 @@ named!(mailbox_data_search<Response>, do_parse!(
197197
));
198198

199199
named!(mailbox_data_flags<Response>, do_parse!(
200-
tag!("FLAGS ") >>
200+
tag_no_case!("FLAGS ") >>
201201
flags: flag_list >>
202202
(Response::MailboxData(MailboxDatum::Flags(flags)))
203203
));
204204

205205
named!(mailbox_data_exists<Response>, do_parse!(
206206
num: number >>
207-
tag!(" EXISTS") >>
207+
tag_no_case!(" EXISTS") >>
208208
(Response::MailboxData(MailboxDatum::Exists(num)))
209209
));
210210

@@ -221,7 +221,7 @@ named!(mailbox_list<(Vec<&str>, Option<&str>, &str)>, do_parse!(
221221
));
222222

223223
named!(mailbox_data_list<Response>, do_parse!(
224-
tag!("LIST ") >>
224+
tag_no_case!("LIST ") >>
225225
data: mailbox_list >>
226226
(Response::MailboxData(MailboxDatum::List {
227227
flags: data.0,
@@ -231,7 +231,7 @@ named!(mailbox_data_list<Response>, do_parse!(
231231
));
232232

233233
named!(mailbox_data_lsub<Response>, do_parse!(
234-
tag!("LSUB ") >>
234+
tag_no_case!("LSUB ") >>
235235
data: mailbox_list >>
236236
(Response::MailboxData(MailboxDatum::List {
237237
flags: data.0,
@@ -245,29 +245,36 @@ named!(mailbox_data_lsub<Response>, do_parse!(
245245
named!(status_att<StatusAttribute>, alt!(
246246
rfc4551::status_att_val_highest_mod_seq |
247247
do_parse!(
248-
key: alt!(
249-
tag!("MESSAGES") |
250-
tag!("RECENT") |
251-
tag!("UIDNEXT") |
252-
tag!("UIDVALIDITY") |
253-
tag!("UNSEEN")
254-
) >>
255-
tag!(" ") >>
248+
tag_no_case!("MESSAGES ") >>
249+
val: number >>
250+
(StatusAttribute::Messages(val))
251+
) |
252+
do_parse!(
253+
tag_no_case!("RECENT ") >>
254+
val: number >>
255+
(StatusAttribute::Recent(val))
256+
) |
257+
do_parse!(
258+
tag_no_case!("UIDNEXT ") >>
256259
val: number >>
257-
(match key {
258-
b"MESSAGES" => StatusAttribute::Messages(val),
259-
b"RECENT" => StatusAttribute::Recent(val),
260-
b"UIDNEXT" => StatusAttribute::UidNext(val),
261-
b"UIDVALIDITY" => StatusAttribute::UidValidity(val),
262-
b"UNSEEN" => StatusAttribute::Unseen(val),
263-
_ => panic!("invalid status key {}", str::from_utf8(key).unwrap()),
264-
}))
260+
(StatusAttribute::UidNext(val))
261+
) |
262+
do_parse!(
263+
tag_no_case!("UIDVALIDITY ") >>
264+
val: number >>
265+
(StatusAttribute::UidValidity(val))
266+
) |
267+
do_parse!(
268+
tag_no_case!("UNSEEN ") >>
269+
val: number >>
270+
(StatusAttribute::Unseen(val))
271+
)
265272
));
266273

267274
named!(status_att_list<Vec<StatusAttribute>>, parenthesized_nonempty_list!(status_att));
268275

269276
named!(mailbox_data_status<Response>, do_parse!(
270-
tag!("STATUS ") >>
277+
tag_no_case!("STATUS ") >>
271278
mailbox: mailbox >>
272279
tag!(" ") >>
273280
status: status_att_list >>
@@ -279,7 +286,7 @@ named!(mailbox_data_status<Response>, do_parse!(
279286

280287
named!(mailbox_data_recent<Response>, do_parse!(
281288
num: number >>
282-
tag!(" RECENT") >>
289+
tag_no_case!(" RECENT") >>
283290
(Response::MailboxData(MailboxDatum::Recent(num)))
284291
));
285292

@@ -361,50 +368,50 @@ named!(pub(crate) envelope<Envelope>, paren_delimited!(
361368
));
362369

363370
named!(msg_att_envelope<AttributeValue>, do_parse!(
364-
tag!("ENVELOPE ") >>
371+
tag_no_case!("ENVELOPE ") >>
365372
envelope: envelope >>
366373
(AttributeValue::Envelope(Box::new(envelope)))
367374
));
368375

369376
named!(msg_att_internal_date<AttributeValue>, do_parse!(
370-
tag!("INTERNALDATE ") >>
377+
tag_no_case!("INTERNALDATE ") >>
371378
date: nstring_utf8 >>
372379
(AttributeValue::InternalDate(date.unwrap()))
373380
));
374381

375382
named!(msg_att_flags<AttributeValue>, do_parse!(
376-
tag!("FLAGS ") >>
383+
tag_no_case!("FLAGS ") >>
377384
flags: flag_list >>
378385
(AttributeValue::Flags(flags))
379386
));
380387

381388
named!(msg_att_rfc822<AttributeValue>, do_parse!(
382-
tag!("RFC822 ") >>
389+
tag_no_case!("RFC822 ") >>
383390
raw: nstring >>
384391
(AttributeValue::Rfc822(raw))
385392
));
386393

387394
named!(msg_att_rfc822_header<AttributeValue>, do_parse!(
388-
tag!("RFC822.HEADER ") >>
395+
tag_no_case!("RFC822.HEADER ") >>
389396
opt!(tag!(" ")) >> // extra space workaround for DavMail
390397
raw: nstring >>
391398
(AttributeValue::Rfc822Header(raw))
392399
));
393400

394401
named!(msg_att_rfc822_size<AttributeValue>, do_parse!(
395-
tag!("RFC822.SIZE ") >>
402+
tag_no_case!("RFC822.SIZE ") >>
396403
num: number >>
397404
(AttributeValue::Rfc822Size(num))
398405
));
399406

400407
named!(msg_att_rfc822_text<AttributeValue>, do_parse!(
401-
tag!("RFC822.TEXT ") >>
408+
tag_no_case!("RFC822.TEXT ") >>
402409
raw: nstring >>
403410
(AttributeValue::Rfc822Text(raw))
404411
));
405412

406413
named!(msg_att_uid<AttributeValue>, do_parse!(
407-
tag!("UID ") >>
414+
tag_no_case!("UID ") >>
408415
num: number >>
409416
(AttributeValue::Uid(num))
410417
));
@@ -427,14 +434,14 @@ named!(msg_att_list<Vec<AttributeValue>>, parenthesized_nonempty_list!(msg_att))
427434

428435
named!(message_data_fetch<Response>, do_parse!(
429436
num: number >>
430-
tag!(" FETCH ") >>
437+
tag_no_case!(" FETCH ") >>
431438
attrs: msg_att_list >>
432439
(Response::Fetch(num, attrs))
433440
));
434441

435442
named!(message_data_expunge<Response>, do_parse!(
436443
num: number >>
437-
tag!(" EXPUNGE") >>
444+
tag_no_case!(" EXPUNGE") >>
438445
(Response::Expunge(num))
439446
));
440447

imap-proto/src/parser/rfc4551.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use types::*;
1717
// [RFC4551 - 3.6 HIGHESTMODSEQ Status Data Items](https://tools.ietf.org/html/rfc4551#section-3.6)
1818
// [RFC4551 - 4. Formal Syntax - resp-text-code](https://tools.ietf.org/html/rfc4551#section-4)
1919
named!(pub (crate) resp_text_code_highest_mod_seq<ResponseCode>, do_parse!(
20-
tag!("HIGHESTMODSEQ ") >>
20+
tag_no_case!("HIGHESTMODSEQ ") >>
2121
num: number_64 >>
2222
(ResponseCode::HighestModSeq(num))
2323
));
@@ -26,14 +26,14 @@ named!(pub (crate) resp_text_code_highest_mod_seq<ResponseCode>, do_parse!(
2626
// [RFC4551 - 3.6 - HIGHESTMODSEQ Status Data Items](https://tools.ietf.org/html/rfc4551#section-3.6)
2727
// [RFC4551 - 4. Formal Syntax - status-att-val](https://tools.ietf.org/html/rfc4551#section-4)
2828
named!(pub (crate) status_att_val_highest_mod_seq<StatusAttribute>, do_parse!(
29-
tag!("HIGHESTMODSEQ ") >>
29+
tag_no_case!("HIGHESTMODSEQ ") >>
3030
mod_sequence_valzer: number_64 >>
3131
(StatusAttribute::HighestModSeq(mod_sequence_valzer))
3232
));
3333

3434
// [RFC4551 - 4. Formal Syntax - fetch-mod-resp](https://tools.ietf.org/html/rfc4551#section-4)
3535
named!(pub (crate) msg_att_mod_seq<AttributeValue>, do_parse!(
36-
tag!("MODSEQ ") >>
36+
tag_no_case!("MODSEQ ") >>
3737
num: paren_delimited!(number_64) >>
3838
(AttributeValue::ModSeq(num))
3939
));

0 commit comments

Comments
 (0)