From: John Goerzen Date: Tue, 12 Aug 2008 08:28:55 +0000 (-0500) Subject: Sanified the return type of greeting X-Git-Url: https://code.delx.au/offlineimap/commitdiff_plain/b7c530c743d45c82a829e4a1daf4c0ade1c3ff30 Sanified the return type of greeting all tests pass --- diff --git a/src/Network/IMAP/Parser.hs b/src/Network/IMAP/Parser.hs index 9f910c5..4c646b2 100644 --- a/src/Network/IMAP/Parser.hs +++ b/src/Network/IMAP/Parser.hs @@ -68,13 +68,12 @@ getFullLine accum conn = {- | 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, @@ -89,10 +88,11 @@ respCondAuth = 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 diff --git a/testsrc/TestParser.hs b/testsrc/TestParser.hs index 3e61eb5..5735042 100644 --- a/testsrc/TestParser.hs +++ b/testsrc/TestParser.hs @@ -94,18 +94,18 @@ prop_greeting_bye :: String -> Property 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."