示例#1
0
 /**
  * @param CBodyStructureObject $bodyStructureObject
  */
 function FillByBodyStructure(&$bodyStructureObject, $defaulAccountEncode = null)
 {
     $gCharset = null;
     $oHeaders = $bodyStructureObject->GetFullHeaders();
     if (!empty($oHeaders)) {
         $this->OriginalHeaders = $oHeaders;
         $this->Headers->Parse($oHeaders);
     }
     $this->TextBodies->BodyStructureType = $bodyStructureObject->ClassType();
     $this->Size = $bodyStructureObject->GetSize();
     $bodyPartsArray = array();
     $bodyPartsArray =& $bodyStructureObject->GetBodyPartsAsArray();
     if (count($bodyPartsArray) > 0) {
         foreach ($bodyPartsArray as $key => $variable) {
             $encode = '';
             $charset = null !== $defaulAccountEncode ? $defaulAccountEncode : CPAGE_UTF8;
             $part = $bodyStructureObject->GetPartByKey($key);
             if ($part) {
                 $part_charset = CBodyStructureParser::GetCharsetFromPart($part);
                 $part_encode = CBodyStructureParser::GetEncodeFromPart($part);
                 if (strlen($part_charset) > 0) {
                     $charset = $part_charset;
                     $gCharset = null === $gCharset ? $part_charset : $gCharset;
                     $this->TextBodies->SetTextCharset($charset);
                     $this->HasCharset = true;
                 }
                 if (strlen($part_encode) > 0) {
                     $encode = $part_encode;
                 }
                 if (strlen($encode) > 0) {
                     $variable = ConvertUtils::DecodeBodyByType($variable, $encode);
                 }
                 $variable = ConvertUtils::ConvertEncoding($variable, $charset, $GLOBALS[MailOutputCharset]);
                 $len = MIMEConst_TrimBodyLen_Bytes;
                 if (!isset($GLOBALS[MIMEConst_DoNotUseMTrim]) && $len > 0 && strlen($variable) > $len) {
                     $variable = substr($variable, 0, $len);
                     $GLOBALS[MIMEConst_IsBodyTrim] = true;
                 }
                 $type = CBodyStructureParser::GetBodyStructurePartType($part);
                 switch ($type) {
                     case BODYSTRUCTURE_TYPE_TEXT_PLAIN:
                         $this->TextBodies->PlainTextBodyPart .= str_replace("\n", CRLF, str_replace("\r", '', ConvertUtils::WMBackHtmlNewCode($variable)));
                         break;
                     case BODYSTRUCTURE_TYPE_TEXT_HTML:
                         $this->TextBodies->HtmlTextBodyPart .= str_replace("\n", CRLF, str_replace("\r", '', ConvertUtils::WMBackHtmlNewCode($variable)));
                         break;
                 }
             }
         }
     }
     $attachmentsIndexs = array();
     $attachmentsIndexs =& $bodyStructureObject->GetAttachmentIndexs();
     if (count($attachmentsIndexs) > 0) {
         foreach ($attachmentsIndexs as $idx) {
             $part = $bodyStructureObject->GetPartByKey($idx);
             if ($part) {
                 $part_name = CBodyStructureParser::GetNameFromPart($part);
                 if (empty($part_name)) {
                     $part_name = CBodyStructureParser::GetFileNameFromPart($part);
                 }
                 if (empty($part_name)) {
                     $part_name = CBodyStructureParser::GetNullNameByType($part);
                 }
                 if ($gCharset !== null && !ConvertUtils::IsLatin($part_name)) {
                     $part_name = ConvertUtils::ConvertEncoding($part_name, $gCharset, CPAGE_UTF8);
                 }
                 $size = 0;
                 if (!empty($part_name)) {
                     $size = CBodyStructureParser::GetSizeFromPart($part);
                 }
                 $part_encode = CBodyStructureParser::GetEncodeFromPart($part);
                 $part_contentId = CBodyStructureParser::GetContentIdFromPart($part);
                 if (!$part_contentId) {
                     $part_contentId = null;
                 }
                 $this->Attachments->AddFromBodyStructure($part_name, $idx, $size, $part_encode, $part_contentId);
             }
         }
     }
 }
示例#2
0
 function GetArray($str)
 {
     $line = trim($str);
     $line = substr($line, 1, strlen($line) - 2);
     $line = str_replace(')(', ') (', $line);
     $struct = CBodyStructureParser::Parse($line);
     if (is_array($struct) && count($struct) > 1 && is_string($struct[0]) && is_string($struct[1])) {
         $struct = array($struct);
     }
     return $struct;
 }