Jump to content

IMAP : Fatal error: Cannot use object of type stdClass as array


margus21

Recommended Posts

hi,

 

very strange issue. when I create test e-mail or I will forward the specific e-mail, the script works correctly - saves attachment into server disk.

now, when I configure to check another mailbox, it gives me error:

 

Num Messages 11

 

Fatal error: Cannot use object of type stdClass as array in /test/emailattach/index.php on line 34

 

index.php:

 

<?php

$mbox = imap_open("{mail.server.com:143}", "email@email", "XXX") or die('Cannot connect to mail: ' . imap_last_error());

// make connection with mailbox and check # messages
if ($hdr = imap_check($mbox)) {
echo "Num Messages " . $hdr->Nmsgs ."\n\n<br><br>";
$msgCount = $hdr->Nmsgs;
} else { echo "failed"; }
$overview=imap_fetch_overview($mbox,"1:$msgCount",0);
$size=sizeof($overview);


// get message info
for($i=$size-1;$i>=0;$i--)
{
$val=$overview[$i];
$msg=$val->msgno;
$from=$val->from;
$date=$val->date;
$subj=$val->subject;
$seen=$val->seen;
$from = ereg_replace("\"","",$from);


// Check for attachements and store them
$struct = imap_fetchstructure($mbox,$msg);
$contentParts = count($struct->parts);
if ($contentParts >= 2) {
for ($ix=2;$ix<=$contentParts;$ix++) {
$att[$ix-2] = imap_bodystruct($mbox,$msg,$ix);
}
for ($k=0;$k<sizeof($att);$k++) {
if ($att[$k]->parameters[0]->value == "us-ascii" ||
$att[$k]->parameters[0]->value == "US-ASCII") {
if ($att[$k]->parameters[1]->value != "") {
$FileName[$k] = $att[$k]->parameters[1]->value;
$FileType[$k] = strrev(substr(strrev($FileName[$k]),0,4));
}
} elseif ($att[$k]->parameters[0]->value != "iso-8859-1" &&
$att[$k]->parameters[0]->value != "ISO-8859-1") {
$FileName[$k] = $att[$k]->parameters[0]->value;
$FileType[$k] = strrev(substr(strrev($FileName[$k]),0,4));
$fileContent = imap_fetchbody($mbox,$msg,$file+2);
$fileContent = imap_base64($fileContent);


$localfile = fopen("$FileName[$k]","w");
fputs($localfile,$fileContent);
fclose($localfile);
}
}
}
}
imap_close($mbox);
?>

 

Could there be some encoding issue?

 

with thanks,

Margus

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.