Descargar archivos adjuntos con IMAP y PHP

2,386 views
Skip to first unread message

Elí Daván Palma

unread,
May 7, 2012, 7:19:55 PM5/7/12
to ida...@googlegroups.com
Comunidad IDATUX buenas tardes.
muchas beses ne sacaron de apuros espero que esta ves también puedan ayudarme.

Quiero descargar los archivos adjuntos que hay en un correo, e probado todas las opciones que encontré en la web y nada, y por eso acudo a ustedes.

este es el código que mas se acerco a la meta

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <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"> Leer Emails </h1>
         
        <?
// variables de conexión

        $host = '{mail.dominio.com.pe/notls/imap4}INBOX'; //Host to connect
        $user = 'sop...@dominio.com.pe';
        $pass = '1234567';
      

// coneccion
        $imap = @imap_open($host, $user, $pass) or die("No se puede conectar: " . imap_last_error());

        
        
        // busco todos los menajes que coincidan con "asunto" 
    $some = imap_search($imap, 'SUBJECT "TICK-#00225"');
    
    
    //el ultimo de los coinciden
    $indice = 0;
    for ($index = 0; $index < count($some); $index++) {
        $indice = $some[$index];
    }
        
        $resultados = imap_fetch_overview($imap, $indice, 0);

        ?>
        <table class='tabla1'>
            <thead>
                    <tr>
                    <th scope="col" title="Para">Para</th>
                            <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="Cuerpo">Cuerpo Mensaje</th>                    
                            <th scope="col" title="Tamaño">Tamaño</th>
                            <th scope="col" title="Fecha">Fecha</th>
                            <th scope="col" title="Adjunto">Adjunto</th>
                            <th scope="col" title="Leido">Leido</th>
                        </tr>
            </thead>    
            <?
            foreach ($resultados as $detalles) {
                echo "<tr>";

                if ($detalles->subject == '') {
                    $subject = 'Sin asunto';
                } else {
                    $subject = utf8_decode(imap_utf8($detalles->subject));
                }
                $from = utf8_decode(imap_utf8($detalles->from));
                $msg_structure = imap_fetchstructure($imap, $detalles->msgno);
                echo "<td><b>#$detalles->to</b></td>";
                echo "<td><b>#$detalles->msgno</b></td>";
                echo "<td><b>$from</b></td>";
                echo "<td><a href='leermails2_1.php?num=$detalles->msgno'><b>$subject</b></a></td>";
                $section = 1;
                $mensaje = imap_fetchbody($imap, $indice, $section);

                //echo base64_decode(imap_fetchbody($imap, 3, 3));
//echo nl2br(strip_tags("<td><b> $mensaje, '<p>'</b></td>"));
                echo "<td><b> $mensaje, '<p>'</b></td>";
                echo "<td><b>$detalles->size bytes</b></td>";
                echo "<td><b>$detalles->date</b></td>";
                if ($msg_structure->bytes == "") {
                    echo "<td><b>No</b></td>";
                } else {
                    echo "<td><b>Sí</b></td>";
                }
                if ($detalles->seen == "0") {
                    echo "<td><b>Sin leer</b></td>";
                    $cont = $cont + 1;
                } else {
                    echo "<td>Leido</td>";
                }
                echo "</tr>";
            }
            imap_close($imap);
            ?>
        </table>
    </body>
</html>

encontré otros códigos en estas web pero no he podido implementarlo


espero me puedan dar una LUZ como dijo mi amigo Omar

--
Atentamente,
__________________________________
Daván Palma Elì
Técnico en Computación e informática

Reply all
Reply to author
Forward
0 new messages