]> code.delx.au - offlineimap/commitdiff
Sanified the return type of greeting
authorJohn Goerzen <jgoerzen@complete.org>
Tue, 12 Aug 2008 08:28:55 +0000 (03:28 -0500)
committerJohn Goerzen <jgoerzen@complete.org>
Tue, 12 Aug 2008 08:28:55 +0000 (03:28 -0500)
all tests pass

src/Network/IMAP/Parser.hs
testsrc/TestParser.hs

index 9f910c5bd50da50691b9aebf03a55e5b9c4465f5..4c646b2fca33ef3eaa09b3e831d0269db142367c 100644 (file)
@@ -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
index 3e61eb55e933f4742587ae065a6cd750e1c5df0f..5735042ab2c6d73fbed578eb4e9f4572e18e1ac8 100644 (file)
@@ -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."