public function getHeader($msgid) { SpotDebug::msg(SpotDebug::TRACE, __CLASS__ . "->getHeader(" . $msgid . ")"); $this->connect(); try { $this->registerTryCommand(); return $this->_nntp->getHeader($msgid); } catch (Exception $x) { $this->registerError($x); echo PHP_EOL . 'getHeader(): Failed to retrieve article: ' . $msgid . PHP_EOL; /** * Try this operation again, but make sure we are not overloading * the NNTP server with useless requests */ if ($this->tooManyErrors()) { throw $x; } else { return $this->getHeader($msgid); } # else } # catch }
/** * Download a full article header. * * @param string $groupName The name of the group the article is in. * @param mixed $identifier (string) The message-id of the article to download. * (int) The article number. * * @return mixed On success : (array) The header. * On failure : (object) PEAR_Error. * * @access public */ public function get_Header($groupName, $identifier) { $connected = $this->_checkConnection(); if ($connected !== true) { return $connected; } // Make sure the requested group is already selected, if not select it. if (parent::group() !== $groupName) { // Select the group. $summary = $this->selectGroup($groupName); // Return PEAR error object on failure. if ($this->isError($summary)) { if ($this->_debugBool) { $this->_debugging->log(get_class(), __FUNCTION__, $summary->getMessage(), Logger::LOG_NOTICE); } return $summary; } } // Check if it's an article number or message-id. if (!is_numeric($identifier)) { // Verify we have the required triangular brackets if it is a message-id. $identifier = $this->_formatMessageID($identifier); } // Download the header. $header = parent::getHeader($identifier); // If we failed, return PEAR error object. if ($this->isError($header)) { if ($this->_debugBool) { $this->_debugging->log(get_class(), __FUNCTION__, $header->getMessage(), Logger::LOG_NOTICE); } return $header; } $ret = $header; if (count($header) > 0) { $ret = []; // Use the line types of the header as array keys (From, Subject, etc). foreach ($header as $line) { if (preg_match('/([A-Z-]+?): (.*)/i', $line, $matches)) { // If the line type takes more than 1 line, re-use the same array key. if (array_key_exists($matches[1], $ret)) { $ret[$matches[1]] .= $matches[2]; } else { $ret[$matches[1]] = $matches[2]; } } } } return $ret; }