Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion HaskellNet.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Extra-Source-Files:

Source-Repository head
type: git
location: git://github.com/qnikst/HaskellNet.git
location: https://github.com/qnikst/HaskellNet.git

Flag network-bsd
description: Use network-bsd
Expand Down Expand Up @@ -87,3 +87,13 @@ Library
network >=2.7
else
Build-Depends: network <2.7

Test-suite imap-parsers
Type: exitcode-stdio-1.0
Hs-Source-Dirs: test
Main-is: IMAPParsersTest.hs
default-language: Haskell2010
Build-Depends:
base >= 4.3 && < 4.22,
HaskellNet,
HUnit >= 1.6 && < 1.7
10 changes: 9 additions & 1 deletion src/Network/HaskellNet/IMAP/Parsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ pListLine list =
pStatusLine :: Parser RespDerivs (Either a [(MailboxStatus, Integer)])
pStatusLine =
do string "* STATUS "
_ <- anyChar `manyTill` space
_ <- pMailboxName
space
stats <- between (char '(') (char ')') (parseStat `sepBy1` space)
crlfP
return $ Right stats
Expand All @@ -274,6 +275,13 @@ pStatusLine =
num <- many1 digit >>= return . read
return (cons, num)

pMailboxName :: Parser RespDerivs MailboxName
pMailboxName = pQuotedString <|> many1 (noneOf " \r\n")

pQuotedString :: Parser RespDerivs String
pQuotedString = between (char '"') (char '"') (many quotedChar)
where quotedChar = (char '\\' >> noneOf "\r\n") <|> noneOf "\"\\\r\n"

pSearchLine :: Parser RespDerivs (Either a [UID])
pSearchLine = do string "* SEARCH "
nums <- (many1 digit) `sepBy` space
Expand Down
31 changes: 29 additions & 2 deletions test/IMAPParsersTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ module Main (main) where
import Network.HaskellNet.IMAP.Parsers
import Network.HaskellNet.IMAP.Types

import System.Exit

import Test.HUnit

baseTest =
Expand Down Expand Up @@ -96,6 +98,27 @@ statusTest =
"* STATUS blurdybloop (MESSAGES 231 UIDNEXT 44292)\r\n\
\A042 OK STATUS completed\r\n"

statusQuotedMailboxTest =
[ ( 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"
, ( OK Nothing "STATUS completed"
, MboxUpdate Nothing Nothing
, [(MESSAGES, 1)])
~=? eval' pStatus "A043"
"* STATUS \"foo\\\" bar\" (MESSAGES 1)\r\n\
\A043 OK STATUS completed\r\n"
, ( OK Nothing "STATUS completed"
, MboxUpdate Nothing Nothing
, [(MESSAGES, 1)])
~=? eval' pStatus "A044"
"* STATUS foo (MESSAGES 1)\r\n\
\A044 OK STATUS completed\r\n"
]

expungeTest =
( OK Nothing "EXPUNGE completed"
, MboxUpdate Nothing Nothing
Expand Down Expand Up @@ -167,11 +190,15 @@ testData = [ "base" ~: baseTest
, "noop" ~: noopTest
, "select" ~: selectTest
, "list" ~: listTest
, "status" ~: statusTest
, "status" ~: TestList [ statusTest, TestList statusQuotedMailboxTest ]
, "expunge" ~: expungeTest
, "search" ~: searchTest
, "fetch" ~: fetchTest
]


main = runTestTT (test testData)
main = do
counts <- runTestTT (test testData)
if errors counts == 0 && failures counts == 0
then exitSuccess
else exitFailure
Loading