diff options
author | Raúl Benencia <rul@kalgan.cc> | 2013-09-03 20:24:51 -0300 |
---|---|---|
committer | Raúl Benencia <rul@kalgan.cc> | 2013-09-03 20:24:51 -0300 |
commit | 84fa12fef1736d04ee79e40cebaadadda262f063 (patch) | |
tree | 4842389a50b1c0f76b3d9a27ef3f562adac87b57 /Maildir.hs | |
parent | c91af8d1f85f876eb7119ce8406385cf570d3886 (diff) |
Mark as read functionality
Diffstat (limited to 'Maildir.hs')
-rw-r--r-- | Maildir.hs | 31 |
1 files changed, 25 insertions, 6 deletions
@@ -11,8 +11,8 @@ module Maildir where import Control.Monad.Loops(allM) import Control.Monad (forM, filterM) import Data.List(isPrefixOf) -import System.Directory (doesDirectoryExist, getDirectoryContents) -import System.FilePath ((</>)) +import System.Directory (doesDirectoryExist, getDirectoryContents, renameFile) +import System.FilePath ((</>), takeFileName, takeDirectory, splitDirectories, joinPath) import System.IO(IOMode(..), hGetContents, openFile) import Types(Maildir, Flag(..), Flags) @@ -40,10 +40,29 @@ getMessages :: Maildir -> [FilePath] -> IO [(FilePath, Flags, String)] getMessages mb list = do messages <- getAll mb return $ filter (\(id, f, m) -> id `elem` list) messages - --- --- | Based on getRecursiveContents from Real World Haskell --- + +{- Given a mail in a Maildir, mark it as read -} +markAsRead :: FilePath -> IO FilePath +markAsRead fp = + case newPath of + Nothing -> return fp + Just path -> do + renameFile fp path + return path + where newPath = + if not $ isNew fp + then Just fp + else do + let fil = takeFileName fp + let dir = takeDirectory fp + let spl = splitDirectories dir + case last spl of + "cur" -> Just $ fp ++ "S" + "new" -> Just $ (joinPath . init $ spl) </> ("cur" </> (fil ++ "S")) + _ -> Nothing + + +-- Based on getRecursiveContents from Real World Haskell getMaildirsRecursively :: FilePath -> IO [Maildir] getMaildirsRecursively topdir = do result <- search topdir |