{- | Returns Left for a "BYE" response, or Right if we are ready to
proceed with auth (or preauth). -}
-greeting :: IMAPParser (Either RespText (AuthReady, RespText))
+greeting :: IMAPParser (AuthReady, RespText)
greeting =
do string "* "
- (respCondBye >>= return . Left) <|>
- (respCondAuth >>= return . Right)
+ respCondBye <|> respCondAuth
-data AuthReady = AUTHOK | AUTHPREAUTH
+data AuthReady = AUTHOK | AUTHPREAUTH | AUTHBYE
deriving (Eq, Read, Show)
data RespText = RespText {respTextCode :: Maybe String,
t <- respText
return (s, t)
-respCondBye :: IMAPParser RespText
+respCondBye :: IMAPParser (AuthReady, RespText)
respCondBye =
do string "BYE "
- respText
+ t <- respText
+ return (AUTHBYE, t)
-- Less strict than mandated in RFC3501 formal syntax
respText :: IMAPParser RespText
prop_greeting_bye s =
isValidAtom s && head s /= '[' ==>
p greeting ("* BYE " ++ s) @?=
- (Just $ Left $ RespText Nothing s)
+ (Just $ (AUTHBYE, RespText Nothing s))
prop_greeting_auth :: String -> Property
prop_greeting_auth s =
isValidAtom s && head s /= '[' ==>
p' greeting ("* OK " ++ s) @?=
- (Right $ Right $ (AUTHOK, RespText Nothing s))
+ (Right $ (AUTHOK, RespText Nothing s))
prop_greeting_courier :: Result
prop_greeting_courier =
p greeting courierStr @?=
- (Just $ Right $ (AUTHOK, RespText (Just code) text))
+ (Just $ (AUTHOK, RespText (Just code) text))
where courierStr = "* OK [CAPABILITY IMAP4rev1 UIDPLUS CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA IDLE ACL ACL2=UNION] Courier-IMAP ready. See COPYING for distribution information."
code = "CAPABILITY IMAP4rev1 UIDPLUS CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA IDLE ACL ACL2=UNION"
text = "Courier-IMAP ready. See COPYING for distribution information."