With Gmail you also have to be aware of the fact that Google does not actually implement IMAP to the standard. There are quite a few odd behaviours. A notable one has to do with deletion of emails, but I can't find the exact reference just now. (I can try digging if you're really intereested.)
Robby