1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
{- Lazymail user configuration
-
- Copyright 2013 Raúl Benencia <rul@kalgan.cc>
-
- Licensed under the GNU GPL version 3 or higher
-
-}
module Config(LazymailConfig(..), defaultConfig, customConfig) where
import Data.List(sort, stripPrefix)
import System.FilePath(FilePath, takeFileName, dropTrailingPathSeparator)
import System.Posix.Files(getSymbolicLinkStatus, isSymbolicLink)
import UI.NCurses(Color(..))
data LazymailConfig = LazymailConfig {
baseColor :: (Color, Color) -- (foreground, background)
, selectionColor :: (Color, Color)
, statusBarColor :: (Color, Color)
, showStatusBar :: Bool
, initialPath :: FilePath
, filterMaildirsHook :: [FilePath] -> IO [FilePath]
, maildirDrawHook :: String -> String -> String
}
defaultConfig = LazymailConfig {
baseColor = (ColorWhite, ColorBlack)
, selectionColor = (ColorYellow, ColorBlack)
, statusBarColor = (ColorYellow, ColorBlack)
, showStatusBar = True
, initialPath = ""
, filterMaildirsHook = \mds -> return mds
, maildirDrawHook = \_ md -> md
}
--
-- | Users should modify customConfig in order to set-up their
-- preferences. In a possible future maybe I'll work in a not-so-crappy
-- config system.
--
--customConfig = defaultConfig { initialPath = "/home/rul/mail/"}
customConfig = defaultConfig { initialPath = "/home/rul/mail/linti"
, maildirDrawHook = indentedShow
, filterMaildirsHook = filterSymlinks }
indentedShow :: String -> String -> String
indentedShow bp md =
let str = case (stripPrefix bp md) of
Nothing -> md
Just s -> s
name' = takeFileName . dropTrailingPathSeparator $ str
name = takeFileName $ map (\x -> if x `elem` imapSep then '/' else x) name'
pad = " "
numPads = (length $ filter (== '/') str) + (length $ filter (`elem` imapSep) str)
imapSep = ['.'] -- IMAP usually separates its directories with dots
in (concat $ replicate (numPads - 1) pad) ++ name
filterSymlinks :: [FilePath] -> IO [FilePath]
filterSymlinks [] = return []
filterSymlinks (md:mds) = do
filtered <- do
fs <- getSymbolicLinkStatus md
rest <- filterSymlinks mds
if isSymbolicLink fs
then return rest
else return (md:rest)
return $ sort filtered
|