iPhone and IMAP problem solved
I had initially a problem with setting IMAP account up on the phone. In case if anybody has a similar problem I put here a description.
The problem with IMAP on iPhone is that it tries to establish secure connection (which is good) and it firstly tries to connect to SSL port - 993, (which is not so good). If it detected unknown certificate then it asks whether you want to proceed. You say yes of course and then the iPhone tries to connect to a standard IMAP port - 143 and establish TLS connection. And again, usually it finds the same certificate used for TLS and asks again whether you want to proceed. You say yes and now the IMAP account is set up and functional.
In my case I had IMAP available only on SSL port - 993. So after the first yes it tried to connect to the standard IMAP port and it couldn't. So the configuration for the IMAP account was failing. The solution was to enable IMAP access on standard IMAP port 143 with TLS turned on.
Below statement is no longer true after upgrading software on the iphone to version 1.1.3. Now any modifications in your e-mail box are updated on the server, regardless you are connected to IMAP or GMail account.
Please remember in same cases iPhone is not very consistent with what it does. If you are connected to IMAP account and you delete message from your INBOX it is also deleted on the server. If you use GMAIL account and you delete the message from your INBOX it is deleted only localy on you iPhone. Just in case there is a Trash on iPhone to recover deleted messages....