]> code.delx.au - offlineimap/blobdiff - src/Network/IMAP/Parser.hs
Sanified the return type of greeting
[offlineimap] / src / Network / IMAP / Parser.hs
index 23cf07461a0f89c3c12ef53bf001f86a5e673bde..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
@@ -103,10 +103,11 @@ respText =
     where respTextCode =
               do char '['
                  a <- atom
-                 sp
-                 b <- option "" respTextCodeText
+                 b <- option "" (sp >> respTextCodeText)
                  char ']'
                  sp
-                 return (a ++ " " ++ b)
+                 case b of
+                   [] -> return a
+                   _ -> return $ a ++ " " ++ b
           respTextCodeText = many1 (noneOf (']' : crlf))
                  
\ No newline at end of file