During migration from Ubuntu 12.04 to 14.04 I stumbled over this as well and wanted to share that as of Ubuntu 14.04 LTS the IMAP extension seems no longer to be loaded per default.
Check to verify if the extension is installed:
dpkg -l | grep php5-imap
should give a response like this:
ii php5-imap 5.4.6-0ubuntu5 amd64 IMAP module for php5
if not, install it.
To actually enable the extension
cd /etc/php5/apache2/conf.d
ln -s ../../mods-available/imap.ini 20-imap.ini
service apache2 restart
should fix it for apache. For CLI do the same in /etc/php5/cli/conf.d