I haven't fount the solution to the problem, but I have gathered a little more info that might just help you.
I noticed that I got an "too many login failures" error. After commenting away different pieces of code, i noticed that the problem was NOT in imap_open, but in a call to imap_body(), accidentally requesting (the noexistant) message number 0. This resulted in the "couldn't open stream" error, which half the visitors of this site seem to get.
In other words, your problem is probably not in the line where the error is produced, bit in some call to another function, which requests the imap tream.
I really hope this helps you.