irm/lib/hildegard.class.php
/*
  function to decode a MIME-encoded string, returns the original string, if not MIME
  Thanks to horde!
  function taken from: http://ftp.horde.org/pub/imp/tarballs/old/imp-2.0.0.tar.gz
*/
function to decode a MIME-encoded string, returns the original string, if not MIME
Thanks to horde.
function to decode a MIME - encoded string returns the original string if not MIME Thanks to horde .
function decode_mime_string ($string) {
   if (eregi("=?([A-Z,0-9,-]+)?([A-Z,0-9,-]+)?([A-Z,0-9,-,=,_]+)?=", $string)) {
      if (ereg("^=?", $string)) $string = ' ' . $string;
      $coded_strings = explode(' =?', $string);
      $counter = 1;
      $string = $coded_strings[0]; 
      while ($counter < sizeof($coded_strings)) {
         $elements = explode('?', $coded_strings[$counter]); 
         if (eregi("Q", $elements[1])) {
            $elements[2] = str_replace('_', ' ', $elements[2]);
            $elements[2] = eregi_replace("=([A-F,0-9]{2})", "%\\1", $elements[2]);
            $string .= urldecode($elements[2]);
         } else { 
            $elements[2] = str_replace('=', '', $elements[2]);
            if ($elements[2]) { $string .= base64_decode($elements[2]); }
         }
         if (isset($elements[3]) && $elements[3] != '') {
            $elements[3] = ereg_replace("^=", '', $elements[3]);
            $string .= $elements[3];
         }
         $counter++;
      }
   }
   return $string;
}
function decode_mime_string ( $ string ) { if ( eregi ( " =?([A-Z,0-9,-]+)?([A-Z,0-9,-]+)?([A-Z,0-9,-,=,_]+)?= " , $ string ) ) { if ( ereg ( " ^=? " , $ string ) ) $ string = ' ' . $ string ; $ coded_strings = explode ( ' =?' , $ string ) ; $ counter = 1 ; $ string = $ coded_strings [ 0 ] ; while ( $ counter < sizeof ( $ coded_strings ) ) { $ elements = explode ( '?' , $ coded_strings [ $ counter ] ) ; if ( eregi ( " Q " , $ elements [ 1 ] ) ) { $ elements [ 2 ] = str_replace ( '_' , ' ' , $ elements [ 2 ] ) ; $ elements [ 2 ] = eregi_replace ( " =([A-F,0-9]{2}) " , " % \\ 1 " , $ elements [ 2 ] ) ; $ string .= urldecode ( $ elements [ 2 ] ) ; } else { $ elements [ 2 ] = str_replace ( '=' , '' , $ elements [ 2 ] ) ; if ( $ elements [ 2 ] ) { $ string .= base64_decode ( $ elements [ 2 ] ) ; } } if ( isset ( $ elements [ 3 ] ) && $ elements [ 3 ] != '' ) { $ elements [ 3 ] = ereg_replace ( " ^= " , '' , $ elements [ 3 ] ) ; $ string .= $ elements [ 3 ] ; } $ counter ++ ; } } return $ string ; }
function to decode a MIME-encoded string, returns the original string, if not MIME
Thanks to horde!
function to decode a MIME - encoded string returns the original string if not MIME Thanks to horde!
/* add non encoded text that is before the encoding */ /* part 0 = charset */ /* part 1 == encoding */ /* part 2 == encoded part */ /* part 3 == unencoded part beginning with a = */ /* How can we use the charset information? */ /* we should check for B the only valid encoding other then Q */