66use DirectoryTree \ImapEngine \Collections \ResponseCollection ;
77use DirectoryTree \ImapEngine \Connection \ConnectionInterface ;
88use DirectoryTree \ImapEngine \Connection \ImapQueryBuilder ;
9+ use DirectoryTree \ImapEngine \Connection \Responses \MessageResponseParser ;
910use DirectoryTree \ImapEngine \Connection \Responses \UntaggedResponse ;
1011use DirectoryTree \ImapEngine \Connection \Tokens \Atom ;
1112use DirectoryTree \ImapEngine \Enums \ImapFetchIdentifier ;
@@ -336,36 +337,15 @@ protected function fetch(Collection $messages): array
336337
337338 $ flags = $ this ->fetchFlags ? $ this ->connection ()
338339 ->flags ($ uids )
339- ->mapWithKeys (function (UntaggedResponse $ response ) {
340- $ data = $ response ->tokenAt (3 );
341-
342- $ uid = $ data ->lookup ('UID ' )->value ;
343- $ flags = $ data ->lookup ('FLAGS ' )->values ();
344-
345- return [$ uid => $ flags ];
346- }) : new Collection ;
340+ ->mapWithKeys (MessageResponseParser::getFlags (...))->all () : [];
347341
348342 $ headers = $ this ->fetchHeaders ? $ this ->connection ()
349343 ->bodyHeader ($ uids , $ this ->fetchAsUnread )
350- ->mapWithKeys (function (UntaggedResponse $ response ) {
351- $ data = $ response ->tokenAt (3 );
352-
353- $ uid = $ data ->lookup ('UID ' )->value ;
354- $ headers = $ data ->lookup ('[HEADER] ' )->value ;
355-
356- return [$ uid => $ headers ];
357- }) : new Collection ;
344+ ->mapWithKeys (MessageResponseParser::getBodyHeader (...))->all () : [];
358345
359346 $ contents = $ this ->fetchBody ? $ this ->connection ()
360347 ->bodyText ($ uids , $ this ->fetchAsUnread )
361- ->mapWithKeys (function (UntaggedResponse $ response ) {
362- $ data = $ response ->tokenAt (3 );
363-
364- $ uid = $ data ->lookup ('UID ' )->value ;
365- $ contents = $ data ->lookup ('[TEXT] ' )->value ;
366-
367- return [$ uid => $ contents ];
368- }) : new Collection ;
348+ ->mapWithKeys (MessageResponseParser::getBodyText (...)) : [];
369349
370350 return [
371351 'uids ' => $ uids ,
@@ -380,13 +360,7 @@ protected function fetch(Collection $messages): array
380360 */
381361 protected function newMessage (int $ uid , array $ flags , string $ headers , string $ contents ): Message
382362 {
383- return new Message (
384- $ this ->folder ,
385- $ uid ,
386- $ flags ,
387- $ headers ,
388- $ contents ,
389- );
363+ return new Message ($ this ->folder , $ uid , $ flags , $ headers , $ contents );
390364 }
391365
392366 /**
@@ -446,11 +420,11 @@ public function get(): MessageCollection
446420 */
447421 public function append (string $ message , mixed $ flags = null ): int
448422 {
449- $ result = $ this ->connection ()->append (
423+ $ response = $ this ->connection ()->append (
450424 $ this ->folder ->path (), $ message , Str::enums ($ flags ),
451425 );
452426
453- return $ result // TAG4 OK [APPENDUID <uidvalidity> <uid>] APPEND completed.
427+ return $ response // TAG4 OK [APPENDUID <uidvalidity> <uid>] APPEND completed.
454428 ->tokenAt (2 ) // [APPENDUID <uidvalidity> <uid>]
455429 ->tokenAt (2 ) // <uid>
456430 ->value ;
0 commit comments