@@ -255,6 +255,79 @@ imapFetchTest =
255255 ]
256256 fetched <- IMAP. fetch conn 42
257257 body @=? fetched
258+ , " fetchPeek reads body response without setting Seen" ~: TestCase $ do
259+ let body = BS. pack " peeked"
260+ conn <- scriptedConnection
261+ [ line (" * 12 FETCH (BODY[] {" ++ show (BS. length body) ++ " }" )
262+ , ReadBytes body
263+ , line " UID 42)"
264+ , okLine " FETCH completed"
265+ ]
266+ fetched <- IMAP. fetchPeek conn 42
267+ body @=? fetched
268+ , " fetchSize parses scalar size responses" ~: TestCase $ do
269+ conn <- scriptedConnection
270+ [ line " * 12 FETCH (RFC822.SIZE 12345 UID 42)"
271+ , okLine " FETCH completed"
272+ ]
273+ fetched <- IMAP. fetchSize conn 42
274+ 12345 @=? fetched
275+ , " fetchFlags parses parenthesized flag responses" ~: TestCase $ do
276+ conn <- scriptedConnection
277+ [ line " * 12 FETCH (FLAGS (\\ Seen \\ Deleted) UID 42)"
278+ , okLine " FETCH completed"
279+ ]
280+ fetched <- IMAP. fetchFlags conn 42
281+ [Seen , Deleted ] @=? fetched
282+ , " fetchHeaderFields matches normalized body section keys" ~: TestCase $ do
283+ let headers = BS. pack " Subject: Hi\r\n From: a@example.com\r\n\r\n "
284+ conn <- scriptedConnection
285+ [ line (" * 12 FETCH (BODY[HEADER.FIELDS (SUBJECT FROM)] {"
286+ ++ show (BS. length headers) ++ " }" )
287+ , ReadBytes headers
288+ , line " UID 42)"
289+ , okLine " FETCH completed"
290+ ]
291+ fetched <- IMAP. fetchHeaderFields conn 42 [" Subject" , " From" ]
292+ headers @=? fetched
293+ , " fetchR maps sequence numbers to response UIDs" ~: TestCase $ do
294+ let firstBody = BS. pack " one"
295+ secondBody = BS. pack " two"
296+ conn <- scriptedConnection
297+ [ line (" * 1 FETCH (BODY[] {" ++ show (BS. length firstBody) ++ " }" )
298+ , ReadBytes firstBody
299+ , line " UID 101)"
300+ , line (" * 2 FETCH (BODY[] {" ++ show (BS. length secondBody) ++ " }" )
301+ , ReadBytes secondBody
302+ , line " UID 102)"
303+ , okLine " FETCH completed"
304+ ]
305+ fetched <- IMAP. fetchR conn (1 , 2 )
306+ [(101 , firstBody), (102 , secondBody)] @=? fetched
307+ , " fetchByString keeps scalar and literal values compatible" ~: TestCase $ do
308+ let headers = BS. pack " hello"
309+ conn <- scriptedConnection
310+ [ line (" * 12 FETCH (RFC822.SIZE 123 FLAGS (\\ Seen) BODY[HEADER] {"
311+ ++ show (BS. length headers) ++ " }" )
312+ , ReadBytes headers
313+ , line " NILKEY NIL QUOTED \" world\" UID 42)"
314+ , okLine " FETCH completed"
315+ ]
316+ fetched <- IMAP. fetchByString conn 42
317+ " RFC822.SIZE FLAGS BODY[HEADER] NILKEY QUOTED"
318+ [ (" RFC822.SIZE" , " 123" )
319+ , (" FLAGS" , " (\\ Seen)" )
320+ , (" BODY[HEADER]" , " hello" )
321+ , (" NILKEY" , " NIL" )
322+ , (" QUOTED" , " \" world\" " )
323+ , (" UID" , " 42" )
324+ ] @=? fetched
325+ , " store accepts FETCH data in STORE responses" ~: TestCase $ do
326+ conn <- scriptedConnection
327+ [ line " * 12 FETCH (UID 42 FLAGS (\\ Seen))"
328+ , okLine " STORE completed"
329+ ]
330+ IMAP. store conn 42 (IMAP. PlusFlags [Seen ])
258331 ]
259332
260333testData = [ " base" ~: baseTest
0 commit comments