Hi,
I am trying to download an attachment with IMAP functions but i have some problems.Please could you see what's srong in my code.
#The main file contains the following lines :
include ("recep_mail.php");
$msg=imap_open("{131.107.2.107/pop3:110}INBOX","","");
$tab = imap_headers($msg);
$size = sizeof($tab);
$i=0;
while ($i < $taille) {
$fetch=imap_fetchstructure($msg,$i);
dissect_part($fetch, "");
$i++;
}
imap_close($msg);
#The recep_mail file is :
function dissect_part($this_part, $part_no) {
if ($this_part->ifdisposition) {
// There is an attachment
if ($this_part->disposition == "ATTACHMENT") {
// Is there a file name ?
$att_name = "unknown";
for ($lcv = 0; $lcv < count($this_part->parameters); $lcv++) {
$param = $this_part->parameters[$lcv];
if ($param->attribute == "NAME") {
$att_name = $param->value;
break;
}
}
header("Content-Type: application/octet-stream");
header("Content-Disposition: ATTACHMENT; filename=$att_name");
// Download
}
else {
// INLINE ????
}
}
else {
// No attachment ???
switch ($this_part->type) {
case TYPETEXT:
$mime_type = "text";
break;
case TYPEMULTIPART:
$mime_type = "multipart";
for ($j = 0; $j < count($this_part->parts); $j++) {
if ($part_no != "") {
$part_no = $part_no.".";
}
for ($j = 0; $j < count($this_part->parts); $j++) {
dissect_part($this_part->parts[$j], $part_no.($j + 1));
}
}
break;
case TYPEMESSAGE:
$mime_type = "message";
break;
case TYPEAPPLICATION:
$mime_type = "application";
break;
case TYPEAUDIO:
$mime_type = "audio";
break;
case TYPEIMAGE:
$mime_type = "image";
break;
case TYPEVIDEO:
$mime_type = "video";
break;
case TYPEMODEL:
$mime_type = "model";
break;
default:
$mime_type = "unknown";
}
$full_mime_type = $mime_type."/".$this_part->subtype;
switch ($this_part->encoding) {
case ENCBASE64:
// use imap_base64
break;
case ENCQUOTEDPRINTABLE:
// use imap_qprint to decode
break;
case ENCOTHER:
// no decode
break;
default:
//????
}
}
}
Thank you !