aboutsummaryrefslogtreecommitdiff
path: root/Handlers.hs
diff options
context:
space:
mode:
authorRaúl Benencia <rul@kalgan.cc>2013-09-03 20:24:51 -0300
committerRaúl Benencia <rul@kalgan.cc>2013-09-03 20:24:51 -0300
commit84fa12fef1736d04ee79e40cebaadadda262f063 (patch)
tree4842389a50b1c0f76b3d9a27ef3f562adac87b57 /Handlers.hs
parentc91af8d1f85f876eb7119ce8406385cf570d3886 (diff)
Mark as read functionality
Diffstat (limited to 'Handlers.hs')
-rw-r--r--Handlers.hs41
1 files changed, 39 insertions, 2 deletions
diff --git a/Handlers.hs b/Handlers.hs
index da886b3..5c04f89 100644
--- a/Handlers.hs
+++ b/Handlers.hs
@@ -26,7 +26,13 @@ import Types
previousMode :: Mode -> LazymailCurses ()
previousMode MaildirMode = (=<<) put $ get >>= \st -> return st { exitRequested = True }
-previousMode EmailMode = (=<<) put $ get >>= \st -> return st { mode = IndexMode }
+previousMode EmailMode = do
+ st <- get
+ if (triggerUpdateIn . indexState $ st)
+ then do
+ changeMode MaildirMode
+ solveIndexUpdate
+ else put $ st { mode = IndexMode }
previousMode IndexMode = do
st <- get
let ist = (indexState st) { selectedRowIn = 0, scrollRowIn = 0 }
@@ -36,7 +42,13 @@ changeMode :: Mode -> LazymailCurses ()
changeMode EmailMode = return ()
changeMode IndexMode = do
st <- get
- msg <- liftIO $ UTF8.readFile (selectedEmailPath . indexState $ st)
+ let fp = selectedEmailPath . indexState $ st
+ nfp <- if (isNew fp)
+ then liftIO $ markAsRead fp
+ else return fp
+ when (fp /= nfp) triggerIndexUpdate
+ st <- get
+ msg <- liftIO $ UTF8.readFile nfp
let email = parseMIMEMessage msg
let body = getBody $ email
let el = formatBody body $ screenColumns st
@@ -193,3 +205,28 @@ formatMaildirModeRows st = mapM formatRow where
pad = " "
numPads = (length $ filter (== '/') str) + (length $ filter (`elem` imapSep) str)
imapSep = ['.'] -- IMAP usually separates its directories with dots
+
+triggerIndexUpdate :: LazymailCurses ()
+triggerIndexUpdate = do
+ st <- get
+ let ist = indexState st
+ put $ st { indexState = (ist { triggerUpdateIn = True }) }
+
+solveIndexUpdate :: LazymailCurses ()
+solveIndexUpdate = do
+ st <- get
+ let ist = indexState st
+ put $ st { indexState = (ist { triggerUpdateIn = False }) }
+
+triggerMaildirUpdate :: LazymailCurses ()
+triggerMaildirUpdate = do
+ st <- get
+ let mst = maildirState st
+ put $ st { maildirState = (mst { triggerUpdateMD = True }) }
+
+solveMaildirUpdate :: LazymailCurses ()
+solveMaildirUpdate = do
+ st <- get
+ let mst = maildirState st
+ put $ st { maildirState = (mst { triggerUpdateMD = False }) }
+
nihil fit ex nihilo