-- | Use 'IN.addWatch' to watch for 'IN.Create', 'IN.MoveIn', 'IN.Delete' and
-- 'IN.MoveOut' events in all @new\/@ subfolders of 'mailFolder'. Updates the
-- returned 'Conc.MVar' on each callback
watchEmailFolder :: Conc.MVar Int -> IO ()
watchEmailFolder mvar =
    bracketOnError IN.initINotify IN.killINotify $ \notify -> do
        folders <- allNewFolders
        forM_ folders $ \folder -> do
            files <- getTotalFiles folder
            when (files > 0) $ Conc.modifyMVar_ mvar $ \x -> return (x + files)
            IN.addWatch
                notify
                [IN.Create, IN.MoveIn, IN.Delete, IN.MoveOut]
                (toPreludeFp folder)
                (eventLength mvar)

-- | Turtle gives back 'FS.FilePath' but 'System.INotify' uses 'Prelude.FilePath'
-- so we have to convert between the two.
watchEmailFolder :: Conc.MVar Int -> IO ()
watchEmailFolder mvar =
    bracketOnError IN.initINotify IN.killINotify $ \notify -> do
        folders <- allNewFolders
        forM_ folders $ \folder -> do
            files <- getTotalFiles folder
            when (files > 0) $ Conc.modifyMVar_ mvar $ \x -> return (x + files)
            IN.addWatch
                notify
                [IN.Create, IN.MoveIn, IN.Delete, IN.MoveOut]
                (toPreludeFp folder)
                (eventLength mvar)

-- | Turtle gives back 'FS.FilePath' but 'System.INotify' uses 'Prelude.FilePath'
-- so we have to convert between the two.
watchEmailFolder mvar =
    bracketOnError IN.initINotify IN.killINotify $ \notify -> do
        folders <- allNewFolders
        forM_ folders $ \folder -> do
            files <- getTotalFiles folder
            when (files > 0) $ Conc.modifyMVar_ mvar $ \x -> return (x + files)
            IN.addWatch
                notify
                [IN.Create, IN.MoveIn, IN.Delete, IN.MoveOut]
                (toPreludeFp folder)
                (eventLength mvar)

-- | Turtle gives back 'FS.FilePath' but 'System.INotify' uses 'Prelude.FilePath'
-- so we have to convert between the two.