IMAP Email display
December 11, 2003 1:03 PM   Subscribe

I need a simple PHP/Perl script that displays the subjects of the last 10 emails in my inbox via an IMAP connection. I'd like to use it as an include on a personal portal page. [more inside]

I can't program on that level and everything I've found so far on the intarweb is a huge integrated portal suite that does way more than I need. Is there a script out there to do this or should I buy someone some beer to write it?
posted by machaus to Computers & Internet (7 answers total)
I have no idea if there's a script out there, but if you don't come up with anything, drop me a line and I'll do it over the weekend just for the distraction value.
posted by majick at 1:09 PM on December 11, 2003

Example 1 on's imap_open page is a good start. I just ran it on my php host and they had all the require libs installed and it ran without a hitch.

In my case, it took a few seconds to run. You probably don't want to do this in real time, but rather as a period cron job and buffer the output.
posted by jschuur at 2:10 PM on December 11, 2003

If you'd prefer perl, it shouldn't be too difficult to repurpose this thing.
posted by xiffix at 2:18 PM on December 11, 2003

Something like this?
// the server attributes, edit to yours
$mailhost = '';
$username = 'yourusername';
$password = 'yourpassword';

$mail_stream = imap_open( "{{$mailhost}}INBOX", $username, $password);
$message_count = imap_num_msg($mail_stream);
$i = ($message_count > 10) ? $message_count - 10 : 1;
for (; $i < $message_count; $i++)
$mesg = imap_headerinfo( $mail_stream, $i);
// look at the imap_headerinfo() function ref
// to see all the info the $mesg object holds.
// and change the echo() func to meet your needs
It probably took me longer to weed out all the < and > characters when posting this than to write it. You'll doubtless have to play with the echo line to get the output formatted how you want it (or to read it into an array); this is strictly proof-of-concept here, but it works for me.
posted by boaz at 3:00 PM on December 11, 2003

Ugg, OSX doesn't have that module compiled by default. This is gonna get ugly.
posted by machaus at 4:50 PM on December 11, 2003

Try Mark Liyanage's PHP module. It's much more complete.
posted by boaz at 5:01 PM on December 11, 2003

Yeah, I just installed that and it didn't break anything else. Sweet! Thanks for everyone's help.
posted by machaus at 10:00 PM on December 11, 2003

« Older What does it mean to "eq" a recording?   |   I have an Apple iBook. Advice on getting an... Newer »
This thread is closed to new comments.