<?php
// http://davidwalsh.name/gmail-php-imap
include("mail.php");
include("debuglib.php");
?>



<head>
<style type="text/css">
		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>
</head>

top






<?php 



/* connect to gmail */
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'tcga00@gmail.com';
$password = 'Peru.995';

/* try to connect */
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());


print("INBOX: ===========================================<br />");
print_a($inbox);


// grab emails 
$emails = imap_search($inbox, 'ALL');

print("START EMAILS: ===========================================<br />");

print_a($emails);

print("END EMAILS: ===========================================<br />");


if($emails) 
{
    rsort($emails);

	// for every email... 
	foreach($emails as $email_number) 
	{
        echo '<br />EMAIL_NUMBER <hr />';
        print_a($email_number);

        // get information specific to this email
		$overview = imap_fetch_overview($inbox, $email_number, 0);
		$message = imap_fetchbody($inbox, $email_number, 2);

        $structure = imap_fetchstructure($inbox, $email_number);

        $hederinfo = imap_headerinfo($inbox, $email_number);

        echo '<br />OVERVIEW <hr />';
        print_a($overview);
        echo '<hr />';

        echo '<br />HEADERINFO<hr />';
        print_a($hederinfo);
        echo '<hr />';

        echo '<br />MESSAGE <hr />';
        print_a($message);
        echo '<hr />';
        echo '<br />STRUCTURE <hr />';
        print_a($structure);
        echo '<hr />';
        echo '<hr />';
        echo '<hr />';
        echo '<hr />';

		// output the email header information 
//		$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>';
	}

	//echo $output;
} 












/*
// if emails are returned, cycle through each... 
if($emails) {
	
	// begin output var 
	$output = '';
	
	// put the newest emails on top 
	rsort($emails);
	
	// for every email... 
	foreach($emails as $email_number) {
		
		// get information specific to this email 
		$overview = imap_fetch_overview($inbox,$email_number,0);
		$message = imap_fetchbody($inbox,$email_number,2);
		
		// output the email header information 
		$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 the email body 
		$output.= '<div class="body">'.$message.'</div>';
	}
	
	echo $output;
} 
*/

// print_a($inbox);
show_vars();

// close the connection 
imap_close($inbox);

?>
