filterMode keys = do
    let query = unions $ rights $ map parseQuery keys
    hPutStrLn stderr $ show query
    headerString <- hGetLine stdin
    let parsedHeader = runParser parseHeader () "" headerString
    either wrongHeader (filterBody headerString query) parsedHeader
    where  wrongHeader _ = hPutStrLn stderr "wrong Header"
           filterBody headerString query header = do
                C.putStrLn headerString
                body <- hGetContents stdin
                let matcher = match header query
                forM_ (filter matcher (C.split '\n' body)) $ C.putStrLn
filterMode keys = do
    let query = unions $ rights $ map parseQuery keys
    hPutStrLn stderr $ show query
    headerString <- hGetLine stdin
    let parsedHeader = runParser parseHeader () "" headerString
    either wrongHeader (filterBody headerString query) parsedHeader
    where  wrongHeader _ = hPutStrLn stderr "wrong Header"
           filterBody headerString query header = do
                C.putStrLn headerString
                body <- hGetContents stdin
                let matcher = match header query
                forM_ (filter matcher (C.split '\n' body)) $ C.putStrLn
filterMode keys = do
    let query = unions $ rights $ map parseQuery keys
    hPutStrLn stderr $ show query
    headerString <- hGetLine stdin
    let parsedHeader = runParser parseHeader () "" headerString
    either wrongHeader (filterBody headerString query) parsedHeader
    where  wrongHeader _ = hPutStrLn stderr "wrong Header"
           filterBody headerString query header = do
                C.putStrLn headerString
                body <- hGetContents stdin
                let matcher = match header query
                forM_ (filter matcher (C.split '\n' body)) $ C.putStrLn