Ver Mensaje Individual
  #3 (permalink)  
Antiguo 25/05/2011, 15:40
alex_13
 
Fecha de Ingreso: mayo-2011
Mensajes: 2
Antigüedad: 12 años, 11 meses
Puntos: 0
Pregunta Respuesta: ¿¿Cómo acceder a los ficheros del correo??

He estado investigando sobre este tema y hasta ahora solo he podido acceder a los correos de una determinada carpeta y a los adjuntos de cada uno de estos correos, pero aun no se como poder bajarlos.

Aqui les presento el codigo, en cual cuando debiera descargar el adjunto de un correo lo que hace es salir el error:

"Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\correo\imap.php:11) in C:\xampp\htdocs\correo\correo_imap.php on line 140"

alquien sabe que esta ocurriendo en este caso??.

Archivo correo_imap.php
Código __default:
Ver original
  1. [HIGHLIGHT="PHP"]
  2. <?php
  3.  
  4.  
  5. include("imap.php");
  6.  
  7. $message=$_GET['num'];
  8.  
  9. //if($mensaje->parts[1]->ifdisposition = "1" and $mensaje->parts[1]->disposition = "attachment"){Hacer lo de attachments}
  10. $imap = imap_open("{imap.uci.cu:993/imap/ssl}Yanelis", "[email protected]", "2011.porti") or die("No Se Pudo Conectar Al Servidor:" . imap_last_error());
  11. //Escoger un mensaje especifico
  12.  
  13. //Mostrar todas las propiedades del mensaje
  14. //echo "<pre>\n\n";
  15. //print_r(imap_fetchstructure($imap, $message));
  16. //echo "\n\n</pre>";
  17.  
  18. $mensaje = imap_fetchstructure($imap, $message);
  19. $partes = count($mensaje->parts);
  20. $partesreales = $partes-1;
  21. if(!$partes)
  22. {
  23. echo "El Mensaje No Tiene Archivos Adjuntos<br>";
  24. }
  25. echo "$partes<br>";
  26. echo "El Mensaje Tiene $partesreales Archivos Adjunto(s)!<br>";
  27. echo "Detalles del Archivo Adjunto".$message."<br>";
  28.  
  29. $analisar = $mensaje->parts[1];
  30. //echo "Este es un Array : $analisar->parameters<br>"; //Array
  31.  
  32. $seguimos = $analisar->dparameters[0];
  33.  
  34. echo "Nombre Del Archivo Adjunto: $seguimos->value<br>";
  35.  
  36. $final = $mensaje->parts[1]->dparameters[0]->value;
  37.  
  38. $final = trim($final, "=,?"); //Elimina ? y = del inicio o final del nombre.
  39.  
  40. echo "Nombre Del Archivo Adjunto: $final<br>";
  41.  
  42. $tamano = $mensaje->parts[1]->bytes;
  43. $tipo = $mensaje->parts[1]->subtype;
  44.  
  45. echo "El Archivo Adjunto Tiene ".$tamano ."bytes!<br>";
  46. echo "El Archivo Adjunto es un Archivo ".$tipo."<br>";
  47.  
  48.  
  49. $attachments = array();
  50.  
  51. if(isset($mensaje->parts) && count($mensaje->parts))
  52. {
  53. for($i = 0; $i < count($mensaje->parts); $i++)
  54. {
  55. $attachments[$i] = array('is_attachment' => false,'filename' => '','name' => '','attachment' => '');
  56.  
  57. if($mensaje->parts[$i]->ifdparameters)
  58. {
  59. foreach($mensaje->parts[$i]->dparameters as $object)
  60. {
  61. if(strtolower($object->attribute) == 'filename')
  62. {
  63. $attachments[$i]['is_attachment'] = true;
  64. $attachments[$i]['filename'] = $object->value;
  65. }
  66. }
  67. }
  68.  
  69. if($mensaje->parts[$i]->ifparameters)
  70. {
  71. foreach($mensaje->parts[$i]->parameters as $object)
  72. {
  73. if(strtolower($object->attribute) == 'name')
  74. {
  75. $attachments[$i]['is_attachment'] = true;
  76. $attachments[$i]['name'] = $object->value;
  77. }
  78. }
  79. }
  80.  
  81. if($attachments[$i]['is_attachment'])
  82. {
  83. $attachments[$i]['attachment'] = imap_fetchbody($imap, $message, $i+1);
  84.  
  85. if($mensaje->parts[$i]->encoding == 3)
  86. {
  87. // 3 = BASE64
  88. $attachments[$i]['attachment'] = base64_decode($attachments[$i]['attachment']);
  89. }  
  90. elseif($mensaje->parts[$i]->encoding == 4)
  91. {
  92. // 4 = QUOTED-PRINTABLE
  93. $attachments[$i]['attachment'] = quoted_printable_decode($attachments[$i]['attachment']);
  94. }  
  95. }
  96. }  
  97. }
  98.  
  99. imap_close($imap);
  100.  
  101.  
  102.  
  103. $carpeta="C:/test/";
  104.  
  105. $file = $carpeta.$_GET['num']; 
  106.  
  107. $name = $file.".rar";
  108.  
  109.  
  110. header("Content-Transfer-Encoding: binary");   
  111. header("Content-type: application/pdf");
  112. header("Content-Disposition: attachment; filename=$name");
  113. header("Content-Length: ".filesize($file));
  114. ?>
[/HIGHLIGHT]


Archivo imap.php
Código __default:
Ver original
  1. [HIGHLIGHT="PHP"]
  2.  
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <title>Chequear cuenta de correo</title>
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  7. <link href="imap_css.css" rel="stylesheet" type="text/css" media="all" />
  8.  
  9. </head>
  10. <body>
  11. <h1 class="titulo"> Webmail </h1>
  12. <?php
  13. $imap = imap_open ("{imap.uci.cu:993/imap/ssl}Yanelis", "[email protected]", "2011.porti") or die("No Se Pudo Conectar Al Servidor:" . imap_last_error());
  14. $checar = imap_check($imap);
  15.  
  16. // Detalles generales de todos los mensajes del usuario.
  17. $resultados = imap_fetch_overview($imap,"1:{$checar->Nmsgs}",0);
  18. // Ordenamos los mensajes arriba los ms nuevos y abajo los ms antiguos
  19. krsort($resultados);
  20. $cont = 0;
  21.  
  22. // Informacion del mailbox
  23. $check = imap_mailboxmsginfo($imap);
  24.  
  25. echo "<div class='estadisticas'>";
  26. if ($check) {
  27. echo "Fecha: " . $check->Date . "<br/>" ;
  28. //echo "Driver: " . $check->Driver . "<br />\n" ;
  29. //echo "Mailbox: " . $check->Mailbox . "<br />\n" ;
  30. echo "Total Mensajes: $check->Nmsgs | Sin Leer: $check->Unread | Recientes: $check->Recent | Eliminados: $check->Deleted <br/>";
  31. echo "Tamao buzn: " . $check->Size . "<br/><br/>" ;
  32. } else {
  33. echo "imap_check() failed: " . imap_last_error() . "<br />\n";
  34. }
  35. echo "</div>";
  36.  
  37. // MOSTRAMOS EL MENSAJE
  38. echo "-------------------------------------------------------<br />";
  39. if (isset($_GET['num'])){
  40. $num_mensaje=$_GET['num'];
  41. echo "Mostrando cuerpo del mensaje #$num_mensaje<br/>";
  42. $cont=0;
  43. foreach ($resultados as $detalles) {
  44. $cont = $cont + 1;
  45. if ($cont == $num_mensaje){
  46. $asunto=$detalles->subject;
  47. echo "<p class='asunto'>$asunto</p>";}
  48. }
  49.  
  50. $section = 1;
  51. $mensaje = imap_fetchbody($imap, $num_mensaje, $section);
  52. echo nl2br(strip_tags($mensaje,'<p>')); // Util para los mensajes HTML, los transforma en texto plano
  53.  
  54. }else{
  55. echo "Mensaje no encontrado<br/>";
  56. }
  57. echo "<br />-------------------------------------------------------<br />";
  58. ?>
  59. <table class='tabla1'>
  60. <thead>
  61. <tr>
  62. <th scope="col" title="Mensaje">Msj</th>
  63. <th scope="col" title="Remitente">Remitente</th>
  64. <th scope="col" title="Asunto">Asunto</th>
  65. <th scope="col" title="Tamao">Tamao</th>
  66. <th scope="col" title="Fecha">Fecha</th>
  67. <th scope="col" title="Leido">Leido</th>
  68. </tr>
  69. </thead>
  70. <?php
  71. //$i=0;
  72. foreach ($resultados as $detalles) {
  73. echo "<tr>";
  74. //echo "Para: $detalles->to <br>";
  75.  
  76. // Ponemos 'Sin asunto' en caso que no tenga.
  77. if ($detalles->subject == ''){$subject='Sin asunto';}
  78. else{
  79. //Evita asuntos tipo =?ISO-8859-1?Q?B=F8lla?=
  80. $subject = utf8_decode(imap_utf8($detalles->subject));
  81. }
  82. $from = utf8_decode(imap_utf8($detalles->from));
  83.  
  84. echo "<td><b>#$detalles->msgno</b></td>";
  85. echo "<td><b>$from</b></td>";
  86.  
  87. echo "<td><a href='correo_imap.php?num=$detalles->msgno'><b>$subject</b></a></td>";
  88.  
  89.  
  90. echo "<td><b>$detalles->size bytes</b></td>";
  91. echo "<td><b>$detalles->date</b></td>";
  92. if($detalles->seen == "0") {
  93. echo "<td><b>Sin leer</b></td>";
  94. $cont = $cont + 1;
  95. } else {
  96. echo "<td>Leido</td>";
  97. }
  98.  
  99.  
  100. //$servidorenvia = strstr($detalles->message_id, '@');
  101. //echo "Dominio Que Envia: $servidorenvia<br><hr>";
  102. echo "</tr>";
  103.  
  104. // $i=$i+1;
  105. // $mi_array=array($i=>$detalles->msgno,$from,$subject,$detalles->size,$detalles->date);
  106. }
  107. echo "</table>";
  108.  
  109. //foreach ($mi_array as $indice=>$actual)
  110. // echo $actual . "<br>";
  111.  
  112.  
  113. imap_close($imap);
  114. ?>
  115. <div id="footer"> <p>Tratamiento de correo via IMAP </p></div>
  116. </body>
  117. </html>
[/HIGHLIGHT]