Foros del Web » Programando para Internet » PHP »

Problema al tratar adjuntos vía IMAP

Estas en el tema de Problema al tratar adjuntos vía IMAP en el foro de PHP en Foros del Web. Buenas, Sigo dando aprendiendo cosas nuevas al tratar correos por IMAP. Me pasa algo muy raro cuando envío una imagen adjuntada con Thunderbird a mi ...
  #1 (permalink)  
Antiguo 24/10/2009, 04:11
Avatar de neodani  
Fecha de Ingreso: marzo-2007
Mensajes: 1.811
Antigüedad: 17 años, 1 mes
Puntos: 20
Problema al tratar adjuntos vía IMAP

Buenas,

Sigo dando aprendiendo cosas nuevas al tratar correos por IMAP.

Me pasa algo muy raro cuando envío una imagen adjuntada con Thunderbird a mi cuenta de gmail, no me lo detecta como adjunto.
En cambio, si lo envío desde el webmail de gmail adjuntando la imagen, si que me lo detecta como adjunto!!

Esto me provoca desconcierto, porque me estoy dando cuenta que no detecto siempre los adjuntos...

Por ej. código para detectar si el mensaje tiene adjuntos:

El correo enviado desde Thunderbird muestra
More then one part
Inline message has lines


Y el mensaje enviado desde el webmail de gmail muestra
More then one part
Attachment found!Filename: color-palet.PNG


¿Sabéis porque no me detecta el adjunto cuando envío desde Thunderbird? ¿Qué debería modificar para que me lo detectase?

Muchas gracias de antemano!

PD: Siento ser un pesado con el tema IMAP pero me está costando crear un script que contemple esto.


Código php:
Ver original
  1. <?php
  2. $imap = imap_open ("{imap.gmail.com:993/imap/ssl}INBOX", "user", "pass") or die("No Se Pudo Conectar Al Servidor:" . imap_last_error());
  3.  
  4. // delibertely choose a message with an attachment
  5. $message = 18;
  6.  
  7. $info = imap_fetchstructure($imap, $message);
  8.  
  9. // find out how may parts the object has
  10. $numparts = count($info->parts);
  11.  
  12. // find if if multipart message
  13. if ($numparts > 1) {
  14.  
  15.    echo "More then one part<BR>";
  16.    
  17.    foreach ($info->parts as $part) {
  18.  
  19.       if ($part->disposition == "INLINE") {
  20.          // inline message. Show number of lines
  21.      
  22.          printf("Inline message has %s lines<BR>", $part->lines);
  23.      
  24.       } elseif ($part->disposition == "ATTACHMENT") {
  25.          // an attachment
  26.      
  27.          echo "Attachment found!";
  28.          // print out the file name
  29.          echo "Filename: ", $part->dparameters[0]->value;
  30.          
  31.       }
  32.      
  33.    }
  34.    
  35. } else {
  36.    // only one part so get some useful info
  37.    echo "Only one part";
  38. }
  39.  
  40. imap_close($imap);
  41. ?>
  #2 (permalink)  
Antiguo 24/10/2009, 04:31
Avatar de neodani  
Fecha de Ingreso: marzo-2007
Mensajes: 1.811
Antigüedad: 17 años, 1 mes
Puntos: 20
Respuesta: Problema al tratar adjuntos vía IMAP

Cabecera del correo enviado desde el webmail de gmail
Este si dectecta el adjunto.
Código:
Delivered-To: [email protected]
Received: by 10.216.39.6 with SMTP id c6cs15172web;
        Sat, 24 Oct 2009 03:00:46 -0700 (PDT)
Return-Path: <[email protected]>
Received-SPF: pass (google.com: domain of [email protected] designates 10.211.128.14 as permitted sender) client-ip=10.211.128.14;
Authentication-Results: mr.google.com; spf=pass (google.com: domain of [email protected] designates 10.211.128.14 as permitted sender) smtp.mail=[email protected]; dkim=pass header.i=[email protected]
Received: from mr.google.com ([10.211.128.14])
        by 10.211.128.14 with SMTP id f14mr635149ebn.75.1256378445979 (num_hops = 1);
        Sat, 24 Oct 2009 03:00:45 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=gamma;
        h=domainkey-signature:mime-version:received:date:message-id:subject
         :from:to:content-type;
        bh=f/C4vwyqMAdbGjWNcM4VL3lrRun4tlw/FPCk/3uvtKc=;
        b=rGEDf2fV6HiNldg4UyMhHleULEU22xA8D6/wqbo/q0WSjtbbIqUv7/47/YL28Rqeig
         ItYC9RGZw8BtnKsM+te/wGLiqM7CXaEuvJuxeiLW666OH9Q3fVzzjAS6E3HlMysD+Wid
         8tPOq2nUZh4Q7Gv40JU1OGyzA2MmlsCd5rhA8=
DomainKey-Signature: a=rsa-sha1; c=nofws;
        d=gmail.com; s=gamma;
        h=mime-version:date:message-id:subject:from:to:content-type;
        b=fi8eZyHKyaHfZVM7WPj6IqI4K52Bxda12PqlIVI+VuTdQdG+J8dwQZeK4iM3aBNLSg
         C3hk7zD4RGKpP3xLmT01wMmiJ4Klfiue5UAMglY3nHvhTioadlRzBnvIKZYMadUvlT4G
         X96fxvGt+M8/Cv54R6ZXT9ar2C3pHOmxbkQgo=
MIME-Version: 1.0
Received: by 10.211.128.14 with SMTP id f14mr635149ebn.75.1256378445976; Sat, 
	24 Oct 2009 03:00:45 -0700 (PDT)
Date: Sat, 24 Oct 2009 12:00:45 +0200
Message-ID: <[email protected]>
Subject: test imagen1
From: Usuario <[email protected]>
To: [email protected]
Content-Type: multipart/mixed; boundary=00504502cfc1f9d5590476ab665f

--00504502cfc1f9d5590476ab665f
Content-Type: multipart/alternative; boundary=00504502cfc1f9d5510476ab665d

--00504502cfc1f9d5510476ab665d
Content-Type: text/plain; charset=ISO-8859-1

test imagen1

--00504502cfc1f9d5510476ab665d
Content-Type: text/html; charset=ISO-8859-1

test imagen1<br>

--00504502cfc1f9d5510476ab665d--
--00504502cfc1f9d5590476ab665f
Content-Type: image/png; name="color-palet.PNG"
Content-Disposition: attachment; filename="color-palet.PNG"
Content-Transfer-Encoding: base64
X-Attachment-Id: f_g167ad7x0

iVBORw0KGgoAAAANSUhEUgAAAGUAAABkCAIAAAAQQmk9AAAABGdBTUEAALGPC/xhBQAAASZJREFU
eF7t1bENg1AUBEGox126LFeH6eBvcNlYDlcXPDFwf37fy+/8Av97+Z9f4DpPla9FV0gXcK/2OnIv
91p+wTxfni/PV/qETWMeeeRxSiyN88gjj4nMNOaRRx6nxNI4jzzymMhMYx555HFKLI3zyCOPicw0
5pFHHqfE0jiPPPKYyExjHnnkcUosjfPII4+JzDTmkUcep8TSOI888pjITGMeeeRxSiyN88gjj4nM
NOaRRx6nxNI4jzzymMhMYx555HFKLI3zyCOPicw05pFHHqfE0jiPPPKYyExjHnnkcUosjfPII4+J
zDTmkUcep8TSOI888pjITGMeeeRxSiyN88gjj4nMNOaRRx6nxNI4jzzymMhMYx555HFKLI3zyCOP
icw0fgCne8qcMt8NwQAAAABJRU5ErkJggg==
--00504502cfc1f9d5590476ab665f--

Y aquí está el mensaje original enviado desde el Thunderbird. Se aprecian diferencias...


Código:
Received: by 10.216.39.6 with SMTP id c6cs15184web;
        Sat, 24 Oct 2009 03:01:21 -0700 (PDT)
Received: by 10.210.101.1 with SMTP id y1mr6261388ebb.67.1256378481265;
        Sat, 24 Oct 2009 03:01:21 -0700 (PDT)
Return-Path: <[email protected]>
Received: from mail-ew0-f210.google.com (mail-ew0-f210.google.com [209.85.219.210])
        by mx.google.com with ESMTP id 28si406710eye.29.2009.10.24.03.01.20;
        Sat, 24 Oct 2009 03:01:20 -0700 (PDT)
Received-SPF: pass (google.com: domain of [email protected] designates 209.85.219.210 as permitted sender) client-ip=209.85.219.210;
Authentication-Results: mx.google.com; spf=pass (google.com: domain of [email protected] designates 209.85.219.210 as permitted sender) smtp.mail=[email protected]; dkim=pass (test mode) [email protected]
Received: by mail-ew0-f210.google.com with SMTP id 6so6743485ewy.30
        for <[email protected]>; Sat, 24 Oct 2009 03:01:20 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=gamma;
        h=domainkey-signature:received:received:message-id:date:from
         :user-agent:mime-version:to:subject:content-type;
        bh=ljtrYOhb9e5tgGVQbJsu4T9jVCzSlRJ2vnHH4QNrLBQ=;
        b=d1fJIMSpkm1kdyyEEPglUYu3940eEGcHq7VHlL5aZj/mdtz9K1NdF1edaMu9O2Rw91
         sa9O2MEuKyeagZxrd+ByD+rK74c5kCQwbloWs2gqOYzV2ipHYhU4WR1tXoHpyV8mxKWA
         pScpbK9EO63j86bZ7Zue6RGC8cGl9TbJnK6HU=
DomainKey-Signature: a=rsa-sha1; c=nofws;
        d=gmail.com; s=gamma;
        h=message-id:date:from:user-agent:mime-version:to:subject
         :content-type;
        b=EX6c0pYgRN4haJNTq9PdR4Ip7hE7cMzYznEq8QdAhxh4vzTspq6FTAKcJgSv1wawVv
         SnuSrrlrSwrXArSgMeAT3BlrTCxJOPLSHQPribmdeWKVnxLIJ9xwS1/0MsF1nyVp+qfr
         aNSRyzXoON4J8qCwdQjBKclmJS9SyOVwRU2e8=
Received: by 10.210.7.24 with SMTP id 24mr4109661ebg.48.1256378480125;
        Sat, 24 Oct 2009 03:01:20 -0700 (PDT)
Return-Path: <[email protected]>
Received: from ?192.168.1.34? (6.Red-83-59-82.dynamicIP.rima-tde.net [83.59.82.6])
        by mx.google.com with ESMTPS id 10sm2902115eyd.10.2009.10.24.03.01.18
        (version=TLSv1/SSLv3 cipher=RC4-MD5);
        Sat, 24 Oct 2009 03:01:19 -0700 (PDT)
Message-ID: <[email protected]>
Date: Sat, 24 Oct 2009 12:01:20 +0200
From: User<[email protected]>
User-Agent: Thunderbird 2.0.0.23 (Windows/20090812)
MIME-Version: 1.0
To: [email protected]
Subject: test imagen2
Content-Type: multipart/mixed;
 boundary="------------080602000207040202060806"

This is a multi-part message in MIME format.
--------------080602000207040202060806
Content-Type: multipart/alternative;
 boundary="------------020902060809030905030907"


--------------020902060809030905030907
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

test imagen2

--------------020902060809030905030907
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body bgcolor="#ffffff" text="#000000">
<font size="-1"><font face="Arial">test imagen2</font></font>
</body>
</html>

--------------020902060809030905030907--

--------------080602000207040202060806
Content-Type: image/png;
 name="color-palet.PNG"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
 filename="color-palet.PNG"

iVBORw0KGgoAAAANSUhEUgAAAGUAAABkCAIAAAAQQmk9AAAABGdBTUEAALGPC/xhBQAAASZJ
REFUeF7t1bENg1AUBEGox126LFeH6eBvcNlYDlcXPDFwf37fy+/8Av97+Z9f4DpPla9FV0gX
cK/2OnIv91p+wTxfni/PV/qETWMeeeRxSiyN88gjj4nMNOaRRx6nxNI4jzzymMhMYx555HFK
LI3zyCOPicw05pFHHqfE0jiPPPKYyExjHnnkcUosjfPII4+JzDTmkUcep8TSOI888pjITGMe
eeRxSiyN88gjj4nMNOaRRx6nxNI4jzzymMhMYx555HFKLI3zyCOPicw05pFHHqfE0jiPPPKY
yExjHnnkcUosjfPII4+JzDTmkUcep8TSOI888pjITGMeeeRxSiyN88gjj4nMNOaRRx6nxNI4
jzzymMhMYx555HFKLI3zyCOPicw0fgCne8qcMt8NwQAAAABJRU5ErkJggg==
--------------080602000207040202060806--
  #3 (permalink)  
Antiguo 24/10/2009, 04:42
Avatar de neodani  
Fecha de Ingreso: marzo-2007
Mensajes: 1.811
Antigüedad: 17 años, 1 mes
Puntos: 20
Respuesta: Problema al tratar adjuntos vía IMAP

Imprimo el array por si nos puede dar mas pistas...
print_r(imap_fetchstructure($imap, $message));

Desde el webmail de GMAIL
More then one part
Attachment found!Filename: color-palet.PNG


Código php:
Ver original
  1. stdClass Object
  2. (
  3.     [type] => 1
  4.     [encoding] => 0
  5.     [ifsubtype] => 1
  6.     [subtype] => MIXED
  7.     [ifdescription] => 0
  8.     [ifid] => 0
  9.     [ifdisposition] => 0
  10.     [ifdparameters] => 0
  11.     [ifparameters] => 1
  12.     [parameters] => Array
  13.         (
  14.             [0] => stdClass Object
  15.                 (
  16.                     [attribute] => BOUNDARY
  17.                     [value] => 00504502cfc1f9d5590476ab665f
  18.                 )
  19.  
  20.         )
  21.  
  22.     [parts] => Array
  23.         (
  24.             [0] => stdClass Object
  25.                 (
  26.                     [type] => 1
  27.                     [encoding] => 0
  28.                     [ifsubtype] => 1
  29.                     [subtype] => ALTERNATIVE
  30.                     [ifdescription] => 0
  31.                     [ifid] => 0
  32.                     [ifdisposition] => 0
  33.                     [ifdparameters] => 0
  34.                     [ifparameters] => 1
  35.                     [parameters] => Array
  36.                         (
  37.                             [0] => stdClass Object
  38.                                 (
  39.                                     [attribute] => BOUNDARY
  40.                                     [value] => 00504502cfc1f9d5510476ab665d
  41.                                 )
  42.  
  43.                         )
  44.  
  45.                     [parts] => Array
  46.                         (
  47.                             [0] => stdClass Object
  48.                                 (
  49.                                     [type] => 0
  50.                                     [encoding] => 0
  51.                                     [ifsubtype] => 1
  52.                                     [subtype] => PLAIN
  53.                                     [ifdescription] => 0
  54.                                     [ifid] => 0
  55.                                     [lines] => 1
  56.                                     [bytes] => 14
  57.                                     [ifdisposition] => 0
  58.                                     [ifdparameters] => 0
  59.                                     [ifparameters] => 1
  60.                                     [parameters] => Array
  61.                                         (
  62.                                             [0] => stdClass Object
  63.                                                 (
  64.                                                     [attribute] => CHARSET
  65.                                                     [value] => ISO-8859-1
  66.                                                 )
  67.  
  68.                                         )
  69.  
  70.                                 )
  71.  
  72.                             [1] => stdClass Object
  73.                                 (
  74.                                     [type] => 0
  75.                                     [encoding] => 0
  76.                                     [ifsubtype] => 1
  77.                                     [subtype] => HTML
  78.                                     [ifdescription] => 0
  79.                                     [ifid] => 0
  80.                                     [lines] => 1
  81.                                     [bytes] => 18
  82.                                     [ifdisposition] => 0
  83.                                     [ifdparameters] => 0
  84.                                     [ifparameters] => 1
  85.                                     [parameters] => Array
  86.                                         (
  87.                                             [0] => stdClass Object
  88.                                                 (
  89.                                                     [attribute] => CHARSET
  90.                                                     [value] => ISO-8859-1
  91.                                                 )
  92.  
  93.                                         )
  94.  
  95.                                 )
  96.  
  97.                         )
  98.  
  99.                 )
  100.  
  101.             [1] => stdClass Object
  102.                 (
  103.                     [type] => 5
  104.                     [encoding] => 3
  105.                     [ifsubtype] => 1
  106.                     [subtype] => PNG
  107.                     [ifdescription] => 0
  108.                     [ifid] => 0
  109.                     [bytes] => 504
  110.                     [ifdisposition] => 1
  111.                     [disposition] => ATTACHMENT
  112.                     [ifdparameters] => 1
  113.                     [dparameters] => Array
  114.                         (
  115.                             [0] => stdClass Object
  116.                                 (
  117.                                     [attribute] => FILENAME
  118.                                     [value] => color-palet.PNG
  119.                                 )
  120.  
  121.                         )
  122.  
  123.                     [ifparameters] => 1
  124.                     [parameters] => Array
  125.                         (
  126.                             [0] => stdClass Object
  127.                                 (
  128.                                     [attribute] => NAME
  129.                                     [value] => color-palet.PNG
  130.                                 )
  131.  
  132.                         )
  133.  
  134.                 )
  135.  
  136.         )
  137.  
  138. )

A continuación el otro...
  #4 (permalink)  
Antiguo 24/10/2009, 04:42
Avatar de neodani  
Fecha de Ingreso: marzo-2007
Mensajes: 1.811
Antigüedad: 17 años, 1 mes
Puntos: 20
Respuesta: Problema al tratar adjuntos vía IMAP

Desde el Thunderbird
More then one part
Inline message has lines


Código php:
Ver original
  1. stdClass Object
  2. (
  3.     [type] => 1
  4.     [encoding] => 0
  5.     [ifsubtype] => 1
  6.     [subtype] => MIXED
  7.     [ifdescription] => 0
  8.     [ifid] => 0
  9.     [ifdisposition] => 0
  10.     [ifdparameters] => 0
  11.     [ifparameters] => 1
  12.     [parameters] => Array
  13.         (
  14.             [0] => stdClass Object
  15.                 (
  16.                     [attribute] => BOUNDARY
  17.                     [value] => ------------080602000207040202060806
  18.                 )
  19.  
  20.         )
  21.  
  22.     [parts] => Array
  23.         (
  24.             [0] => stdClass Object
  25.                 (
  26.                     [type] => 1
  27.                     [encoding] => 0
  28.                     [ifsubtype] => 1
  29.                     [subtype] => ALTERNATIVE
  30.                     [ifdescription] => 0
  31.                     [ifid] => 0
  32.                     [ifdisposition] => 0
  33.                     [ifdparameters] => 0
  34.                     [ifparameters] => 1
  35.                     [parameters] => Array
  36.                         (
  37.                             [0] => stdClass Object
  38.                                 (
  39.                                     [attribute] => BOUNDARY
  40.                                     [value] => ------------020902060809030905030907
  41.                                 )
  42.  
  43.                         )
  44.  
  45.                     [parts] => Array
  46.                         (
  47.                             [0] => stdClass Object
  48.                                 (
  49.                                     [type] => 0
  50.                                     [encoding] => 0
  51.                                     [ifsubtype] => 1
  52.                                     [subtype] => PLAIN
  53.                                     [ifdescription] => 0
  54.                                     [ifid] => 0
  55.                                     [lines] => 1
  56.                                     [bytes] => 14
  57.                                     [ifdisposition] => 0
  58.                                     [ifdparameters] => 0
  59.                                     [ifparameters] => 1
  60.                                     [parameters] => Array
  61.                                         (
  62.                                             [0] => stdClass Object
  63.                                                 (
  64.                                                     [attribute] => CHARSET
  65.                                                     [value] => ISO-8859-1
  66.                                                 )
  67.  
  68.                                             [1] => stdClass Object
  69.                                                 (
  70.                                                     [attribute] => FORMAT
  71.                                                     [value] => flowed
  72.                                                 )
  73.  
  74.                                         )
  75.  
  76.                                 )
  77.  
  78.                             [1] => stdClass Object
  79.                                 (
  80.                                     [type] => 0
  81.                                     [encoding] => 0
  82.                                     [ifsubtype] => 1
  83.                                     [subtype] => HTML
  84.                                     [ifdescription] => 0
  85.                                     [ifid] => 0
  86.                                     [lines] => 8
  87.                                     [bytes] => 212
  88.                                     [ifdisposition] => 0
  89.                                     [ifdparameters] => 0
  90.                                     [ifparameters] => 1
  91.                                     [parameters] => Array
  92.                                         (
  93.                                             [0] => stdClass Object
  94.                                                 (
  95.                                                     [attribute] => CHARSET
  96.                                                     [value] => ISO-8859-1
  97.                                                 )
  98.  
  99.                                         )
  100.  
  101.                                 )
  102.  
  103.                         )
  104.  
  105.                 )
  106.  
  107.             [1] => stdClass Object
  108.                 (
  109.                     [type] => 5
  110.                     [encoding] => 3
  111.                     [ifsubtype] => 1
  112.                     [subtype] => PNG
  113.                     [ifdescription] => 0
  114.                     [ifid] => 0
  115.                     [bytes] => 504
  116.                     [ifdisposition] => 1
  117.                     [disposition] => INLINE
  118.                     [ifdparameters] => 1
  119.                     [dparameters] => Array
  120.                         (
  121.                             [0] => stdClass Object
  122.                                 (
  123.                                     [attribute] => FILENAME
  124.                                     [value] => color-palet.PNG
  125.                                 )
  126.  
  127.                         )
  128.  
  129.                     [ifparameters] => 1
  130.                     [parameters] => Array
  131.                         (
  132.                             [0] => stdClass Object
  133.                                 (
  134.                                     [attribute] => NAME
  135.                                     [value] => color-palet.PNG
  136.                                 )
  137.  
  138.                         )
  139.  
  140.                 )
  141.  
  142.         )
  143.  
  144. )
  #5 (permalink)  
Antiguo 26/10/2009, 10:15
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 10 meses
Puntos: 2135
Respuesta: Problema al tratar adjuntos vía IMAP

Creo es evidente, uno manda el attachment como inline y el otro como attachment, lo que hace que tu script no lo detecte, vas a tener que tratar los inlines y analizarlos para ver si son realmente attachments o simplemente el mensaje enviado como attachment.

Saludos.
  #6 (permalink)  
Antiguo 27/10/2009, 01:09
Avatar de neodani  
Fecha de Ingreso: marzo-2007
Mensajes: 1.811
Antigüedad: 17 años, 1 mes
Puntos: 20
Respuesta: Problema al tratar adjuntos vía IMAP

Cita:
Iniciado por GatorV Ver Mensaje
Creo es evidente, uno manda el attachment como inline y el otro como attachment, lo que hace que tu script no lo detecte, vas a tener que tratar los inlines y analizarlos para ver si son realmente attachments o simplemente el mensaje enviado como attachment.

Saludos.
Sí, el problema es ese, cómo analizar los mensajes que contienen el attachment como inline.

Dices de analizar cada uno de los inline para ver si son attachments. ¿Existe una forma rotunda de decir que el inline es un attachment?

He visto que hay distintos códigos, si aparece cualquiera de ellos se considera attachtment o podemos discriminar alguno?

Tipo de Body primario
0 text
1 multipart
2 message
3 application
4 audio
5 image
6 video
7 other

Codificaciones de Transferencia
0 7BIT
1 8BIT
2 BINARY
3 BASE64
4 QUOTED-PRINTABLE
5 OTHER

Gracias de antemano!
  #7 (permalink)  
Antiguo 27/10/2009, 08:27
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 10 meses
Puntos: 2135
Respuesta: Problema al tratar adjuntos vía IMAP

Pues creo que todo lo puedes tratar como attachment excepto el 0 y el 2 que son texto, pero es cuestión de que tu analizes eso y lo adaptes a tus requerimientos.

Saludos.
  #8 (permalink)  
Antiguo 27/10/2009, 18:31
 
Fecha de Ingreso: abril-2006
Mensajes: 1.128
Antigüedad: 18 años
Puntos: 33
Respuesta: Problema al tratar adjuntos vía IMAP

Neodani:
Muy interesante tu codigo y cuando se llega a los attachments, hay
sin lugar a dudas problema.
Como tu sabes hay los INLINE que son imagenes, por ejemplo,
que forman el cuerpo del mensaje; y estan los ATTACHMENTS que
son los adjuntos propiamente dicho.
Sin lugar a dudas con esta funcion ->
$mensajeadjunto = imap_fetchstructure($imap, $analisarcorreo);
es que se pueden sacar.
Aqui te pongo lo que yo hago para sacar los INLINE y los
ATTACHMENTS de un correo; me funciona con cualquier
cliente de correo y con gmail.com, hotmail.com, yahoo.com,
aol.com y mi servidor.
Cita:
for($z=0; $z < $partesreales; $z++) {
if(($mensajeadjunto->parts[1]->ifdisposition == "1" && $mensajeadjunto->parts[1]->disposition == "ATTACHMENT")
XOR ($mensajeadjunto->parts[1]->ifdisposition == "1" && $mensajeadjunto->parts[1]->disposition == "INLINE")
XOR ($mensajeadjunto->parts[1]->ifdisposition == "0" && $mensajeadjunto->parts[1]->type != "0")) {
$cantidad = $z + 1;..........................................
Claro esta es una fraccion del codigo y debes analizarla con cuidado y en base
a los relustados que muestras arriba y veras que con ambos clientes sale
como esperado.
Saludos
Franco
  #9 (permalink)  
Antiguo 30/10/2009, 16:26
Avatar de neodani  
Fecha de Ingreso: marzo-2007
Mensajes: 1.811
Antigüedad: 17 años, 1 mes
Puntos: 20
Respuesta: Problema al tratar adjuntos vía IMAP

Cita:
Iniciado por franco190453 Ver Mensaje
Neodani:
Muy interesante tu codigo y cuando se llega a los attachments, hay
sin lugar a dudas problema.
Como tu sabes hay los INLINE que son imagenes, por ejemplo,
que forman el cuerpo del mensaje; y estan los ATTACHMENTS que
son los adjuntos propiamente dicho.
Sin lugar a dudas con esta funcion ->
$mensajeadjunto = imap_fetchstructure($imap, $analisarcorreo);
es que se pueden sacar.
Aqui te pongo lo que yo hago para sacar los INLINE y los
ATTACHMENTS de un correo; me funciona con cualquier
cliente de correo y con gmail.com, hotmail.com, yahoo.com,
aol.com y mi servidor.

Claro esta es una fraccion del codigo y debes analizarla con cuidado y en base
a los relustados que muestras arriba y veras que con ambos clientes sale
como esperado.
Saludos
Franco
Buenas,

No acabo de entender el código ya que... entrará tantas veces en el if como partes tenga el correo.

Si mi variable $numparts es igual que tu $partesreales, la sacas de la misma forma?
$numparts = count($info->parts);

En el siguiente ejemplo, me dice que hay 2 adjuntos y en verdad hay uno. Pero como hay dos partes con tu fragmento de script detecta dos.

Código PHP:
stdClass Object
(
    [
type] => 1
    
[encoding] => 0
    
[ifsubtype] => 1
    
[subtype] => MIXED
    
[ifdescription] => 0
    
[ifid] => 0
    
[ifdisposition] => 0
    
[ifdparameters] => 0
    
[ifparameters] => 1
    
[parameters] => Array
        (
            [
0] => stdClass Object
                
(
                    [
attribute] => BOUNDARY
                    
[value] => =_49f16ff92b161073280b5c7e7d15eca6
                
)

        )

    [
parts] => Array
        (
            [
0] => stdClass Object
                
(
                    [
type] => 0
                    
[encoding] => 4
                    
[ifsubtype] => 1
                    
[subtype] => PLAIN
                    
[ifdescription] => 0
                    
[ifid] => 0
                    
[lines] => 5
                    
[bytes] => 60
                    
[ifdisposition] => 0
                    
[ifdparameters] => 0
                    
[ifparameters] => 1
                    
[parameters] => Array
                        (
                            [
0] => stdClass Object
                                
(
                                    [
attribute] => CHARSET
                                    
[value] => utf-8
                                
)

                        )

                )

            [
1] => stdClass Object
                
(
                    [
type] => 5
                    
[encoding] => 3
                    
[ifsubtype] => 1
                    
[subtype] => PNG
                    
[ifdescription] => 0
                    
[ifid] => 0
                    
[bytes] => 504
                    
[ifdisposition] => 1
                    
[disposition] => ATTACHMENT
                    
[ifdparameters] => 1
                    
[dparameters] => Array
                        (
                            [
0] => stdClass Object
                                
(
                                    [
attribute] => FILENAME
                                    
[value] => color-palet.PNG
                                
)

                        )

                    [
ifparameters] => 1
                    
[parameters] => Array
                        (
                            [
0] => stdClass Object
                                
(
                                    [
attribute] => NAME
                                    
[value] => color-palet.PNG
                                
)

                        )

                )

        )



Un saludo,
  #10 (permalink)  
Antiguo 30/10/2009, 20:33
 
Fecha de Ingreso: abril-2006
Mensajes: 1.128
Antigüedad: 18 años
Puntos: 33
Respuesta: Problema al tratar adjuntos vía IMAP

Neodani:

Cita:
Si mi variable $numparts es igual que tu $partesreales, la sacas de la misma forma?
$numparts = count($info->parts);
SI sale de la misma forma.

Cita:
En el siguiente ejemplo, me dice que hay 2 adjuntos y en verdad hay uno. Pero como hay dos partes con tu fragmento de script detecta dos.
NO mi fragmento de codigo detecta uno solamente, analisalo bien.

Todo eso lo tuve que ir diseñando debido a la forma en que se comportan
los diferentes servidores y clientes de correo.

Saludos
Franco
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 16:04.