/** * Return the current element * * @return Message */ public function current() { if (!isset($this->batch[$this->iterationPos]) && !array_key_exists($this->iterationPos, $this->batch)) { // initialize the batch $this->batch = []; if ($this->batchSize > 1) { $ids = []; $pos = $this->iterationPos; $i = 0; while ($i < $this->batchSize && $this->isValidPosition($pos)) { $ids[$pos] = $this->getMessageId($pos); $this->increasePosition($pos); $i++; } $messages = $this->imap->getMessages(array_values($ids)); foreach ($ids as $pos => $id) { $this->batch[$pos] = isset($messages[$id]) ? $messages[$id] : null; } } else { $this->batch[$this->iterationPos] = $this->imap->getMessage($this->getMessageId($this->iterationPos)); } if ($this->onBatchLoaded !== null) { call_user_func($this->onBatchLoaded, $this->batch); } } return $this->batch[$this->iterationPos]; }