
It seems you are expected to fetch until you have the entire thing.
You can't just fetch 40000 and hope you get it all. If you do it
blocking, it will be almost guaranteed to block unless there were
40000 to fetch. If you do it non blocking, you have to keep fetching
until you are sure you have the entire message.
If you are doing this as simply as possible, that means you have to
fetch, and then repeatedly check the string until you are sure you
have the whole thing. You'll do that by fetching once, checking the
beginning of the string for the {342} in the following example from
the rfc:
C: a004 fetch 12 body[header]
S: * 12 FETCH (BODY[HEADER] {342}
S: Date: Wed, 17 Jul 1996 02:23:25 -0700 (PDT)
S: From: Terry Gray
Manfred,
The problem is that the message itself is some 30K big and I only get some 16K of the message.
How could I force to get the whole message?
My guess is that you can't. This call:
c' <- B.hGetNonBlocking h 40000
tries to read as much as it can (up to 40000 bytes) but it won't block to wait for data. Perhaps the rest of your message is in a different TCP packet or delayed or whatever, but I think you have to keep on reading (and maybe block) until you know you have read the entire message. The IMAP specs will tell you how to identify the "end of the message".
BTW: This issue is not Haskell specific. If you implement the same code in C, Perl or Java you will have to deal with the same problem. When you read from a socket, there is no general way of knowing that the other side has sent everything.
Patrick
-- Manfred
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
-- ===================== Patrick LeBoutillier Rosemère, Québec, Canada
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners