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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
{- Common types of Lazymail
-
- Copyright 2013 Raúl Benencia <rul@kalgan.cc>
-
- Licensed under the GNU GPL version 3 or higher
-}
module Lazymail.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 System.IO(Handle)
import UI.NCurses(Curses, Update, Color(..), ColorID, Event(..))
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]
, globalKeymap :: [Keymap]
, maildirModeKeymap :: [Keymap]
, indexModeKeymap :: [Keymap]
, emailModeKeymap :: [Keymap]
, composeModeKeymap :: [Keymap]
, textEditor :: FilePath
, sendmailCommand :: [String]
}
data Email = Email {
emailValue :: MIMEValue
, emailDate :: DateTime
, emailPath :: FilePath
, emailHandle :: Handle
}
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
, inputState :: InputState
, colorStyle :: ColorStyle
}
data MaildirState = MaildirState {
selectedRowMD :: Int
, selectedMD :: String
, detectedMDs :: [(FilePath, String)]
, scrollRowMD :: Int
, scrollBufferMD :: [(FilePath, String)]
, triggerUpdateMD :: Bool
}
data IndexState = IndexState {
selectedRowIn :: Int
, selectedEmailPath :: FilePath
, selectedEmails :: [Email]
, scrollRowIn :: Int
, currentInLen :: Int
, scrollBufferIn :: [(FilePath, String)]
, triggerUpdateIn :: Bool
}
data ComposeState = ComposeState {
composeFields :: ComposeFields
, bodyFileName :: Maybe FilePath
, bodyReady :: Bool
}
data ComposeFields = ComposeFields {
fromField :: Maybe String
, toField :: Maybe String
, ccField :: Maybe String
, bccField :: Maybe String
, subjectField :: Maybe String
, replyToField :: 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
}
data InputState = InputState {
inputRequested :: Bool
, prompt :: Maybe String
, currentInput :: String
, postInputActions :: LazymailCurses ()
}
type Keymap = ([Event], LazymailCurses ())
|