From 5273db3d5c21cd4ef331df57e09c58c93bcc3f46 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 11 Jan 2015 21:53:13 +0100 Subject: notmuch insert reply drafts --- Notmuch.hs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'Notmuch.hs') diff --git a/Notmuch.hs b/Notmuch.hs index 7851e17..8b45741 100644 --- a/Notmuch.hs +++ b/Notmuch.hs @@ -96,6 +96,44 @@ notmuch' args = do return (exitCode, out, err) +notmuchWithInput + :: [String] + -> LBS.ByteString + -> IO (ExitCode, LBS.ByteString, LBS.ByteString) +notmuchWithInput args input = do + (Just hin, Just hout, Just herr, ph) <- + createProcess (proc "notmuch" args) + { std_in = CreatePipe + , std_out = CreatePipe + , std_err = CreatePipe + } + LBS.hPut hin input + hClose hin + + out <- LBS.hGetContents hout + err <- LBS.hGetContents herr + + withForkWait (evaluate $ rnf out) $ \waitOut -> do + withForkWait (evaluate $ rnf err) $ \waitErr -> do + + ---- now write any input + --unless (null input) $ + -- ignoreSigPipe $ hPutStr inh input + -- hClose performs implicit hFlush, and thus may trigger a SIGPIPE + --ignoreSigPipe $ hClose inh + + -- wait on the output + waitOut + waitErr + hClose hout + hClose herr + + -- wait on the process + exitCode <- waitForProcess ph + + return (exitCode, out, err) + + search :: String -> IO (Either String [SearchResult]) search term = notmuch [ "search", "--format=json", "--format-version=2", term ] -- cgit v1.2.3