@@ -165,13 +165,44 @@ pub(crate) async fn parse_mailbox<T: Stream<Item = io::Result<ResponseData>> + U
165
165
) -> Result < Mailbox > {
166
166
let mut mailbox = Mailbox :: default ( ) ;
167
167
168
- while let Some ( resp) = stream
169
- . take_while ( |res| filter_sync ( res, & command_tag) )
170
- . next ( )
171
- . await
172
- {
168
+ while let Some ( resp) = stream. next ( ) . await {
173
169
let resp = resp?;
174
170
match resp. parsed ( ) {
171
+ Response :: Done {
172
+ tag,
173
+ status,
174
+ code,
175
+ information,
176
+ ..
177
+ } if tag == & command_tag => {
178
+ use imap_proto:: Status ;
179
+ match status {
180
+ Status :: Ok => {
181
+ break ;
182
+ }
183
+ Status :: Bad => {
184
+ return Err ( Error :: Bad ( format ! (
185
+ "code: {:?}, info: {:?}" ,
186
+ code, information
187
+ ) ) )
188
+ }
189
+ Status :: No => {
190
+ return Err ( Error :: No ( format ! (
191
+ "code: {:?}, info: {:?}" ,
192
+ code, information
193
+ ) ) )
194
+ }
195
+ _ => {
196
+ return Err ( Error :: Io ( io:: Error :: new (
197
+ io:: ErrorKind :: Other ,
198
+ format ! (
199
+ "status: {:?}, code: {:?}, information: {:?}" ,
200
+ status, code, information
201
+ ) ,
202
+ ) ) ) ;
203
+ }
204
+ }
205
+ }
175
206
Response :: Data {
176
207
status,
177
208
code,
@@ -618,4 +649,19 @@ mod tests {
618
649
let ids: HashSet < u32 > = ids. iter ( ) . cloned ( ) . collect ( ) ;
619
650
assert_eq ! ( ids, HashSet :: <u32 >:: new( ) ) ;
620
651
}
652
+
653
+ #[ async_std:: test]
654
+ async fn parse_mailbox_does_not_exist_error ( ) {
655
+ let ( send, recv) = channel:: bounded ( 10 ) ;
656
+ let responses = input_stream ( & [
657
+ "A0003 NO Mailbox doesn't exist: DeltaChat (0.001 + 0.140 + 0.139 secs).\r \n " ,
658
+ ] ) ;
659
+ let mut stream = async_std:: stream:: from_iter ( responses) ;
660
+
661
+ let id = RequestId ( "A0003" . into ( ) ) ;
662
+ let mailbox = parse_mailbox ( & mut stream, send, id) . await ;
663
+ assert ! ( recv. is_empty( ) ) ;
664
+
665
+ assert ! ( matches!( mailbox, Err ( Error :: No ( _) ) ) ) ;
666
+ }
621
667
}
0 commit comments