This is more of a utility. You manually set the variables for the output file and in the array $thisServer, then run it. It will open each message, retrieving all e-mail addresses in the to, from, reply_to, sender, cc and bcc header fields. The output is a cleaned up list of e-mail addresses stored in $dataFile.
All e-mail addresses are set to lower case, then stored as the key in a hash, effectively removing duplicates.
NOTE: you can change the headers searched by modifying the $headerFieldsToSearch parameter.
Modify the script, then run as
php ./getImapAddress.php
Then, go look wherever you set $dataFile.
Download Here or use wget http://unixservertech.com/scripts/getImapAddresses.tgz