aboutsummaryrefslogtreecommitdiff
path: root/Types.hs
blob: 86ca3347705910a65abeacc09fa123c6cffed5ef (plain)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
{- Common types of Lazymail
 -
 - Copyright 2013 Raúl Benencia <rul@kalgan.cc>
 -
 - Licensed under the GNU GPL version 3 or higher
 -}

module Types where

import Codec.MIME.Type(MIMEValue(..))
import Control.Monad.Reader(ReaderT)
import Control.Monad.State(StateT)
import Data.DateTime(DateTime)
import System.FilePath(FilePath)
import UI.NCurses(Curses, Update, Color(..), ColorID)

type LazymailUpdate = ReaderT LazymailConfig (StateT LazymailState Update)
type LazymailCurses = ReaderT LazymailConfig (StateT LazymailState Curses)

{- Lazymail monad is a ReaderT around a StateT with IO at the bottom of the
 - stack.
 -}
type Lazymail = ReaderT LazymailConfig (StateT LazymailState IO)

data LazymailConfig = LazymailConfig {
    baseColor          :: (Color, Color) -- (foreground, background)
  , selectionColor     :: (Color, Color)
  , statusBarColor     :: (Color, Color)
  , headerColor        :: (Color, Color)
  , newEmailColor      :: (Color, Color)
  , showStatusBar      :: Bool
  , initialPath        :: FilePath
  , filterMaildirsHook :: [FilePath] -> IO [FilePath]
  , indexDateFormat    :: String
  , headersToShow      :: [String]
}

data Email = Email {
    emailValue :: MIMEValue
  , emailDate  :: DateTime
  , emailPath  :: FilePath
}

instance Eq Email where
  (Email _ _ fp1) == (Email _ _ fp2) = fp1 == fp2

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
  , basePath        :: FilePath
  , screenRows      :: Int
  , screenColumns   :: Int
  , currentRow      :: Int
  , columnPadding   :: Int
  , exitRequested   :: Bool
  , statusBar       :: Bool
  , maildirState    :: MaildirState
  , indexState      :: IndexState
  , emailState      :: EmailState
  , composeState    :: ComposeState
  , colorStyle      :: ColorStyle
}

data MaildirState = MaildirState {
    selectedRowMD   :: Int
  , selectedMD      :: String
  , detectedMDs     :: [(FilePath, String)]
  , scrollRowMD     :: Int
  , scrollBufferMD  :: [(FilePath, String)]
}

data IndexState = IndexState {
    selectedRowIn     :: Int
  , selectedEmailPath :: FilePath
  , selectedEmails    :: [Email]
  , scrollRowIn       :: Int
  , currentInLen      :: Int
  , scrollBufferIn    :: [(FilePath, String)]
}

data ComposeState = ComposeState {
    composition     :: Maybe String
}

data EmailState = EmailState {
    scrollRowEm    :: Int
  , bodyStartRow   :: Int
  , emailLines     :: [String]
  , currentEmail   :: MIMEValue
}

data ColorStyle = ColorStyle {
    baseColorID      :: ColorID
  , selectionColorID :: ColorID
  , statusBarColorID :: ColorID
  , headerColorID    :: ColorID
  , newEmailColorID  :: ColorID
}
nihil fit ex nihilo