scriptz-team

DEiONCUBE

Dec 28th, 2011
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 26.35 KB | None | 0 0
  1. <?php
  2. /**
  3. *
  4. *    
  5. *      _____ _____ _ _____ _____         _____ _____ _____ _____
  6. *  ___|     | __  |_|  _  |_   _|___ ___|_   _|   __|  _  |     |
  7. * |_ -|   --|    -| |   __| | | |- _|___| | | |   __|     | | | |
  8. * |___|_____|__|__|_|__|    |_| |___|     |_| |_____|__|__|_|_|_|
  9. * |s C R i P T z - T E A M . i N F O|
  10. *
  11. * This file was created by sCRiPTz-TEAM.iNFO [DEiONCUBE TEAM]
  12. * @ IonCube & Zend & NuSphere DeCoder
  13. *
  14. * @    Version             :    1.0.0.3
  15. * @    Author              :    sCRiPTz-TEAM.iNFO
  16. * @    Released            :    26-December-2011
  17. * @    Official site       :    http://sCRiPTz-TEAM.iNFO
  18. *
  19. */
  20.  
  21. class Mail_mimeDecode
  22. {
  23.  
  24.     public $_input = NULL;
  25.     public $_header = NULL;
  26.     public $_body = NULL;
  27.     public $_error = NULL;
  28.     public $_include_bodies = NULL;
  29.     public $_decode_bodies = NULL;
  30.     public $_decode_headers = NULL;
  31.  
  32.     public function Mail_mimeDecode( $input )
  33.     {
  34.         list( $header, $body ) = header        $this->_input = $input;
  35.         $this->_header = $header;
  36.         $this->_body = $body;
  37.         $this->_decode_bodies = true;
  38.         $this->_include_bodies = true;
  39.     }
  40.  
  41.     public function decode( $params = null )
  42.     {
  43.         $isStatic = !( isset( $this ) && get_class( $this ) == "Mail_mimeDecode" );
  44.         if ( $isStatic && isset( $params['input'] ) )
  45.         {
  46.             $obj = new Mail_mimeDecode( $params['input'] );
  47.             $structure = $obj->decode( $params );
  48.         }
  49.         else
  50.         {
  51.             if ( $isStatic )
  52.             {
  53.                 return false;
  54.             }
  55.             $this->_include_bodies = isset( $params['include_bodies'] ) ? $params['include_bodies'] : false;
  56.             $this->_decode_bodies = isset( $params['decode_bodies'] ) ? $params['decode_bodies'] : false;
  57.             $this->_decode_headers = isset( $params['decode_headers'] ) ? $params['decode_headers'] : false;
  58.             $structure = $this->_decode( $this->_header, $this->_body );
  59.         }
  60.         return $structure;
  61.     }
  62.  
  63.     public function _decode( $headers, $body, $default_ctype = "text/plain" )
  64.     {
  65.         $return = new stdClass( );
  66.         $return->headers = array( );
  67.         $headers = $this->_parseHeaders( $headers );
  68.         foreach ( $headers as $value )
  69.         {
  70.             if ( isset( $return->headers[strtolower( $value['name'] )] ) && !is_array( $return->headers[strtolower( $value['name'] )] ) )
  71.             {
  72.                 $return->headers[strtolower( $value['name'] )] = array(
  73.                     $return->headers[strtolower( $value['name'] )]
  74.                 );
  75.                 $return->headers[strtolower( $value['name'] )][] = $value['value'];
  76.             }
  77.             else if ( isset( $return->headers[strtolower( $value['name'] )] ) )
  78.             {
  79.                 $return->headers[strtolower( $value['name'] )][] = $value['value'];
  80.             }
  81.             else
  82.             {
  83.                 $return->headers[strtolower( $value['name'] )] = $value['value'];
  84.             }
  85.         }
  86.         reset( $headers );
  87.         while ( list( $key, $value ) = key )
  88.         {
  89.             $headers[$key]['name'] = strtolower( $headers[$key]['name'] );
  90.             switch ( $headers[$key]['name'] )
  91.             {
  92.             case "content-type" :
  93.                 $content_type = $this->_parseHeaderValue( $headers[$key]['value'] );
  94.                 if ( preg_match( "/([0-9a-z+.-]+)\\/([0-9a-z+.-]+)/i", $content_type['value'], $regs ) )
  95.                 {
  96.                     $return->ctype_primary = $regs[1];
  97.                     $return->ctype_secondary = $regs[2];
  98.                 }
  99.                 if ( isset( $content_type['other'] ) )
  100.                 {
  101.                     while ( list( $p_name, $p_value ) = p_name )
  102.                     {
  103.                         $return->ctype_parameters[$p_name] = $p_value;
  104.                     }
  105.                 }
  106.                 break;
  107.             case "content-disposition" :
  108.                 $content_disposition = $this->_parseHeaderValue( $headers[$key]['value'] );
  109.                 $return->disposition = $content_disposition['value'];
  110.                 if ( isset( $content_disposition['other'] ) )
  111.                 {
  112.                     while ( list( $p_name, $p_value ) = p_name )
  113.                     {
  114.                         $return->d_parameters[$p_name] = $p_value;
  115.                     }
  116.                 }
  117.                 break;
  118.             case "content-transfer-encoding" :
  119.                 $content_transfer_encoding = $this->_parseHeaderValue( $headers[$key]['value'] );
  120.             }
  121.         }
  122.         if ( isset( $content_type ) )
  123.         {
  124.             switch ( strtolower( $content_type['value'] ) )
  125.             {
  126.             case "text/plain" :
  127.                 $encoding = isset( $content_transfer_encoding ) ? $content_transfer_encoding['value'] : "7bit";
  128.                 $this->_include_bodies ? ( $return->body = $this->_decode_bodies ? $this->_decodeBody( $body, $encoding ) : $body ) : null;
  129.                 break;
  130.             case "text/html" :
  131.                 $encoding = isset( $content_transfer_encoding ) ? $content_transfer_encoding['value'] : "7bit";
  132.                 $this->_include_bodies ? ( $return->body = $this->_decode_bodies ? $this->_decodeBody( $body, $encoding ) : $body ) : null;
  133.                 break;
  134.             case "multipart/parallel" :
  135.             case "multipart/report" :
  136.             case "multipart/signed" :
  137.             case "multipart/digest" :
  138.             case "multipart/alternative" :
  139.             case "multipart/related" :
  140.             case "multipart/mixed" :
  141.                 if ( !isset( $content_type['other']['boundary'] ) )
  142.                 {
  143.                     $this->_error = "No boundary found for ".$content_type['value']." part";
  144.                     return false;
  145.                 }
  146.                 $default_ctype = strtolower( $content_type['value'] ) === "multipart/digest" ? "message/rfc822" : "text/plain";
  147.                 $parts = $this->_boundarySplit( $body, $content_type['other']['boundary'] );
  148.                 $i = 0;
  149.                 while ( $i < count( $parts ) )
  150.                 {
  151.                     list( $part_header, $part_body ) = part_header                    $part = $this->_decode( $part_header, $part_body, $default_ctype );
  152.                     $return->parts[] = $part;
  153.                     ++$i;
  154.                 }
  155.                 break;
  156.             case "message/rfc822" :
  157.             }
  158.             $obj =& new Mail_mimeDecode( $body );
  159.             $return->parts[] = $obj->decode( array(
  160.                 "include_bodies" => $this->_include_bodies,
  161.                 "decode_bodies" => $this->_decode_bodies,
  162.                 "decode_headers" => $this->_decode_headers
  163.             ) );
  164.             unset( $obj );
  165.             break;
  166.             if ( !isset( $content_transfer_encoding['value'] ) )
  167.             {
  168.                 $content_transfer_encoding['value'] = "7bit";
  169.             }
  170.             $this->_include_bodies ? ( $return->body = $this->_decode_bodies ? $this->_decodeBody( $body, $content_transfer_encoding['value'] ) : $body ) : null;
  171.             break;
  172.         }
  173.         else
  174.         {
  175.             $ctype = explode( "/", $default_ctype );
  176.             $return->ctype_primary = $ctype[0];
  177.             $return->ctype_secondary = $ctype[1];
  178.             $this->_include_bodies ? ( $return->body = $this->_decode_bodies ? $this->_decodeBody( $body ) : $body ) : null;
  179.         }
  180.         return $return;
  181.     }
  182.  
  183.     public function &getMimeNumbers( &$structure, $no_refs = false, $mime_number = "", $prepend = "" )
  184.     {
  185.         $return = array( );
  186.         if ( !empty( $structure->parts ) )
  187.         {
  188.             if ( $mime_number != "" )
  189.             {
  190.                 $structure->mime_id = $prepend.$mime_number;
  191.                 $return[$prepend.$mime_number] =& $structure;
  192.             }
  193.             $i = 0;
  194.             while ( $i < count( $structure->parts ) )
  195.             {
  196.                 if ( !empty( $structure->headers['content-type'] ) && substr( strtolower( $structure->headers['content-type'] ), 0, 8 ) == "message/" )
  197.                 {
  198.                     $prepend = $prepend.$mime_number.".";
  199.                     $_mime_number = "";
  200.                 }
  201.                 else
  202.                 {
  203.                     $_mime_number = $mime_number == "" ? $i + 1 : sprintf( "%s.%s", $mime_number, $i + 1 );
  204.                 }
  205.                 $arr =& Mail_mimeDecode::getmimenumbers( $structure->parts[$i], $no_refs, $_mime_number, $prepend );
  206.                 foreach ( $arr as $key => $val )
  207.                 {
  208.                     $no_refs ? $return[$key] = "" : ( $return[$key] =& $arr[$key] );
  209.                 }
  210.                 ++$i;
  211.             }
  212.         }
  213.         else
  214.         {
  215.             if ( $mime_number == "" )
  216.             {
  217.                 $mime_number = "1";
  218.             }
  219.             $structure->mime_id = $prepend.$mime_number;
  220.             $no_refs ? $return[$prepend.$mime_number] = "" : ( $return[$prepend.$mime_number] =& $structure );
  221.         }
  222.         return $return;
  223.     }
  224.  
  225.     public function _splitBodyHeader( $input )
  226.     {
  227.         if ( preg_match( "/^(.*?)\r?\n\r?\n(.*)/s", $input, $match ) )
  228.         {
  229.             return array(
  230.                 $match[1],
  231.                 $match[2]
  232.             );
  233.         }
  234.         $this->_error = "Could not split header and body";
  235.         return false;
  236.     }
  237.  
  238.     public function _parseHeaders( $input )
  239.     {
  240.         if ( $input !== "" )
  241.         {
  242.             $input = preg_replace( "/\r?\n/", "\r\n", $input );
  243.             $input = preg_replace( "/\r\n(\t| )+/", " ", $input );
  244.             $headers = explode( "\r\n", trim( $input ) );
  245.             foreach ( $headers as $value )
  246.             {
  247.                 $hdr_name = substr( $value, 0, $pos = strpos( $value, ":" ) );
  248.                 $hdr_value = substr( $value, $pos + 1 );
  249.                 if ( $hdr_value[0] == " " )
  250.                 {
  251.                     $hdr_value = substr( $hdr_value, 1 );
  252.                 }
  253.                 $return[] = array(
  254.                     "name" => $hdr_name,
  255.                     "value" => $this->_decode_headers ? $this->_decodeHeader( $hdr_value ) : $hdr_value
  256.                 );
  257.             }
  258.         }
  259.         else
  260.         {
  261.             $return = array( );
  262.         }
  263.         return $return;
  264.     }
  265.  
  266.     public function _parseHeaderValue( $input )
  267.     {
  268.         if ( ( $pos = strpos( $input, ";" ) ) !== false )
  269.         {
  270.             $return['value'] = trim( substr( $input, 0, $pos ) );
  271.             $input = trim( substr( $input, $pos + 1 ) );
  272.             if ( 0 < strlen( $input ) )
  273.             {
  274.                 $splitRegex = "/([^;'\"]*['\"]([^'\"]*([^'\"]*)*)['\"][^;'\"]*|([^;]+))(;|\$)/";
  275.                 preg_match_all( $splitRegex, $input, $matches );
  276.                 $parameters = array( );
  277.                 $i = 0;
  278.                 while ( $i < count( $matches[0] ) )
  279.                 {
  280.                     $param = $matches[0][$i];
  281.                     while ( substr( $param, 0 - 2 ) == "\\;" )
  282.                     {
  283.                         $param .= $matches[0][++$i];
  284.                     }
  285.                     $parameters[] = $param;
  286.                     ++$i;
  287.                 }
  288.                 $i = 0;
  289.                 while ( $i < count( $parameters ) )
  290.                 {
  291.                     $param_name = trim( substr( $parameters[$i], 0, $pos = strpos( $parameters[$i], "=" ) ), "'\";\t\\ " );
  292.                     $param_value = trim( str_replace( "\\;", ";", substr( $parameters[$i], $pos + 1 ) ), "'\";\t\\ " );
  293.                     if ( $param_value[0] == "\"" )
  294.                     {
  295.                         $param_value = substr( $param_value, 1, 0 - 1 );
  296.                     }
  297.                     $return['other'][$param_name] = $param_value;
  298.                     $return['other'][strtolower( $param_name )] = $param_value;
  299.                     ++$i;
  300.                 }
  301.             }
  302.         }
  303.         else
  304.         {
  305.             $return['value'] = trim( $input );
  306.         }
  307.         return $return;
  308.     }
  309.  
  310.     public function _boundarySplit( $input, $boundary )
  311.     {
  312.         $parts = array( );
  313.         $bs_possible = substr( $boundary, 2, 0 - 2 );
  314.         $bs_check = "\\\"".$bs_possible."\\\"";
  315.         if ( $boundary == $bs_check )
  316.         {
  317.             $boundary = $bs_possible;
  318.         }
  319.         $tmp = explode( "--".$boundary, $input );
  320.         $i = 1;
  321.         while ( $i < count( $tmp ) - 1 )
  322.         {
  323.             $parts[] = $tmp[$i];
  324.             ++$i;
  325.         }
  326.         return $parts;
  327.     }
  328.  
  329.     public function _decodeHeader( $input )
  330.     {
  331.         $input = preg_replace( "/(=\\?[^?]+\\?(q|b)\\?[^?]*\\?=)(\\s)+=\\?/i", "\\1=?", $input );
  332.         while ( preg_match( "/(=\\?([^?]+)\\?(q|b)\\?([^?]*)\\?=)/i", $input, $matches ) )
  333.         {
  334.             $encoded = $matches[1];
  335.             $charset = $matches[2];
  336.             $encoding = $matches[3];
  337.             $text = $matches[4];
  338.             switch ( strtolower( $encoding ) )
  339.             {
  340.             case "b" :
  341.                 $text = base64_decode( $text );
  342.                 break;
  343.             case "q" :
  344.                 $text = str_replace( "_", " ", $text );
  345.                 preg_match_all( "/=([a-f0-9]{2})/i", $text, $matches );
  346.                 foreach ( $matches[1] as $value )
  347.                 {
  348.                     $text = str_replace( "=".$value, chr( hexdec( $value ) ), $text );
  349.                 }
  350.             }
  351.             $input = str_replace( $encoded, $text, $input );
  352.         }
  353.         return $input;
  354.     }
  355.  
  356.     public function _decodeBody( $input, $encoding = "7bit" )
  357.     {
  358.         switch ( strtolower( $encoding ) )
  359.         {
  360.         case "7bit" :
  361.             return $input;
  362.         case "quoted-printable" :
  363.             return $this->_quotedPrintableDecode( $input );
  364.         case "base64" :
  365.         }
  366.         return base64_decode( $input );
  367.         return $input;
  368.     }
  369.  
  370.     public function _quotedPrintableDecode( $input )
  371.     {
  372.         $input = preg_replace( "/=\r?\n/", "", $input );
  373.         $input = preg_replace( "/=([a-f0-9]{2})/ie", "chr(hexdec('\\1'))", $input );
  374.         return $input;
  375.     }
  376.  
  377.     public function &uudecode( $input )
  378.     {
  379.         preg_match_all( "/begin ([0-7]{3}) (.+)\r?\n(.+)\r?\nend/Us", $input, $matches );
  380.         $j = 0;
  381.         while ( $j < count( $matches[3] ) )
  382.         {
  383.             $str = $matches[3][$j];
  384.             $filename = $matches[2][$j];
  385.             $fileperm = $matches[1][$j];
  386.             $file = "";
  387.             $str = preg_split( "/\r?\n/", trim( $str ) );
  388.             $strlen = count( $str );
  389.             $i = 0;
  390.             while ( $i < $strlen )
  391.             {
  392.                 $pos = 1;
  393.                 $d = 0;
  394.                 $len = ( integer )( ord( substr( $str[$i], 0, 1 ) ) - 32 - " " & 63 );
  395.                 while ( $d + 3 <= $len && $pos + 4 <= strlen( $str[$i] ) )
  396.                 {
  397.                     $c0 = ord( substr( $str[$i], $pos, 1 ) ) ^ 32;
  398.                     $c1 = ord( substr( $str[$i], $pos + 1, 1 ) ) ^ 32;
  399.                     $c2 = ord( substr( $str[$i], $pos + 2, 1 ) ) ^ 32;
  400.                     $c3 = ord( substr( $str[$i], $pos + 3, 1 ) ) ^ 32;
  401.                     $file .= chr( ( $c0 - " " & 63 ) << 2 | ( $c1 - " " & 63 ) >> 4 );
  402.                     $file .= chr( ( $c1 - " " & 63 ) << 4 | ( $c2 - " " & 63 ) >> 2 );
  403.                     $file .= chr( ( $c2 - " " & 63 ) << 6 | $c3 - " " & 63 );
  404.                     $pos += 4;
  405.                     $d += 3;
  406.                 }
  407.                 if ( $d + 2 <= $len && $pos + 3 <= strlen( $str[$i] ) )
  408.                 {
  409.                     $c0 = ord( substr( $str[$i], $pos, 1 ) ) ^ 32;
  410.                     $c1 = ord( substr( $str[$i], $pos + 1, 1 ) ) ^ 32;
  411.                     $c2 = ord( substr( $str[$i], $pos + 2, 1 ) ) ^ 32;
  412.                     $file .= chr( ( $c0 - " " & 63 ) << 2 | ( $c1 - " " & 63 ) >> 4 );
  413.                     $file .= chr( ( $c1 - " " & 63 ) << 4 | ( $c2 - " " & 63 ) >> 2 );
  414.                     $pos += 3;
  415.                     $d += 2;
  416.                 }
  417.                 if ( $d + 1 <= $len && $pos + 2 <= strlen( $str[$i] ) )
  418.                 {
  419.                     $c0 = ord( substr( $str[$i], $pos, 1 ) ) ^ 32;
  420.                     $c1 = ord( substr( $str[$i], $pos + 1, 1 ) ) ^ 32;
  421.                     $file .= chr( ( $c0 - " " & 63 ) << 2 | ( $c1 - " " & 63 ) >> 4 );
  422.                 }
  423.                 ++$i;
  424.             }
  425.             $files[] = array(
  426.                 "filename" => $filename,
  427.                 "fileperm" => $fileperm,
  428.                 "filedata" => $file
  429.             );
  430.             ++$j;
  431.         }
  432.         return $files;
  433.     }
  434.  
  435.     public function getSendArray( )
  436.     {
  437.         $this->_decode_headers = FALSE;
  438.         $headerlist = $this->_parseHeaders( $this->_header );
  439.         $to = "";
  440.         if ( !$headerlist )
  441.         {
  442.             return false;
  443.         }
  444.         foreach ( $headerlist as $item )
  445.         {
  446.             $header[$item['name']] = $item['value'];
  447.             switch ( strtolower( $item['name'] ) )
  448.             {
  449.             case "to" :
  450.                 break;
  451.             case "cc" :
  452.                 break;
  453.             case "bcc" :
  454.             }
  455.             $to = ",".$item['value'];
  456.             break;
  457.         }
  458.         if ( $to == "" )
  459.         {
  460.             return false;
  461.         }
  462.         $to = substr( $to, 1 );
  463.         return array(
  464.             $to,
  465.             $header,
  466.             $this->_body
  467.         );
  468.     }
  469.  
  470.     public function getXML( $input )
  471.     {
  472.         $crlf = "\r\n";
  473.         $output = "<?xml version='1.0'?>".$crlf."<!DOCTYPE email SYSTEM \"http://www.phpguru.org/xmail/xmail.dtd\">".$crlf."<email>".$crlf.Mail_mimeDecode::_getxml( $input )."</email>";
  474.         return $output;
  475.     }
  476.  
  477.     public function _getXML( $input, $indent = 1 )
  478.     {
  479.         $htab = "\t";
  480.         $crlf = "\r\n";
  481.         $output = "";
  482.         $headers = ( array )$input->headers;
  483.         foreach ( $headers as $hdr_name => $hdr_value )
  484.         {
  485.             if ( is_array( $headers[$hdr_name] ) )
  486.             {
  487.                 $i = 0;
  488.                 do
  489.                 {
  490.                     if ( $i < count( $hdr_value ) )
  491.                     {
  492.                         $output .= Mail_mimeDecode::_getxml_helper( $hdr_name, $hdr_value[$i], $indent );
  493.                         ++$i;
  494.                     }
  495.                 } while ( 1 );
  496.             }
  497.             $output .= Mail_mimeDecode::_getxml_helper( $hdr_name, $hdr_value, $indent );
  498.         }
  499.         if ( !empty( $input->parts ) )
  500.         {
  501.             $i = 0;
  502.             while ( $i < count( $input->parts ) )
  503.             {
  504.                 $output .= $crlf.str_repeat( $htab, $indent )."<mimepart>".$crlf.Mail_mimeDecode::_getxml( $input->parts[$i], $indent + 1 ).str_repeat( $htab, $indent )."</mimepart>".$crlf;
  505.                 ++$i;
  506.             }
  507.         }
  508.         else if ( isset( $input->body ) )
  509.         {
  510.             $output .= $crlf.str_repeat( $htab, $indent )."<body><![CDATA[".$input->body."]]></body>".$crlf;
  511.         }
  512.         return $output;
  513.     }
  514.  
  515.     public function _getXML_helper( $hdr_name, $hdr_value, $indent )
  516.     {
  517.         $htab = "\t";
  518.         $crlf = "\r\n";
  519.         $return = "";
  520.         $new_hdr_value = $hdr_name != "received" ? Mail_mimeDecode::_parseheadervalue( $hdr_value ) : array(
  521.             "value" => $hdr_value
  522.         );
  523.         $new_hdr_name = str_replace( " ", "-", ucwords( str_replace( "-", " ", $hdr_name ) ) );
  524.         if ( !empty( $new_hdr_value['other'] ) )
  525.         {
  526.             foreach ( $new_hdr_value['other'] as $paramname => $paramvalue )
  527.             {
  528.                 $params[] = str_repeat( $htab, $indent ).$htab."<parameter>".$crlf.str_repeat( $htab, $indent ).$htab.$htab."<paramname>".htmlspecialchars( $paramname )."</paramname>".$crlf.str_repeat( $htab, $indent ).$htab.$htab."<paramvalue>".htmlspecialchars( $paramvalue )."</paramvalue>".$crlf.str_repeat( $htab, $indent ).$htab."</parameter>".$crlf;
  529.             }
  530.             $params = implode( "", $params );
  531.         }
  532.         else
  533.         {
  534.             $params = "";
  535.         }
  536.         $return = str_repeat( $htab, $indent )."<header>".$crlf.str_repeat( $htab, $indent ).$htab."<headername>".htmlspecialchars( $new_hdr_name )."</headername>".$crlf.str_repeat( $htab, $indent ).$htab."<headervalue>".htmlspecialchars( $new_hdr_value['value'] )."</headervalue>".$crlf.$params.str_repeat( $htab, $indent )."</header>".$crlf;
  537.         return $return;
  538.     }
  539.  
  540. }
  541.  
  542. function interpret_structure( $structure )
  543. {
  544.     global $_emailoutput;
  545.     global $disable_iconv;
  546.     $ctype = strtolower( $structure->ctype_primary )."/".strtolower( $structure->ctype_secondary );
  547.     if ( !$ctype )
  548.     {
  549.         $ctype = "text/plain";
  550.     }
  551.     if ( $ctype == "text/html" || $ctype == "text/plain" )
  552.     {
  553.         $charset = "us-ascii";
  554.         if ( !empty( $structure->ctype_parameters ) && isset( $structure->ctype_parameters['charset'] ) )
  555.         {
  556.             $charset = $structure->ctype_parameters['charset'];
  557.         }
  558.         if ( !empty( $structure->disposition ) && $structure->disposition == "attachment" )
  559.         {
  560.             handle_attachment( $structure );
  561.         }
  562.         else
  563.         {
  564.             $var = $ctype == "text/html" ? "html" : "text";
  565.             $bodyUtf8 = $structure->body;
  566.             if ( $charset == "UTF-8" )
  567.             {
  568.                 $charset = "";
  569.             }
  570.             if ( $charset && function_exists( "iconv" ) && !$disable_iconv )
  571.             {
  572.                 $bodyUtf8 = iconv( $charset, "utf-8", $bodyUtf8 );
  573.                 if ( !$_emailoutput['headers']['convertedcharset'] )
  574.                 {
  575.                     $_emailoutput['headers']['subject'] = iconv( $charset, "utf-8", $_emailoutput['headers']['subject'] );
  576.                     $_emailoutput['headers']['convertedcharset'] = true;
  577.                 }
  578.             }
  579.             $_emailoutput['body'][$ctype] = trim( $bodyUtf8 );
  580.         }
  581.     }
  582.     else if ( strtolower( $structure->ctype_primary ) == "multipart" )
  583.     {
  584.         if ( !empty( $structure->parts ) )
  585.         {
  586.             $i = 0;
  587.             while ( $i < count( $structure->parts ) )
  588.             {
  589.                 interpret_structure( $structure->parts[$i] );
  590.                 ++$i;
  591.             }
  592.         }
  593.     }
  594.     else
  595.     {
  596.         handle_attachment( $structure );
  597.     }
  598. }
  599.  
  600. function handle_attachment( $structure )
  601. {
  602.     global $_emailoutput;
  603.     if ( !empty( $structure->d_parameters['filename'] ) )
  604.     {
  605.         $filename = $structure->d_parameters['filename'];
  606.     }
  607.     else if ( !empty( $structure->ctype_parameters['name'] ) )
  608.     {
  609.         $filename = $structure->ctype_parameters['name'];
  610.     }
  611.     else
  612.     {
  613.         return;
  614.     }
  615.     $ctype = strtolower( $structure->ctype_primary )."/".strtolower( $structure->ctype_secondary );
  616.     $_emailoutput['attachments'][] = array(
  617.         "data" => $structure->body,
  618.         "size" => strlen( $structure->body ),
  619.         "filename" => $filename,
  620.         "contenttype" => $ctype
  621.     );
  622. }
  623.  
  624. require( dirname( "E:\\WWW\\Server\\xampp\\htdocs\\dec\\PHP_DECODER_APP\\app\\01_Decode\\pipe.php" )."/../dbconnect.php" );
  625. require( dirname( "E:\\WWW\\Server\\xampp\\htdocs\\dec\\PHP_DECODER_APP\\app\\01_Decode\\pipe.php" )."/../includes/functions.php" );
  626. require( dirname( "E:\\WWW\\Server\\xampp\\htdocs\\dec\\PHP_DECODER_APP\\app\\01_Decode\\pipe.php" )."/../includes/adminfunctions.php" );
  627. require( dirname( "E:\\WWW\\Server\\xampp\\htdocs\\dec\\PHP_DECODER_APP\\app\\01_Decode\\pipe.php" )."/../includes/ticketfunctions.php" );
  628. $silent = "true";
  629. $_emailoutput = array( );
  630. $fd = fopen( "php://stdin", "r" );
  631. $input = "";
  632. while ( !feof( $fd ) )
  633. {
  634.     $input .= fread( $fd, 1024 );
  635. }
  636. fclose( $fd );
  637. $decode_params['input'] = $input;
  638. $decode_params['include_bodies'] = true;
  639. $decode_params['decode_bodies'] = true;
  640. $decode_params['decode_headers'] = true;
  641. $decode = new Mail_mimeDecode( $input, "\r\n" );
  642. $structure = $decode->decode( $decode_params );
  643. $_emailoutput['headers'] = $structure->headers;
  644. interpret_structure( $structure );
  645. if ( $_emailoutput['body']['text/plain'] )
  646. {
  647.     $body = $_emailoutput['body']['text/plain'];
  648. }
  649. else if ( $_emailoutput['body']['text/html'] )
  650. {
  651.     $body = strip_tags( $_emailoutput['body']['text/html'] );
  652. }
  653. else
  654. {
  655.     $body = "No message found.";
  656. }
  657. $attachments = "";
  658. if ( !empty( $_emailoutput['attachments'] ) )
  659. {
  660.     foreach ( $_emailoutput['attachments'] as $attachment )
  661.     {
  662.         if ( checkTicketAttachmentExtension( $attachment['filename'] ) )
  663.         {
  664.             mt_srand( time( ) );
  665.             $rand = mt_rand( 100000, 999999 );
  666.             $attachmentfilename = $rand."_".$attachment['filename'];
  667.             $attachments .= $attachmentfilename."|";
  668.             $fp = fopen( $attachments_dir.$attachmentfilename, "w" );
  669.             fwrite( $fp, $attachment['data'] );
  670.             fclose( $fp );
  671.         }
  672.         else
  673.         {
  674.             $body .= "\n\nAttachment {$attachment['filename']} blocked - file type not allowed.";
  675.         }
  676.     }
  677. }
  678. $attachments = substr( $attachments, 0, 0 - 1 );
  679. $from = $_emailoutput['headers']['from'];
  680. $to = $_emailoutput['headers']['to'];
  681. $cc = $_emailoutput['headers']['cc'];
  682. $bcc = $_emailoutput['headers']['bcc'];
  683. if ( !$to )
  684. {
  685.     $to = $_emailoutput['headers']['resent-to'];
  686. }
  687. $subject = $_emailoutput['headers']['subject'];
  688. $fromname = preg_replace( "/(.*)<(.*)>/", "\\1", $from );
  689. $fromname = str_replace( "\"", "", $fromname );
  690. $fromemail = preg_replace( "/(.*)<(.*)>/", "\\2", $from );
  691. $to = explode( ",", $to );
  692. foreach ( $to as $toemail )
  693. {
  694.     if ( strpos( ".".$toemail, "<" ) )
  695.     {
  696.         $toemails[] = preg_replace( "/(.*)<(.*)>/", "\\2", $toemail );
  697.     }
  698.     else
  699.     {
  700.         $toemails[] = $toemail;
  701.     }
  702. }
  703. $to = explode( ",", $cc );
  704. foreach ( $to as $toemail )
  705. {
  706.     if ( strpos( ".".$toemail, "<" ) )
  707.     {
  708.         $toemails[] = preg_replace( "/(.*)<(.*)>/", "\\2", $toemail );
  709.     }
  710.     else
  711.     {
  712.         $toemails[] = $toemail;
  713.     }
  714. }
  715. $to = explode( ",", $bcc );
  716. foreach ( $to as $toemail )
  717. {
  718.     if ( strpos( ".".$toemail, "<" ) )
  719.     {
  720.         $toemails[] = preg_replace( "/(.*)<(.*)>/", "\\2", $toemail );
  721.     }
  722.     else
  723.     {
  724.         $toemails[] = $toemail;
  725.     }
  726.     break;
  727. }
  728. $to = implode( ",", $toemails );
  729. processPipedTicket( $to, $fromname, $fromemail, $subject, $body, $attachments );
  730. ?>
Advertisement
Add Comment
Please, Sign In to add comment