aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Handlers.hs9
-rw-r--r--Types.hs12
2 files changed, 14 insertions, 7 deletions
diff --git a/Handlers.hs b/Handlers.hs
index 644d643..da886b3 100644
--- a/Handlers.hs
+++ b/Handlers.hs
@@ -13,6 +13,7 @@ import Control.Exception(evaluate)
import Control.Monad.State
import Data.List(intercalate, stripPrefix, sort)
import System.FilePath(FilePath, takeFileName, dropTrailingPathSeparator)
+import System.IO(openFile, IOMode(..), hClose)
import System.Locale(rfc822DateFormat)
import Data.DateTime(parseDateTime, startOfTime, formatDateTime)
import qualified System.IO.UTF8 as UTF8
@@ -45,6 +46,7 @@ changeMode IndexMode = do
changeMode MaildirMode = do
st <- get
unsortedEmails <- liftIO $ do
+ freeOldHandlers st
let md = (selectedMD . maildirState) $ st
emails <- getMaildirEmails md
mapM toEmail emails
@@ -60,11 +62,14 @@ changeMode MaildirMode = do
where
toEmail fp = do
- msg <- readFile fp
+ handle <- openFile fp ReadMode
+ msg <- UTF8.hGetContents handle
let value = parseMIMEMessage msg
let headers = mime_val_headers value
let date = maybe startOfTime id $ parseDateTime rfc822DateFormat $ takeWhile (/= '(') $ lookupField "date" headers
- return (Email value date fp)
+ return (Email value date fp handle)
+
+freeOldHandlers st = mapM (hClose . emailHandle) $ selectedEmails . indexState $ st
{- Boilerplate code -}
incSelectedRow IndexMode = do
diff --git a/Types.hs b/Types.hs
index 86ca334..c5e9428 100644
--- a/Types.hs
+++ b/Types.hs
@@ -12,6 +12,7 @@ import Control.Monad.Reader(ReaderT)
import Control.Monad.State(StateT)
import Data.DateTime(DateTime)
import System.FilePath(FilePath)
+import System.IO(Handle)
import UI.NCurses(Curses, Update, Color(..), ColorID)
type LazymailUpdate = ReaderT LazymailConfig (StateT LazymailState Update)
@@ -36,16 +37,17 @@ data LazymailConfig = LazymailConfig {
}
data Email = Email {
- emailValue :: MIMEValue
- , emailDate :: DateTime
- , emailPath :: FilePath
+ emailValue :: MIMEValue
+ , emailDate :: DateTime
+ , emailPath :: FilePath
+ , emailHandle :: Handle
}
instance Eq Email where
- (Email _ _ fp1) == (Email _ _ fp2) = fp1 == fp2
+ (Email _ _ fp1 _) == (Email _ _ fp2 _) = fp1 == fp2
instance Ord Email where
- (Email _ d1 _) `compare` (Email _ d2 _) = d1 `compare` d2
+ (Email _ d1 _ _) `compare` (Email _ d2 _ _) = d1 `compare` d2
data Mode = MaildirMode | IndexMode | EmailMode | ComposeMode
deriving (Show, Eq)
nihil fit ex nihilo