1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| <?php
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'xxx@gmail.com';
$password = 'xxxx';
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to server: ' . imap_last_error());
$emails = imap_search($inbox,'ALL');
if($emails) {
$output = '';
rsort($emails);
$email_number = $_GET['idmail'];
$overview = imap_fetch_overview($inbox,$email_number,1);
$structure = imap_fetchstructure($inbox, $email_number,FT_UID);
if(isset($structure->parts) && is_array($structure->parts) && isset($structure->parts[1])) {
$part = $structure->parts[1];
$message = imap_fetchbody($inbox,$email_number,2,FT_UID);
if($part->encoding == 3) {
$message = imap_base64($message);
} else if($part->encoding == 1) {
$message = imap_8bit($message);
} else {
$message = imap_qprint($message);
}
}
$datefr = utf8_decode(imap_utf8($overview[0]->udate));
$timefr = date("d M Y", $datefr);
$heurefr = date("H", $datefr);
$minutefr= date("i", $datefr);
$timefr = str_replace( "Jan", 'Janvier', $timefr );
$timefr = str_replace( "Feb", 'Février', $timefr );
$timefr = str_replace( "Mar", 'Mars', $timefr );
$timefr = str_replace( "Apr", 'Avril', $timefr );
$timefr = str_replace( "May", 'Mai', $timefr );
$timefr = str_replace( "Jun", 'Juin', $timefr );
$timefr = str_replace( "Jul", 'Juillet', $timefr );
$timefr = str_replace( "Aug", 'Août', $timefr );
$timefr = str_replace( "Sep", 'Septembre', $timefr );
$timefr = str_replace( "Oct", 'Octobre', $timefr );
$timefr = str_replace( "Nov", 'Novembre', $timefr );
$timefr = str_replace( "Dec", 'Décembre', $timefr );
$output.= '<div class="toggle'.($overview[0]->seen ? 'read' : 'unread').'">';
$output.= '<span class="from">De: '.utf8_decode(imap_utf8($overview[0]->from)).'</span>';
$output.= '<span class="date">Le '.$timefr.' à '.$heurefr.' h '.$minutefr.'</span>';
$output.= '<br /><span class="subject">Sujet: '.imap_utf8($overview[0]->subject).'</span> ';
$output.= '</div>';
$output.= '<div class="body">'.$message.'</div><hr />';
echo $output;
}
imap_close($inbox);
?> |
Partager