PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : ??? imap_fetchstructure ???


ervin
11.06.2002, 19:38
Servus ..... Hab mal ne Frage an die freaks ....
Mails mit Attatchment zu verschicken ist ja an sich mein Problem ....
Wie kann ich aber aus einer Mail die ich per PHP vom pop3 - server gesaugt habe diesen Anhang wieder rausholen ....
z.b. ein Bild .... oder einen Text ....
Habe zu diesem Thema zwar einen netten script entdeckt ....
Dann wiess ich was es für ein Document ist .... wie es codiert ist etc ..... ICH WEISS ABER NICHT WAS ICH ENCODEN MUSS:

Welchen teil des Objektes $This_Part???



Währe cool wenn einer mir wenichstens ne ordentliche dokumentation (NICHT DIE ORGINAM PHP) schicken könnte ....

THX
M:-)sli



Script Anhang:

function DisectThisPart($this_part, $part_no) {
if ($this_part->ifdisposition) {
// See if it has a disposition
// The only thing I know of that this
// would be used for would be an attachment
// Lets check anyway
if ($this_part->disposition == "ATTACHMENT") {
// If it is an attachment, then we let people download it

// First see if they sent a filename
$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;
}
}

// You could give a link to download the attachment here....
} else {
// disposition can also be used for images in HTML (Inline)
}
} else {
// Not an attachment, lets see what this part is...
switch ($this_part->type) {
case TYPETEXT:
$mime_type = "text";
break;
case TYPEMULTIPART:
$mime_type = "multipart";
// Hey, why not use this function to deal with all the parts
// of this multipart part :)
for ($i = 0; $i < count($this_part->parts); $i++) {
if ($part_no != "") {
$part_no = $part_no.".";
}
for ($i = 0; $i < count($this_part->parts); $i++) {
DisectThisPart($this_part->parts[$i], $part_no.($i + 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";
// hmmm....
}
$full_mime_type = $mime_type."/".$this_part->subtype;

// Decide what you what to do with this part
// If you want to show it, figure out the encoding and echo away
switch ($this_part->encoding) {
case ENCBASE64:
// use imap_base64 to decode
break;
case ENCQUOTEDPRINTABLE:
// use imap_qprint to decode
break;
case ENCOTHER:
// not sure if this needs decoding at all
break;
default:
// it is either not encoded or we don't know about it
}
}
}

I haven't tested this code because I do it a little differently in the client that I am writing, so there could be mistakes, but the general flow of the function is good. All you have to do to start examining the entire message is send it the first part. How to call this function:

$msg_struct = imap_fetchstructure($mconn, $msg_no);

DisectThisPart($msg_struct, "");


:) :)