Exemplo n.º 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);
             }
         }
     }
 }
Exemplo n.º 2
0
 function _recFillIndexs($array, $parentKey = null)
 {
     foreach ($array as $key => $variable) {
         if (isset($variable[0])) {
             $idx = null !== $parentKey ? $parentKey . '.' . ($key + 1) : (string) ($key + 1);
             if (is_array($variable[0])) {
                 $this->_recFillIndexs($variable, $idx);
             } else {
                 $type = CBodyStructureParser::GetBodyStructurePartType($variable);
                 switch ($type) {
                     case BODYSTRUCTURE_TYPE_TEXT_PLAIN:
                         $this->_plainIndexs[] = $idx;
                         break;
                     case BODYSTRUCTURE_TYPE_TEXT_HTML:
                         $this->_htmlIndexs[] = $idx;
                         break;
                     case BODYSTRUCTURE_TYPE_ATTACHMENT:
                         $this->_attachmentIndexs[] = $idx;
                         break;
                 }
             }
         }
     }
 }