Hello Ayman,
my suggestion is that you take a look at what has already been acomplished so far in other projects.
If you look around searching for Webmail you will stumble across squirrelmail and IMP. We installed the later one using OpenLDAP, Cyrus IMAP daemon, Postfix. You can savely take these three programms to have a start for your scripts. Using the ns_ldap you can have one password for both the Cyrus/ACS.
Once you have the basics up I'd strongly encourage you to take a look at IMP or squirrelmail, as they already have a lot of features implemented and would allow you to take some of what they have done already and reimplement it within OpenACS. Especially interesting would be the connection between IMAP and OpenACS itself.
On the other hand you can take a completly different approach and implement an IMAP server within AOLserver which stores the emails in the database. This has some benefits, if you look around in the bboards you should see some postings dealing with it.
Hope this gives you a lead where to start