{-# 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
(Flag -> Flag -> Bool) -> (Flag -> Flag -> Bool) -> Eq Flag
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
(Int -> Flag -> ShowS)
-> (Flag -> String) -> ([Flag] -> ShowS) -> Show Flag
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 = a -> IO [(b, [Flag])]
forall a b. MailboxReader a b => a -> IO [(b, [Flag])]
listMessageFlags a
mb IO [(b, [Flag])] -> ([(b, [Flag])] -> IO [b]) -> IO [b]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= [b] -> IO [b]
forall (m :: * -> *) a. Monad m => a -> m a
return ([b] -> IO [b])
-> ([(b, [Flag])] -> [b]) -> [(b, [Flag])] -> IO [b]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((b, [Flag]) -> b) -> [(b, [Flag])] -> [b]
forall a b. (a -> b) -> [a] -> [b]
map (b, [Flag]) -> b
forall a b. (a, b) -> a
fst
listMessageFlags a
mb = a -> IO [(b, [Flag], String)]
forall a b. MailboxReader a b => a -> IO [(b, [Flag], String)]
getAll a
mb IO [(b, [Flag], String)]
-> ([(b, [Flag], String)] -> IO [(b, [Flag])]) -> IO [(b, [Flag])]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= [(b, [Flag])] -> IO [(b, [Flag])]
forall (m :: * -> *) a. Monad m => a -> m a
return ([(b, [Flag])] -> IO [(b, [Flag])])
-> ([(b, [Flag], String)] -> [(b, [Flag])])
-> [(b, [Flag], String)]
-> IO [(b, [Flag])]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
((b, [Flag], String) -> (b, [Flag]))
-> [(b, [Flag], String)] -> [(b, [Flag])]
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 <- a -> IO [(b, [Flag], String)]
forall a b. MailboxReader a b => a -> IO [(b, [Flag], String)]
getAll a
mb
[(b, [Flag], String)] -> IO [(b, [Flag], String)]
forall (m :: * -> *) a. Monad m => a -> m a
return ([(b, [Flag], String)] -> IO [(b, [Flag], String)])
-> [(b, [Flag], String)] -> IO [(b, [Flag], String)]
forall a b. (a -> b) -> a -> b
$ ((b, [Flag], String) -> Bool)
-> [(b, [Flag], String)] -> [(b, [Flag], String)]
forall a. (a -> Bool) -> [a] -> [a]
filter (\(b
x, [Flag]
_, String
_) -> b
x b -> [b] -> Bool
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 ()