@@ -162,6 +162,53 @@ named!(flag_perm<&str>, alt!(
162
162
flag
163
163
) ) ;
164
164
165
+ named ! ( section_part<Vec <u32 >>, do_parse!(
166
+ part: number >>
167
+ rest: many0!( do_parse!(
168
+ tag_s!( "." ) >>
169
+ part: number >>
170
+ ( part)
171
+ ) ) >> ( {
172
+ let mut res = vec![ part] ;
173
+ res. extend( rest) ;
174
+ res
175
+ } )
176
+ ) ) ;
177
+
178
+ named ! ( section_msgtext<MessageSection >, map!(
179
+ alt!( tag_s!( "HEADER" ) | tag_s!( "TEXT" ) ) ,
180
+ |s| match s {
181
+ b"HEADER" => MessageSection :: Header ,
182
+ b"TEXT" => MessageSection :: Text ,
183
+ _ => panic!( "cannot happen" ) ,
184
+ }
185
+ ) ) ;
186
+
187
+ named ! ( section_text<MessageSection >, alt!(
188
+ section_msgtext |
189
+ do_parse!( tag_s!( "MIME" ) >> ( MessageSection :: Mime ) )
190
+ ) ) ;
191
+
192
+ named ! ( section_spec<SectionPath >, alt!(
193
+ map!( section_msgtext, |val| SectionPath :: Full ( val) ) |
194
+ do_parse!(
195
+ part: section_part >>
196
+ text: opt!( do_parse!(
197
+ tag_s!( "." ) >>
198
+ text: section_text >>
199
+ ( text)
200
+ ) ) >>
201
+ ( SectionPath :: Part ( part, text) )
202
+ )
203
+ ) ) ;
204
+
205
+ named ! ( section<Option <SectionPath >>, do_parse!(
206
+ tag_s!( "[" ) >>
207
+ spec: opt!( section_spec) >>
208
+ tag_s!( "]" ) >>
209
+ ( spec)
210
+ ) ) ;
211
+
165
212
named ! ( resp_text_code_permanent_flags<ResponseCode >, do_parse!(
166
213
tag_s!( "PERMANENTFLAGS (" ) >>
167
214
elements: opt!( do_parse!(
@@ -341,6 +388,20 @@ named!(opt_addresses<Option<Vec<Address>>>, alt!(
341
388
)
342
389
) ) ;
343
390
391
+ named ! ( msg_att_body_section<AttributeValue >, do_parse!(
392
+ tag_s!( "BODY" ) >>
393
+ section: section >>
394
+ index: opt!( do_parse!(
395
+ tag_s!( "<" ) >>
396
+ num: number >>
397
+ tag_s!( ">" ) >>
398
+ ( num)
399
+ ) ) >>
400
+ tag_s!( " " ) >>
401
+ data: nstring >>
402
+ ( AttributeValue :: BodySection { section, index, data } )
403
+ ) ) ;
404
+
344
405
named ! ( msg_att_envelope<AttributeValue >, do_parse!(
345
406
tag_s!( "ENVELOPE (" ) >>
346
407
date: nstring >>
@@ -416,6 +477,7 @@ named!(msg_att_uid<AttributeValue>, do_parse!(
416
477
) ) ;
417
478
418
479
named ! ( msg_att<AttributeValue >, alt!(
480
+ msg_att_body_section |
419
481
msg_att_envelope |
420
482
msg_att_internal_date |
421
483
msg_att_flags |
@@ -554,4 +616,19 @@ mod tests {
554
616
rsp @ _ => panic ! ( "unexpected response {:?}" , rsp) ,
555
617
}
556
618
}
619
+
620
+ #[ test]
621
+ fn test_body_text ( ) {
622
+ match parse_response ( b"* 2 FETCH (BODY[TEXT] {3}\r \n foo)\r \n " ) {
623
+ IResult :: Done ( _, Response :: Fetch ( _, attrs) ) => {
624
+ let body = & attrs[ 0 ] ;
625
+ assert_eq ! ( body, & AttributeValue :: BodySection {
626
+ section: Some ( SectionPath :: Full ( MessageSection :: Text ) ) ,
627
+ index: None ,
628
+ data: Some ( b"foo" ) ,
629
+ } , "body = {:?}" , body) ;
630
+ } ,
631
+ rsp @ _ => panic ! ( "unexpected response {:?}" , rsp) ,
632
+ }
633
+ }
557
634
}
0 commit comments