{-# LANGUAGE Safe #-}
module Network.Email.Mailbox(Flag(..), Flags, Message,
MailboxReader(..),
MailboxWriter(..))
where
data Flag =
SEEN
| ANSWERED
| FLAGGED
| DELETED
| DRAFT
| FORWARDED
| OTHERFLAG String
deriving (Flag -> Flag -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Flag -> Flag -> Bool
$c/= :: Flag -> Flag -> Bool
== :: Flag -> Flag -> Bool
$c== :: Flag -> Flag -> Bool
Eq, Int -> Flag -> ShowS
[Flag] -> ShowS
Flag -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Flag] -> ShowS
$cshowList :: [Flag] -> ShowS
show :: Flag -> String
$cshow :: Flag -> String
showsPrec :: Int -> Flag -> ShowS
$cshowsPrec :: Int -> Flag -> ShowS
Show)
type Flags = [Flag]
type Message = String
class (Show a, Show b, Eq b) => MailboxReader a b where
listIDs :: a -> IO [b]
listMessageFlags :: a -> IO [(b, Flags)]
getAll :: a -> IO [(b, Flags, Message)]
getMessages :: a -> [b] -> IO [(b, Flags, Message)]
listIDs a
mb = forall a b. MailboxReader a b => a -> IO [(b, [Flag])]
listMessageFlags a
mb forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst
listMessageFlags a
mb = forall a b. MailboxReader a b => a -> IO [(b, [Flag], String)]
getAll a
mb forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall a b. (a -> b) -> [a] -> [b]
map (\(b
i, [Flag]
f, String
_) -> (b
i, [Flag]
f))
getMessages a
mb [b]
list =
do [(b, [Flag], String)]
messages <- forall a b. MailboxReader a b => a -> IO [(b, [Flag], String)]
getAll a
mb
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. (a -> Bool) -> [a] -> [a]
filter (\(b
x, [Flag]
_, String
_) -> b
x forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [b]
list) [(b, [Flag], String)]
messages
class (MailboxReader a b) => MailboxWriter a b where
appendMessages :: a -> [(Flags, Message)] -> IO [b]
deleteMessages :: a -> [b] -> IO ()
addFlags :: a -> [b] -> Flags -> IO ()
removeFlags :: a -> [b] -> Flags -> IO ()
setFlags :: a -> [b] -> Flags -> IO ()