<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<style>
div.toggler { border:1px solid #ccc; background:url(gmail2.jpg) 10px 12px #eee no-repeat; cursor:pointer; padding:10px 32px; }
div.toggler .subject { font-weight:bold; }
div.read { color:#666; }
div.toggler .from, div.toggler .date { font-style:italic; font-size:11px; }
div.body { padding:10px 20px; }
</style>
<script type=”text/javascript” src=”http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js”></script>
<script type=”text/javascript”>
$(document).ready(function(){
$(“.toggler “).click(function(){
$(“.body”).toggle();
});
});
</script>
</head>
<body>
<?php
ini_set(“max_execution_time”,360);
/* connect to server */
$hostname = ‘{domain.com:143/notls}INBOX’;
$username = ‘amit@domain.com’;
$password = ‘amitmondal’;
/* try to connect */
$inbox = imap_open($hostname,$username,$password) or die(‘Cannot connect to domain:’ . imap_last_error());
/* grab emails */
$emails = imap_search($inbox,’ALL’);
/* if emails are returned, cycle through each… */
if($emails) {
$output = ”;
/* put the newest emails on top */
rsort($emails);
echo “Number of email:”.imap_num_msg($inbox);
/* for every email… */
foreach($emails as $email_number) {
$overview = imap_fetch_overview($inbox,$email_number,0);
$message = imap_fetchbody($inbox,$email_number,1);
$output.= ‘<div class=”toggler ‘.($overview[0]->seen ? ‘read’ : ‘unread’).’”>’;
$output.= ‘<span class=”subject”>’.$overview[0]->subject.’</span> ‘;
$output.= ‘<span class=”from”>’.$overview[0]->from.’</span>’;
$output.= ‘<span class=”date”>on ‘.$overview[0]->date.’</span>’;
$output.= ‘</div>’;
$output.= ‘<div class=”body”>’.$message.’</div>’;
} //end of for loop
echo $output;
} //end of if statement
/* close the connection */
imap_close($inbox);
?>
</body>
</html>