@ Override public Set < Flag > extract ( List < String > messages ) throws ExtractionException { boolean gotFetch = false ; Set < Flag > result = null ; // Find FETCH, throw error if none or more than one, or if we receive an error response. String fetchStr = null ; for ( int i = 0 , messagesSize = messages . size ( ) ; i < messagesSize ; i ++ ) { String message = messages . get ( i ) ; if ( null == message || message . isEmpty ( ) ) continue ; fetchStr = matchAndGetGroup1 ( FETCH_FLAG_PATT , message ) ; if ( fetchStr != null ) { if ( gotFetch ) { throw new ExtractionException ( "STORE_FLAGS RESPONSE: Got more than one FETCH response " + message ) ; } gotFetch = true ; result = Flag . parseFlagList ( Parsing . tokenize ( fetchStr ) ) ; } else { if ( matchAndGetGroup1 ( OK_PATT , message ) != null ) { if ( ! gotFetch ) { throw new ExtractionException ( "STORE_FLAGS RESPONSE: no FLAGS received." + message ) ; } // All Good. } else if ( matchAndGetGroup1 ( BAD_PATT , message ) != null || matchAndGetGroup1 ( NO_PATT , message ) != null ) { throw new ExtractionException ( "STORE_FLAGS RESPONSE: " + message ) ; } } } return result ; }
Parse the response which includes new flag settings and command status . We expect only one FETCH response as we only set flags on one msg .