From f95aeeadefb4ec87cf7da1c4b323ffa23255f239 Mon Sep 17 00:00:00 2001 From: Marc Scholten Date: Wed, 20 Nov 2024 17:55:59 -0800 Subject: [PATCH] IMAP.status doesn't work when mailbox name contains a space The pStatusLine parser parses until it hits a space. When we have a mailbox like `[Gmail]/Alle Nachrichten`, it will not consume the full mailbox name --- src/Network/HaskellNet/IMAP/Parsers.hs | 7 ++++++- test/IMAPParsersTest.hs | 10 +++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Network/HaskellNet/IMAP/Parsers.hs b/src/Network/HaskellNet/IMAP/Parsers.hs index 8153621..716798b 100644 --- a/src/Network/HaskellNet/IMAP/Parsers.hs +++ b/src/Network/HaskellNet/IMAP/Parsers.hs @@ -259,7 +259,7 @@ pListLine list = pStatusLine :: Parser RespDerivs (Either a [(MailboxStatus, Integer)]) pStatusLine = do string "* STATUS " - _ <- anyChar `manyTill` space + mbox <- parseMailbox stats <- between (char '(') (char ')') (parseStat `sepBy1` space) crlfP return $ Right stats @@ -273,6 +273,11 @@ pStatusLine = space num <- many1 digit >>= return . read return (cons, num) + parseMailbox = do + q <- optional $ char '"' + case q of + Just _ -> do mbox <- anyChar `manyTill` char '"'; space; return mbox + Nothing -> anyChar `manyTill` space pSearchLine :: Parser RespDerivs (Either a [UID]) pSearchLine = do string "* SEARCH " diff --git a/test/IMAPParsersTest.hs b/test/IMAPParsersTest.hs index 6819d6c..2d5996b 100644 --- a/test/IMAPParsersTest.hs +++ b/test/IMAPParsersTest.hs @@ -96,6 +96,14 @@ statusTest = "* STATUS blurdybloop (MESSAGES 231 UIDNEXT 44292)\r\n\ \A042 OK STATUS completed\r\n" +statusWithSpaceTest = + ( OK Nothing "STATUS completed" + , MboxUpdate Nothing Nothing + , [(MESSAGES, 231), (UIDNEXT, 44292)]) + ~=? eval' pStatus "A042" + "* STATUS \"[Gmail]/Alle Nachrichten\" (MESSAGES 231 UIDNEXT 44292)\r\n\ + \A042 OK STATUS completed\r\n" + expungeTest = ( OK Nothing "EXPUNGE completed" , MboxUpdate Nothing Nothing @@ -167,7 +175,7 @@ testData = [ "base" ~: baseTest , "noop" ~: noopTest , "select" ~: selectTest , "list" ~: listTest - , "status" ~: statusTest + , "status" ~: TestList [ statusTest, statusWithSpaceTest ] , "expunge" ~: expungeTest , "search" ~: searchTest , "fetch" ~: fetchTest