Despues de investigar en el tema de IMAP he conseguido hacer alguna cosa que otra, faltan pocas cosas para darme por satisfecho. Me gustaría que entre todos sacasemos adelante estas partes.
Actualmente, el script se conecta a GMAIL vía IMAP y te lista todos los mensajes que tienes, marcandotelos si han sido leidos o no.
Dejo el código, funciona 100%
PHP
Código PHP:
Ver original
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Chequear cuenta de correo</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link href="imap_css.css" rel="stylesheet" type="text/css" media="all" /> </head> <body> <h1 class="titulo"> Webmail BETA </h1> <? $imap = imap_open ("{imap.gmail.com:993/imap/ssl}INBOX", "[email protected]", "PASS") or die("No Se Pudo Conectar Al Servidor:" . imap_last_error()); // Detalles generales de todos los mensajes del usuario. // Ordenamos los mensajes arriba los más nuevos y abajo los más antiguos $cont = 0; // Informacion del mailbox echo "<div class='estadisticas'>"; if ($check) { //echo "Driver: " . $check->Driver . "<br />\n" ; //echo "Mailbox: " . $check->Mailbox . "<br />\n" ; echo "Total Mensajes: $check->Nmsgs | Sin Leer: $check->Unread | Recientes: $check->Recent | Eliminados: $check->Deleted <br/>"; echo "Tamaño buzón: " . $check->Size . "<br/><br/>" ; } else { } echo "</div>"; // MOSTRAMOS EL MENSAJE echo "-------------------------------------------------------<br />"; $num_mensaje=$_GET['num']; echo "Mostrando cuerpo del mensaje #$num_mensaje<br/>"; $cont=0; foreach ($resultados as $detalles) { $cont = $cont + 1; if ($cont == $num_mensaje){ $asunto=$detalles->subject; echo "<p class='asunto'>$asunto</p>";} } $section = 1; echo nl2br(strip_tags($mensaje,'<p>')); // Util para los mensajes HTML, los transforma en texto plano }else{ echo "Mensaje no encontrado<br/>"; } echo "<br />-------------------------------------------------------<br />"; ?> <table class='tabla1'> <thead> <tr> <th scope="col" title="Mensaje">Msj</th> <th scope="col" title="Remitente">Remitente</th> <th scope="col" title="Asunto">Asunto</th> <th scope="col" title="Tamaño">Tamaño</th> <th scope="col" title="Fecha">Fecha</th> <th scope="col" title="Leido">Leido</th> </tr> </thead> <? //$i=0; foreach ($resultados as $detalles) { echo "<tr>"; //echo "Para: $detalles->to <br>"; // Ponemos 'Sin asunto' en caso que no tenga. if ($detalles->subject == ''){$subject='Sin asunto';} else{ //Evita asuntos tipo =?ISO-8859-1?Q?B=F8lla?= } echo "<td><b>#$detalles->msgno</b></td>"; echo "<td><b>$from</b></td>"; echo "<td><a href='correo_imap.php?num=$detalles->msgno'><b>$subject</b></a></td>"; echo "<td><b>$detalles->size bytes</b></td>"; echo "<td><b>$detalles->date</b></td>"; if($detalles->seen == "0") { echo "<td><b>Sin leer</b></td>"; $cont = $cont + 1; } else { echo "<td>Leido</td>"; } //$servidorenvia = strstr($detalles->message_id, '@'); //echo "Dominio Que Envia: $servidorenvia<br><hr>"; echo "</tr>"; // $i=$i+1; // $mi_array=array($i=>$detalles->msgno,$from,$subject,$detalles->size,$detalles->date); } echo "</table>"; //foreach ($mi_array as $indice=>$actual) // echo $actual . "<br>"; ?> <div id="footer"> <p>Tratamiento de correo via IMAP - BETA 1.0</p></div> </body> </html>
CSS (imap_css.css)
Código CSS:
Ver original
/* Hoja de estilo */ /* ESTRUCTURA BASICA -------------------------------------------*/ html,body {font-size: 1em;} body { color: #333; background-color: #fff; height:100%; width: 95%; text-align: left; min-width:850px; margin: 2em auto; padding: 0; } #footer { color: #666; background:#eee; border: 1px solid #e5e5e5; border-width: 0 2px 2px 0; text-align:center; padding-top:5px; font-family:Arial; font-weight:bold; margin-top:15px; } a {text-decoration:none; color:#333;} a:hover {color:#2BBA82;} /* ESTILO TEXTO ------------------------------------------- */ .titulo{ color:#333; font-size: 1.30em; font-weight:normal; text-align:justify; line-height:20px; padding:0px 5px 5px 20px; margin:0.5em 0 1em; } .asunto{ color:#60B6EF; font-weight:bold; font-size:1.2em; } .estadisticas{ color:#333; font-size: 1em; font-weight:normal; text-align:justify; line-height:20px; padding:0px 5px 5px 20px; font-family:Arial; } /* TABLAS ESTILO ------------------------------------------- */ table,td { border:1px solid #CCC; border-collapse:collapse; font:small/1.4 Verdana, "Tahoma", "Bitstream Vera Sans", Helvetica, sans-serif; } table { border:none; border:1px solid #CCC; width:100%; } thead th, tbody th { background:#fafafb; color:#666; padding:5px 10px; border-left:1px solid #CCC; font-weight:bold; text-align:center; font-size:11px; vertical-align:middle; } tbody th { background:#fafafb; border-top:1px solid #CCC; text-align:left; font-weight:normal; } tbody tr td { padding:5px 10px; color:#666; cursor:pointer; font-size:11px; text-align:center; vertical-align: middle; } tbody tr:hover {background:#F0F7FC;} tbody tr:hover td {background:#F0F7FC;} tfoot td, tfoot th { border-left:none; border-top:1px solid #CCC; padding:4px; background:#FFF url(../imagenes/tablas/foot_bck.gif) repeat; color:#666; } caption { text-align:left; font-size:100%; padding:30px 0 10px 0px; color:#666; font-weight:bold; width:500px; } table a:link {text-decoration:none; color:#60B6EF;} table a:visited {color:#333;} table a:hover {color:#2BBA82;text-decoration:none;} table a:active {color:#60B6EF;}
Quisiera conseguir lo siguiente:
1. Paginar los correos
2. Mostrar bien remitente, asunto, sin interrogante en lugar de acentos
3. Mostrar fecha en formato dd-mm-aaaa hh:mm
4. Saber cómo está escrito el mensaje si UTF-8 o ISO-8859-1 / (texto plano o html)
5. Saber si tiene adjuntos
6. Ver / Descargar correo original
Cada vez que consigamos un punto nuevo iré actualizando este post inicial.
Muchas gracias a todos!
![sonriente](http://static.forosdelweb.com/fdwtheme/images/smilies/smile.png)