html - php - imap_fetchstructure - get exact object position in array -


i printing out structure

$structure = imap_fetchstructure($imap, $email_number); print_r($structure); 

i need inside array , [disposition] tag of inline attachment.

i trying out using:

$inline_attachment = $structure[1]->disposition;  if($inline_attachment == inline){     echo "inline attachment found!!"; }  stdclass object (       [type] => 1       [encoding] => 0       [ifsubtype] => 1       [subtype] => related       [ifdescription] => 0       [ifid] => 0       [ifdisposition] => 0       [ifdparameters] => 0       [ifparameters] => 1       [parameters] => array           (               [0] => stdclass object                   (                       [attribute] => boundary                       [value] => 047d7b624dd8b40cbc05172d65ae                   )            )        [parts] => array           (               [0] => stdclass object                   (                       [type] => 1                       [encoding] => 0                       [ifsubtype] => 1                       [subtype] => alternative                       [ifdescription] => 0                       [ifid] => 0                       [ifdisposition] => 0                       [ifdparameters] => 0                       [ifparameters] => 1                       [parameters] => array                           (                               [0] => stdclass object                                   (                                       [attribute] => boundary                                       [value] => 047d7b624dd8b40cb805172d65ad                                   )                            )                        [parts] => array                           (                               [0] => stdclass object                                   (                                       [type] => 0                                       [encoding] => 0                                       [ifsubtype] => 1                                       [subtype] => plain                                       [ifdescription] => 0                                       [ifid] => 0                                       [lines] => 1                                       [bytes] => 11                                       [ifdisposition] => 0                                       [ifdparameters] => 0                                       [ifparameters] => 1                                       [parameters] => array                                           (                                               [0] => stdclass object                                                   (                                                       [attribute] => charset                                                       [value] => utf-8                                                   )                                            )                                    )                                [1] => stdclass object                                   (                                       [type] => 0                                       [encoding] => 0                                       [ifsubtype] => 1                                       [subtype] => html                                       [ifdescription] => 0                                       [ifid] => 0                                       [lines] => 1                                       [bytes] => 136                                       [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] => jpeg                       [ifdescription] => 0                       [ifid] => 1                       [id] =>                        [bytes] => 25378                       [ifdisposition] => 1                       **[disposition] => inline**                       [ifdparameters] => 1                       [dparameters] => array                           (                               [0] => stdclass object                                   (                                       [attribute] => filename                                       [value] => 1.jpg                                   )                            )                        [ifparameters] => 1                       [parameters] => array                           (                               [0] => stdclass object                                   (                                       [attribute] => name                                       [value] => 1.jpg                                   )                            )                    )            )    ) 

what best way achieve this? , how can understand how move , specific element in array?

echo var_export($structure);              stdclass::__set_state(array(    'type' => 1,    'encoding' => 0,    'ifsubtype' => 1,    'subtype' => 'related',    'ifdescription' => 0,    'ifid' => 0,    'ifdisposition' => 0,    'ifdparameters' => 0,    'ifparameters' => 1,    'parameters' =>    array (     0 =>      stdclass::__set_state(array(        'attribute' => 'boundary',        'value' => '047d7b624dd8b40cbc05172d65ae',     )),   ),    'parts' =>    array (     0 =>      stdclass::__set_state(array(        'type' => 1,        'encoding' => 0,        'ifsubtype' => 1,        'subtype' => 'alternative',        'ifdescription' => 0,        'ifid' => 0,        'ifdisposition' => 0,        'ifdparameters' => 0,        'ifparameters' => 1,        'parameters' =>        array (         0 =>          stdclass::__set_state(array(            'attribute' => 'boundary',            'value' => '047d7b624dd8b40cb805172d65ad',         )),       ),        'parts' =>        array (         0 =>          stdclass::__set_state(array(            'type' => 0,            'encoding' => 0,            'ifsubtype' => 1,            'subtype' => 'plain',            'ifdescription' => 0,            'ifid' => 0,            'lines' => 1,            'bytes' => 11,            'ifdisposition' => 0,            'ifdparameters' => 0,            'ifparameters' => 1,            'parameters' =>            array (             0 =>              stdclass::__set_state(array(                'attribute' => 'charset',                'value' => 'utf-8',             )),           ),         )),         1 =>          stdclass::__set_state(array(            'type' => 0,            'encoding' => 0,            'ifsubtype' => 1,            'subtype' => 'html',            'ifdescription' => 0,            'ifid' => 0,            'lines' => 1,            'bytes' => 136,            'ifdisposition' => 0,            'ifdparameters' => 0,            'ifparameters' => 1,            'parameters' =>            array (             0 =>              stdclass::__set_state(array(                'attribute' => 'charset',                'value' => 'utf-8',             )),           ),         )),       ),     )),     1 =>      stdclass::__set_state(array(        'type' => 5,        'encoding' => 3,        'ifsubtype' => 1,        'subtype' => 'jpeg',        'ifdescription' => 0,        'ifid' => 1,        'id' => '',        'bytes' => 25378,        'ifdisposition' => 1,        'disposition' => 'inline',        'ifdparameters' => 1,        'dparameters' =>        array (         0 =>          stdclass::__set_state(array(            'attribute' => 'filename',            'value' => '1.jpg',         )),       ),        'ifparameters' => 1,        'parameters' =>        array (         0 =>          stdclass::__set_state(array(            'attribute' => 'name',            'value' => '1.jpg',         )),       ),     )),   ), ))    for($i = 0; $i < count($structure->parts); $i++) {  if($structure->parts[$i]->disposition == inline) {  foreach($structure->parts[$i]->dparameters $object) {  $src_cid = $object->value;  }  } }  

using recursive function, can traverse object's $parts arrays check value of ifdisposition == 1, , retrieve dparameters[0]->value value.

this should sufficient started:

function getdispositions($obj) {   // check ifdisposition 1   if (isset($obj->ifdisposition) && $obj->ifdisposition == 1) {     // print disposition     echo "disposition: {$obj->disposition}\n";     // , print first parameter's value     echo "filename: {$obj->dparameters[0]->value}\n";     // may need loop here instead     //foreach ($obj->dparameters $p) {     //  echo $p->value;     //}   }   // if has parts array   if (isset($obj->parts)) {     // loop on each part , call getdispositions()     // function recursively act on each nested part     foreach ($obj->parts $part) {       getdispositions($part);     }      } }  // call function on outer structure getdispositions($structure); 

this print:

disposition: inline filename: 1.jpg 

here demonstration, adding 1 additional filename prints 2 dispositions , filename values: http://codepad.viper-7.com/1zuxfo


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -