/** * @param array $indexs * @param bool $indexsAsUid = false * @return WebMailMessageCollection | null */ function &LoadMessageHeadersInOneRequest($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); unset($responseArray); $piecesOut = array(); $pieces = preg_split('/\\* [\\d]+ FETCH /', $headersString); $tmpArray = array(); preg_match_all('/\\* ([\\d]+) FETCH /', $headersString, $tmpArray); $piecesFetchId = isset($tmpArray[1]) ? $tmpArray[1] : array(); unset($tmpArray, $headersString); foreach ($pieces as $key => $text) { if (isset($piecesFetchId[$key - 1])) { $index = $piecesFetchId[$key - 1]; $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]; } } $piecesOut[$indexsAsUid ? $uid : $index] = array($uid, trim(implode("\n", $lines)), $size, $flags); } } unset($pieces); foreach ($indexs as $value) { if (isset($piecesOut[$value])) { $headerArray = $piecesOut[$value]; 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; }