Error retrieving object from email using HaskellNet IMAP

I tried to download the subject of some emails, but I got the following error message:

000004:2:1: expecting either "* " or "000004"

      

The following code should reproduce the problem (when the username and password are correctly replaced):

main = do
        conn <- connectIMAPSSL "imap.gmail.com"
        login conn "username" "password"
        boxes <- list conn
        let box = "INBOX"
        select conn box
        uids <- search conn [UNFLAG Seen]
        forM uids $ \uid -> do
            putStrLn "Fetching"
            fetchByString conn uid "BODY[HEADER.FIELDS (SUBJECT)]"
            putStrLn "Fetched"

      

The main problem is that I'm not sure if this is a problem with my code, HaskellNet or GMail.

+3


source to share


2 answers


This is indeed a bug of the parser inside HaskellNet. I submitted a pull request, which you can see here , and in my experience jtdaugherty is pretty quick at responding to these things, so hopefully this will go to the backbone HaskellNet soon.

As Jan Kundrath said, the IMAP log has been invaluable in clearing up the problem. In terms of raw HaskellNet, the answer to the question "how to get the log?" "defines your own BSStream", however, since you are using HaskellNet-SSL to access gmail, BSStream is already defined for you.



I added a parameter to HaskellNet-SSL called "sslLogToConsole" that will push the IMAP session log to the STDOUT line with the token prefix "HaskellNet-SSL" to help you separate them. This feature is available in version 0.2.5, so if you have any more problems, hopefully this helps with debugging them!

Edit: jtdaugherty is so fast that it has merged the changes already before I can manage to type this answer!

+3


source


Some hints ... I can reproduce the error.

Replacing SUBJECT with UID on the next line does not throw an error.

fetchByString conn uid "BODY[HEADER.FIELDS (SUBJECT)]"

      

It works.



fetch conn uid 

      

Looking at the source, it looks like it should mean the same as ...

fetchByString conn uid "BODY[] "

      

but it produces the same error as above. I suspect the problem is not gmail.

0


source







All Articles