Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 17th, 2012  |  syntax: None  |  size: 3.87 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Odd recursion error in parsing MIME message
  2. multipart/mixed
  3.  -- (part 0, sec. "1") multipart/related
  4.     -- (part 0, sec. "1.1") multipart/alternative
  5.        -- (part 0, sec. "1.1.1") text/plain
  6.        -- (part 1, sec. "1.1.2") text/html
  7.     -- (part 1, sec. "1.2") image/gif
  8.  -- (part 1, sec. "2") image/png
  9.        
  10. object(stdClass)
  11.    public 'type' => int // if 1 it's multipart
  12.    public 'parts' => array // Inner parts
  13.        
  14. public function parse($struct, $depth = '')
  15. {
  16.    if(!isset($struct->parts)) return; // Base case of recursion: no parts inside
  17.  
  18.    // $struct->parts is array: index starting from 0.
  19.    for($i = 0, $j = count($struct->parts); $i < $j; $i++)
  20.    {
  21.       $part = $struct->parts[$i]; // Current part
  22.       $ptno = $i + 1; // This is the part number, will be used to build $secno
  23.  
  24.       // Multipart? Go further in recursion passing the new level of nesting
  25.       if($part->type == 1) $this->parse($part, $depth .= "$partno" . ".");
  26.  
  27.       // Compute the section number with the given $depth (if any)
  28.       // ACTUALLY NOT WORKING
  29.       $secno = !empty($depth) ? "$depth$ptno" : "$ptno";
  30.  
  31.       // Where am i?
  32.       echo self::$TYPES[$part->type] . '/' . $part->subtype . ": $secno<br/>";
  33.    }
  34. }
  35.        
  36. text/PLAIN: 1.1.1
  37. text/HTML: 1.1.2
  38. multipart/ALTERNATIVE: 1.1.1
  39. image/GIF: 1.1.2
  40. multipart/RELATED: 1.1
  41. image/PNG: 1.2
  42.        
  43. text/PLAIN: 1.1.1
  44. text/HTML: 1.1.2
  45. multipart/ALTERNATIVE: 1.1
  46. image/GIF: 1.2
  47. multipart/RELATED: 1
  48. image/PNG: 2
  49.        
  50. $test = (object) array(
  51.     'type' => 1, // multipart
  52.     'subtype' => 'MIXED',
  53.     'parts' => array(
  54.         (object) array(
  55.             'type'    => 1, // multipart
  56.             'subtype' => 'RELATED',
  57.             'parts'   => array(
  58.                 (object) array(
  59.                     'type'    => 1, // multipart
  60.                     'subtype' => 'ALTERNATIVE',
  61.                     'parts'   => array(
  62.                         (object) array('type' => 0, 'subtype' => 'PLAIN'),
  63.                         (object) array('type' => 0, 'subtype' => 'HTML'),
  64.                     )
  65.                 ),
  66.                 (object) array(
  67.                     'type'    => 5, // image
  68.                     'subtype' => 'GIF'
  69.                 )
  70.             )
  71.         ),
  72.         (object) array(
  73.             'type'    => 5, // image
  74.             'subtype' => 'PNG'
  75.         )
  76.     )
  77. );
  78.        
  79. $this->parse($part, $depth .= "$partno" . ".");
  80.        
  81. public function parse($struct, $depth = '')
  82. {
  83.    if(!isset($struct->parts)) return; // Base case of recursion: no parts inside
  84.  
  85.    // $struct->parts is array: index starting from 0.
  86.    for($i = 0, $j = count($struct->parts); $i < $j; $i++)
  87.    {
  88.       $part = $struct->parts[$i]; // Current part
  89.       $ptno = $i + 1; // This is the part number, will be used to build $secno
  90.  
  91.       // Multipart? Go further in recursion passing the new level of nesting
  92.       if($part->type == 1) $this->parse($part, $depth . "$partno" . ".");
  93.  
  94.       // Compute the section number with the given $depth (if any)
  95.       $secno = !empty($depth) ? "$depth$ptno" : "$ptno";
  96.  
  97.       // Where am i?
  98.       echo self::$TYPES[$part->type] . '/' . $part->subtype . ": $secno<br/>";
  99.    }
  100. }
  101.        
  102. public function parse($struct, $depth = '')
  103. {
  104.    if(!isset($struct->parts)) return; // Base case of recursion: no parts inside
  105.  
  106.    // $struct->parts is array: index starting from 0.
  107.    for($i = 0, $j = count($struct->parts); $i < $j; $i++)
  108.    {
  109.       $part = $struct->parts[$i]; // Current part
  110.       $ptno = $i + 1; // This is the part number, will be used to build $secno
  111.  
  112.       // Compute the section number with the given $depth (if any)
  113.       $secno = $depth . $ptno
  114.  
  115.       // Multipart? Go further in recursion passing the new level of nesting
  116.       if($part->type == 1) $this->parse($part, $secno . '.');
  117.  
  118.       // Where am i?
  119.       echo self::$TYPES[$part->type] . '/' . $part->subtype . ": $secno<br/>";
  120.    }
  121. }
  122.        
  123. $this->parse($part, $depth .= "$partno" . ".");
  124.        
  125. $this->parse($part, $depth . "$partno" . ".");