Currently I have a PHP script that connect to a mail server via IMAP and parse new emails to MySQL. credentials to connect to the mail server are stored in MySQL using plain
MySQL supports a AES_ENCRYPT() function. You can encrypt as you INSERT it to the database, and decrypt it as you SELECT it back out.
Read the documentation I linked to for examples.
Then make sure you use port 993 for a TLS encrypted connection to the IMAP server when you imap_open() with the plaintext password.