/**
  * @param string $str
  * @param string $toCharset
  * @return array
  */
 function EncodeString($str, $toCharset)
 {
     $outarray = array();
     /* $factor = (MIMEConst_DefaultQB == MIMEConst_QuotedPrintableShort) ? 0.35 : 0.7; */
     $outarray = strtolower($toCharset) == 'utf-8' ? ConvertUtils::SmartChunk($str, MIMEConst_DefaultQB, $toCharset, true) : ConvertUtils::SmartChunk($str, MIMEConst_DefaultQB, $toCharset, false);
     if (!ConvertUtils::IsLatin($str)) {
         for ($i = 0, $c = count($outarray); $i < $c; $i++) {
             if (MIMEConst_DefaultQB == MIMEConst_QuotedPrintableShort) {
                 $outarray[$i] = '=?' . strtolower($toCharset) . '?Q?' . str_replace('?', '=3F', str_replace(' ', '_', str_replace('_', '=5F', ConvertUtils::quotedPrintableWithLinebreak($outarray[$i], true)))) . '?=';
             } else {
                 if (MIMEConst_DefaultQB == MIMEConst_Base64Short) {
                     $outarray[$i] = '=?' . strtolower($toCharset) . '?B?' . base64_encode($outarray[$i]) . '?=';
                 }
             }
         }
     }
     return $outarray;
 }