note 27396 added to function.imap-fetchstructure
| From: | paradise at ml75 dot com | Date: | Wed, 04 Dec 2002 13:40:47 +0000 |
| Subject: | note 27396 added to function.imap-fetchstructure | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-40340@lists.php.net to get a copy of this message | ||
I'm using freeBSD and had lots of problems with all functions/mail applications i could find on
the net...
So i'm writing my own now..
Most of the stuff works fine now.. but i'm still working on the chooser to select the best part
to show. (plain or HTML).
The #1 problem is that most functions give the wrong ID numbers beck to fetch the body.
Here's a sollution to that problem.. :P
// Debug function.. always handy until it's 100% completed..
$attachments = array(); $dispos=0;
$debug=true;
function doDebug($msg){
global $debug, $debug_depth, $dispos;
if($debug){
for($y = 0; $y < $debug_depth; $y++)
echo(" ");
if($dispos == 0) echo($msg."<br/>"); else
echo("<i>".$msg."</i><br/>");
}
}
function Check_Part($part,$id){
global $attachments, $debug, $debug_depth, $dispos; $ans=sizeof($attachments);
doDebug("+Checking part $id");
$debug_depth++;
doDebug("Parttype=".$part->type ."/". mimetype($part->type)
."/". $part->subtype);
if($part->ifdisposition){ $dispos++; doDebug("<b>Disposition</b>"); }
if($part->ifdescription){
doDebug("<b>Description=".$part->description."</b>"); }
switch($part->type){
case 1: if((strtolower($part->subtype) == "mixed")
or (strtolower($part->subtype) == "alternative")
or (strtolower($part->subtype) == "related")) break;
default: $an = sizeof($attachments);
if($part->ifdparameters){
$dpara = $part->dparameters;
for ($v=0;$v<sizeof($dpara);$v++){
if (eregi("filename", $dpara[$v]->attribute))
$fname = $dpara[$v]->value;}
}
if($part->ifparameters){
if(empty($fname)){
$para = $part->parameters;
for ($v=0;$v<sizeof($para);$v++){
if (eregi("name", $para[$v]->attribute)) $fname =
$para[$v]->value;
}
}
}
if(empty($fname))$fname = "Onbekend";
$attachments[$an]->id = ($an+1);
$attachments[$an]->part = $id;
$attachments[$an]->filename = $fname;
$attachments[$an]->type=$part->type;
$attachments[$an]->subtype=$part->subtype;
$attachments[$an]->dispos=$dispos;
$attachments[$an]->size=$part->bytes;
doDebug("Filename=".$attachments[$an]->filename); break;
}
for($x = 0; $x < count($part->parts); $x++){
Check_Part($part->parts[$x], $id.".".($x+1));
}
doDebug("Dit deel had iets nuttigs.");
if($part->ifdisposition) $dispos--;
$debug_depth--;
doDebug("-End of part $id");
}
function decode_mail($mbox, $msg){
global $attachments, $debug, $debug_depth;
doDebug("+Decoding message $msg"); $debug_depth++;
$obj = imap_fetchstructure($mbox, $msg, FT_UID); $moet_werken=true; $id=1;
while($moet_werken){
Check_Part($obj, $id);
$moet_werken=false;
}
$debug_depth--; doDebug("-End of message $msg");
}
Now to get this to work..
Decode_Mail([Mailbox connection], [Message Number]);
this is the outpu attachment array..
1--1.1.1--Onbekend--0--PLAIN--0--31
2--1.1.2--Onbekend--0--HTML--0--29
3--1.2--Beschrijving Nieuw E.doc--3--MSWORD--1--613718
--------------------------------------
PS.. "Onbekend" is dutch for "Unknown".
Good luck.
Paradise (www.ml75.nl)
--
http://www.php.net/manual/en/function.imap-fetchstructure.php
http://master.php.net/manage/user-notes.php?action=edit+27396
http://master.php.net/manage/user-notes.php?action=delete+27396
http://master.php.net/manage/user-notes.php?action=reject+27396