diff options
-rw-r--r-- | Config.hs | 9 | ||||
-rw-r--r-- | Handlers.hs | 2 | ||||
-rw-r--r-- | Maildir.hs | 9 | ||||
-rw-r--r-- | Print.hs | 7 | ||||
-rw-r--r-- | Screen.hs | 22 | ||||
-rw-r--r-- | State.hs | 1 | ||||
-rw-r--r-- | Types.hs | 19 |
7 files changed, 52 insertions, 17 deletions
@@ -16,14 +16,15 @@ import Types(LazymailConfig(..)) defaultConfig = LazymailConfig { baseColor = (ColorWhite, ColorBlack) - , selectionColor = (ColorYellow, ColorBlack) - , statusBarColor = (ColorYellow, ColorBlack) - , headerColor = (ColorYellow, ColorBlack) + , selectionColor = (ColorBlack, ColorWhite) + , statusBarColor = (ColorBlack, ColorBlue) + , headerColor = (ColorGreen, ColorBlack) + , newEmailColor = (ColorBlue, ColorBlack) , showStatusBar = True , initialPath = "" , filterMaildirsHook = \mds -> return mds , indexDateFormat = "%m %d" - , headersToShow = ["date", "from", "to", "cc", "bcc", "subject", "reply-to"] + , headersToShow = ["date", "from", "to", "cc", "bcc", "subject", "reply-to"] } -- diff --git a/Handlers.hs b/Handlers.hs index fc4c009..644d643 100644 --- a/Handlers.hs +++ b/Handlers.hs @@ -170,7 +170,7 @@ formatIndexModeRows st = map formatRow where email = emailValue e hs = mime_val_headers email str = normalizeLen (screenColumns st) $ intercalate ppSep $ - [ ppFlags . getFlags $ fp + [ "[" ++ normalizeLen maxFlags (ppFlags . getFlags $ fp) ++ "]" , formatDateTime "%b %d" $ emailDate e , normalizeLen fromLen $ ppField $ lookupField "from" hs , ppField $ lookupField "subject" hs @@ -14,9 +14,8 @@ import Data.List(isPrefixOf) import System.Directory (doesDirectoryExist, getDirectoryContents) import System.FilePath ((</>)) import System.IO(IOMode(..), hGetContents, openFile) -import Network.Email.Mailbox(Flag(..), Flags) -type Maildir = FilePath +import Types(Maildir, Flag(..), Flags) isMaildir :: FilePath -> IO Bool isMaildir fp = allM doesDirectoryExist [ fp @@ -96,12 +95,16 @@ listMessageFlags fp = do return (zip ids flags) getFlags :: FilePath -> Flags -getFlags fp = map toFlag $ strip fp +getFlags fp = addNew $ map toFlag $ strip fp where strip x | null x = [] | ":2," `isPrefixOf` x = drop 3 x | otherwise = let (discard, analyze) = span (/= ':') fp in strip analyze + addNew flags = if elem SEEN flags then flags else (NEW:flags) + +isNew :: FilePath -> Bool +isNew fp = elem NEW $ getFlags fp toFlag :: Char -> Flag toFlag c | c == 'S' = SEEN @@ -10,11 +10,10 @@ module Print where import Data.Char (isSpace) import Data.List (intercalate) -import Network.Email.Mailbox(Flag(..), Flags) -import Text.ParserCombinators.Parsec.Rfc2822(NameAddr(..)) import Email import Rfc1342 +import Types(Flag(..), Flags) unquote xs= if (head xs == '"' && last xs == '"') then (tail . init) xs else xs @@ -26,12 +25,16 @@ ppField = flat . decodeField fromLen :: Int fromLen = 20 +maxFlags :: Int +maxFlags = 4 + flat xs = intercalate " " $ map (dropWhile isSpace) $ map (filter (/= '\r')) $ lines xs ppFlags :: Flags -> String ppFlags = map ppFlag ppFlag :: Flag -> Char +ppFlag NEW = 'N' ppFlag SEEN = 'S' ppFlag ANSWERED = 'A' ppFlag FLAGGED = 'F' @@ -54,12 +54,12 @@ startCurses = do basColID <- newColorID (fst . baseColor $ cfg) (snd . baseColor $ cfg) 1 selColID <- newColorID (fst . selectionColor $ cfg) (snd . selectionColor $ cfg) 2 staColID <- newColorID (fst . statusBarColor $ cfg) (snd . statusBarColor $ cfg) 3 - heaColID <- newColorID (fst . headerColor $ cfg) (snd . headerColor $ cfg) 3 - let style = ColorStyle defaultColorID selColID staColID heaColID + heaColID <- newColorID (fst . headerColor $ cfg) (snd . headerColor $ cfg) 4 + newColID <- newColorID (fst . newEmailColor $ cfg) (snd . newEmailColor $ cfg) 5 + let style = ColorStyle basColID selColID staColID heaColID newColID return $ st { screenRows = fromIntegral $ rows - 1 , screenColumns = fromIntegral $ cols , colorStyle = style } - resetScrollBuffer screenLoop @@ -110,7 +110,7 @@ drawSelectionList ((path, str):mds) = do let ist = (indexState st) { selectedEmailPath = path } return $ st { indexState = ist } else do - drawString $ normalizeLen (screenColumns st) str + drawSimpleRow st path str return st st <- get @@ -122,6 +122,16 @@ drawSelectionList ((path, str):mds) = do else resetCurrentRow +drawSimpleRow st path str | (mode st) == MaildirMode = drawString $ normalizeLen (screenColumns st) str + | (mode st) == IndexMode = + if isNew path + then do + setColor $ newEmailColorID . colorStyle $ st + drawCroppedString st str + setColor $ baseColorID . colorStyle $ st + else + drawCroppedString st str + {- Empty the whole window. Useful when changing modes. -} clearMain rows columns = do drawEmptyLine 0 @@ -166,7 +176,7 @@ drawEmailHeaders = do Nothing -> parseHeaders headers row hs Just f -> let p = capitalize h ++ ": " ++ (ppField f) in p:parseHeaders headers (row + 1) hs - + capitalize str = (toUpper . head $ str):(tail str) drawHeaders _ _ [] = return () drawHeaders st row (h:hs) = do @@ -187,7 +197,7 @@ drawStatus = do liftUpdate $ do moveCursor ((scrRowsAsInteger st) - 1) 0 setColor $ statusBarColorID . colorStyle $ st - drawString . normalizeLen (screenColumns st) . concat $ drawStatusHelper (mode st) st + drawCroppedString st $ concat $ drawStatusHelper (mode st) st setColor $ baseColorID . colorStyle $ st {- Status bar string for Maildir mode -} @@ -65,6 +65,7 @@ initialColorStyle = ColorStyle { , selectionColorID = defaultColorID , statusBarColorID = defaultColorID , headerColorID = defaultColorID + , newEmailColorID = defaultColorID } scrColsAsInteger st = toInteger $ screenColumns st @@ -27,11 +27,12 @@ data LazymailConfig = LazymailConfig { , selectionColor :: (Color, Color) , statusBarColor :: (Color, Color) , headerColor :: (Color, Color) + , newEmailColor :: (Color, Color) , showStatusBar :: Bool , initialPath :: FilePath , filterMaildirsHook :: [FilePath] -> IO [FilePath] , indexDateFormat :: String - , headersToShow :: [String] + , headersToShow :: [String] } data Email = Email { @@ -47,6 +48,21 @@ instance Ord Email where (Email _ d1 _) `compare` (Email _ d2 _) = d1 `compare` d2 data Mode = MaildirMode | IndexMode | EmailMode | ComposeMode + deriving (Show, Eq) + +type Maildir = FilePath + +data Flag = NEW + | SEEN + | ANSWERED + | FLAGGED + | DELETED + | DRAFT + | FORWARDED + | OTHERFLAG String + deriving (Eq) + +type Flags = [Flag] data LazymailState = LazymailState { mode :: Mode @@ -97,4 +113,5 @@ data ColorStyle = ColorStyle { , selectionColorID :: ColorID , statusBarColorID :: ColorID , headerColorID :: ColorID + , newEmailColorID :: ColorID } |