Example #1
0
 /**
  * @param array $indexs
  * @param bool $indexsAsUid = false
  * @return WebMailMessageCollection | null
  */
 function &LoadMessageHeadersInOneRequest_Old($folder, $indexs, $indexsAsUid = false, $imapFlags = null, $imapSizes = null)
 {
     $messageCollection = null;
     $indexsStr = trim(implode(',', $indexs));
     $preText = ' ';
     if (null === $imapFlags) {
         $preText .= 'FLAGS ';
     }
     if (null === $imapSizes) {
         $preText .= 'RFC822.SIZE ';
     }
     $rString = 'FETCH ' . $indexsStr . ' (UID' . $preText . 'BODY.PEEK[HEADER])';
     //		$rString = 'FETCH '.$indexsStr.' (UID'.$preText.'BODY.PEEK[HEADER.FIELDS (RETURN-PATH RECEIVED MIME-VERSION FROM TO CC DATE SUBJECT X-MSMAIL-PRIORITY IMPORTANCE X-PRIORITY CONTENT-TYPE)])';
     if ($indexsAsUid) {
         $rString = 'UID ' . $rString;
     }
     $responseArray = $this->_imapMail->getResponseAsArray($rString);
     if (is_array($responseArray)) {
         $messageCollection = new WebMailMessageCollection();
         $headersString = implode('', $responseArray);
         $pieces = preg_split('/\\* [\\d]+ FETCH /', $headersString);
         foreach ($pieces as $key => $text) {
             $uid = $size = $flags = null;
             $lines = explode("\n", trim($text));
             $firstline = array_shift($lines);
             $lastline = array_pop($lines);
             $matchUid = $matchSize = $matchFlags = array();
             preg_match('/UID (\\d+)/', $firstline, $matchUid);
             if (isset($matchUid[1])) {
                 $uid = (int) $matchUid[1];
             }
             if (null === $imapFlags) {
                 preg_match('/FLAGS \\(([^\\)]*)\\)/', $firstline, $matchFlags);
                 if (isset($matchFlags[1])) {
                     $flags = trim(trim($matchFlags[1]), '()');
                 }
             } else {
                 if (isset($imapFlags[$uid])) {
                     $flags = $imapFlags[$uid];
                 }
             }
             if (null === $imapSizes) {
                 preg_match('/RFC822\\.SIZE ([\\d]+)/', $firstline, $matchSize);
                 if (isset($matchSize[1])) {
                     $size = (int) $matchSize[1];
                 }
             } else {
                 if (isset($imapSizes[$uid])) {
                     $size = (int) $imapSizes[$uid];
                 }
             }
             if (null === $uid) {
                 $match = array();
                 preg_match('/UID (\\d+)/', $lastline, $match);
                 if (isset($match[1])) {
                     $uid = (int) $match[1];
                 }
             }
             $text = implode("\n", $lines);
             $pieces[$key] = array($uid, trim($text), $size, $flags);
         }
         if (!$this->_imapMail->IsSortSupport()) {
             arsort($pieces);
         }
         foreach ($pieces as $headerArray) {
             if (is_array($headerArray) && count($headerArray) == 4 && $headerArray[0] > 0 && strlen($headerArray[1]) > 10) {
                 $msg = new WebMailMessage();
                 $msg->LoadMessageFromRawBody($headerArray[1]);
                 $msg->IdFolder = $folder->IdDb;
                 $msg->IdMsg = $headerArray[0];
                 $msg->Uid = $headerArray[0];
                 $msg->Size = (int) $headerArray[2];
                 $this->_setMessageFlags($msg, $headerArray[3]);
                 $messageCollection->Add($msg);
                 unset($msg);
             }
         }
     }
     return $messageCollection;
 }