Source for file NNTP.php
Documentation is available at NNTP.php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Martin Kaltoft <martin@nitro.dk> |
// | Tomas V.V.Cox <cox@idecnet.com> |
// | Heino H. Gehlsen <heino@gehlsen.dk> |
// +----------------------------------------------------------------------+
// $Id: NNTP.php,v 1.30.2.3 2005/01/14 20:07:49 heino Exp $
require_once 'Net/NNTP/Protocol/Client.php';
/* NNTP Authentication modes */
define('NET_NNTP_AUTHORIGINAL', 'original');
define('NET_NNTP_AUTHSIMPLE', 'simple');
define('NET_NNTP_AUTHGENERIC', 'generic');
// Deprecated due to naming
define('PEAR_NNTP_AUTHORIGINAL', NET_NNTP_AUTHORIGINAL );
define('PEAR_NNTP_AUTHSIMPLE', NET_NNTP_AUTHSIMPLE );
define('PEAR_NNTP_AUTHGENERIC', NET_NNTP_AUTHGENERIC );
* The Net_NNTP class is an almost 100 % backward compatible
* frontend class to the Net_NNTP_Protocol_Client class.
* This class should NOT be used in new projects. It is meant
* as a drop in replacement to the outdated v0.2, and uses
* excatly the same protocol implementation as the new
* Net_NNTP_Client class, but has a lot of deprecated
* @author Martin Kaltoft <martin@nitro.dk>
* @author Tomas V.V.Cox <cox@idecnet.com>
* @author Heino H. Gehlsen <heino@gehlsen.dk>
* @version $Id: NNTP.php,v 1.30.2.3 2005/01/14 20:07:49 heino Exp $
* @since Class available since Release 0.1.0
* @deprecated Class deprecated in Release 0.10.0
* @deprecated use last() instead
* @deprecated use first() instead
* Used for storing information about the currently selected group
var $_currentGroup = null;
* Connect to the newsserver.
* The function currently allows automatic authentication via the three last parameters,
* but this feature is to be considered depresated (use connectAuthenticated instead)
* In the future, this function will just be inherrited from the parent,
* and thus the last three parameters will no longer be used to authenticate.
* @param optional string $host The adress of the NNTP-server to connect to.
* @param optional int $port The port to connect to.
* @param optional string $user Deprecated!
* @param optional string $pass Deprecated!
* @param optional string $authmode Deprecated!
* @return mixed (bool) true on success or (object) pear_error on failure
* @see Net_NNTP::connectAuthenticated()
* @see Net_NNTP::authenticate()
function connect($host = NET_NNTP_PROTOCOL_CLIENT_DEFAULT_HOST ,
$port = NET_NNTP_PROTOCOL_CLIENT_DEFAULT_PORT ,
$authmode = NET_NNTP_AUTHORIGINAL )
// Currently this function just 'forwards' to connectAuthenticated().
// {{{ connectAuthenticated()
* Connect to the newsserver, and authenticate. If no user/pass is specified, just connect.
* @param optional string $user The user name to authenticate with
* @param optional string $pass The password
* @param optional string $host The adress of the NNTP-server to connect to.
* @param optional int $port The port to connect to.
* @param optional string $authmode The authentication mode
* @return mixed (bool) true on success or (object) pear_error on failure
* @see Net_NNTP::connect()
* @see Net_NNTP::authenticate()
* @deprecated use connect() and authenticate() instead
$host = NET_NNTP_PROTOCOL_CLIENT_DEFAULT_HOST ,
$port = NET_NNTP_PROTOCOL_CLIENT_DEFAULT_PORT ,
$authmode = NET_NNTP_AUTHORIGINAL )
// Until connect() is changed, connect() is called directly from the parent...
$R = parent ::connect($host, $port);
// Authenticate if username is given
* Close connection to the newsserver
* @see Net_NNTP::connect()
// {{{ prepareConnection()
* Connect to the newsserver, and issue a GROUP command
* Once connection is prepared, we can only fetch articles from one group
* at a time, to fetch from another group, a new connection has to be made.
* This is to avoid the GROUP command for every article, as it is very
* ressource intensive on the newsserver especially when used for
* groups with many articles.
* @param string $host The adress of the NNTP-server to connect to.
* @param optional int $port the port-number to connect to, defaults to 119.
* @param string $newsgroup The name of the newsgroup to use.
* @param optional string $user The user name to authenticate with
* @param optional string $pass The password
* @param optional string $authmode The authentication mode
* @return mixed (bool) true on success or (object) pear_error on failure
* @deprecated Use connect() or connectAuthenticated() instead
$authmode = NET_NNTP_AUTHORIGINAL )
/* connect to the server */
$R = $this->connect($host, $port, $user, $pass, $authmode);
/* issue a GROUP command */
$authmode = NET_NNTP_AUTHORIGINAL )
return $this->prepareConnection($nntpserver, $port, $newsgroup, $user, $pass, $authmode);
* Auth process (not yet standarized but used any way)
* http://www.mibsoftware.com/userkt/nntpext/index.html
* @param string $user The user name
* @param optional string $pass The password if needed
* @param optional string $mode Authinfo type: original, simple, generic
* @return mixed (bool) true on success or (object) pear_error on failure
* @see Net_NNTP::connect()
function authenticate($user, $pass, $mode = NET_NNTP_AUTHORIGINAL )
return PEAR ::throwError ('No username supplied', null );
// Use selected authentication method
return $this->cmdAuthinfo ($user, $pass);
return $this->cmdAuthinfoSimple ($user, $pass);
return $this->cmdAuthinfoGeneric ($user, $pass);
return PEAR ::throwError (" The auth mode: '$mode' is unknown" , null );
* Test whether we are connected or not.
* @return bool true or false
* @see Net_NNTP::connect()
* Selects a news group (issue a GROUP command to the server)
* @param string $newsgroup The newsgroup name
* @return mixed (array) Groups info on success or (object) pear_error on failure
$response_arr = $this->cmdGroup($newsgroup);
if (PEAR ::isError ($response_arr)) {
$this->_currentGroup = $response_arr;
// Deprecated / historical
$response_arr['min'] = & $response_arr['first'];
$response_arr['max'] = & $response_arr['last'];
$this->min = & $response_arr['min'];
$this->max = & $response_arr['max'];
* Fetches a list of all avaible newsgroups
* @return mixed (array) nested array with informations about existing newsgroups on success or (object) pear_error on failure
if (PEAR ::isError ($groups)) {
// Deprecated / historical
$groups[$k]['posting_allowed'] = & $groups[$k]['posting'];
// Get group descriptions
if (PEAR ::isError ($descriptions)) {
// Set known descriptions for groups
if (count($descriptions) > 0 ) {
foreach ($descriptions as $k=> $v) {
$groups[$k]['desc'] = $v;
* Fetch message header from message number $first to $last
* The format of the returned array is:
* $messages[message_id][header_name]
* @param integer $first first article to fetch
* @param integer $last last article to fetch
* @return mixed (array) nested array of message and there headers on success or (object) pear_error on failure
* @see Net_NNTP::getOverviewFormat()
* @see Net_NNTP::getReferencesOverview()
$overview = $this->cmdXOver($first. '-'. $last);
if (PEAR ::isError ($overview)) {
// {{{ getOverviewFormat()
* Returns a list of avaible headers which are send from newsserver to client for every news message
* @return mixed (array) header names on success or (object) pear_error on failure
* @see Net_NNTP::getOverview()
return $this->cmdListOverviewFMT ();
* Returns a list of avaible headers which are send from newsserver to client for every news message
* @return mixed (array) header names on success or (object) pear_error on failure
* @deprecated use getOverviewFormat() instead
// {{{ getReferencesOverview()
* Fetch a list of each message's reference header.
* @param integer $first first article to fetch
* @param integer $last last article to fetch
* @return mixed (array) nested array of references on success or (object) pear_error on failure
* @return mixed (array) nested array of message and there headers on success or (object) pear_error on failure
* @see Net_NNTP::getOverview()
$overview = $this->cmdXROver($first. '-'. $last);
if (PEAR ::isError ($overview)) {
* Post an article to a number of newsgroups.
* (Among the aditional headers you might think of adding could be:
* "NNTP-Posting-Host: <ip-of-author>", which should contain the IP-adress
* of the author of the post, so the message can be traced back to him.
* Or "Organization: <org>" which contain the name of the organization
* the post originates from)
* @param string $subject The subject of the post.
* @param string $newsgroup The newsgroup to post to.
* @param string $from Name + email-adress of sender.
* @param string $body The body of the post itself.
* @param optional string $aditional Aditional headers to send.
* @return mixed (string) server response on success or (object) pear_error on failure
function post($subject, $newsgroup, $from, $body, $aditional = '')
return $this->cmdPost($newsgroup, $subject, $body, $from, $aditional);
* Get an article (raw data)
* @param mixed $article Either the message-id or the message-number on the server of the article to fetch.
* @param bool $implode When true the result array is imploded to a string, defaults to true.
* @return mixed (array/string) The headers on success or (object) pear_error on failure
if (PEAR ::isError ($data)) {
* Get an article (deprecated)
* @param mixed $article Either the message-id or the message-number on the server of the article to fetch.
* @return mixed (string) The headers on success or (object) pear_error on failure
* @deprecated Use getArticleRaw() instead
* Get the headers of an article (raw data)
* @param mixed $article Either the (string) message-id or the (int) message-number on the server of the article to fetch.
* @param bool $implode When true the result array is imploded to a string, defaults to true.
* @return mixed (array/string) headers on success or (object) pear_error on failure
if (PEAR ::isError ($data)) {
* Get the headers of an article (deprecated)
* @param mixed $article Either the (string) message-id or the (int) message-number on the server of the article to fetch.
* @return mixed (string) headers on success or (object) pear_error on failure
* @deprecated Use getHeaderRaw() instead
* Get the body of an article (raw data)
* @param mixed $article Either the message-id or the message-number on the server of the article to fetch.
* @param bool $implode When true the result array is imploded to a string, defaults to true.
* @return mixed (array/string) headers on success or (object) pear_error on failure
if (PEAR ::isError ($data)) {
* Get the body of an article (deprecated)
* @param mixed $article Either the message-id or the message-number on the server of the article to fetch.
* @return mixed (string) headers on success or (object) pear_error on failure
* @deprecated Use getBodyRaw() instead
* Get the NNTP-server's internal date
* Get the date from the newsserver format of returned date:
* @param optional int $format
* @return mixed (mixed) date on success or (object) pear_error on failure
if (PEAR ::isError ($date)) {
return array ('y' => substr($date, 0 , 4 ), 'm' => substr($date, 4 , 2 ), 'd' => substr($date, 6 , 2 ));
* @return mixed (array) date on success or (object) pear_error on failure
* @deprecated Use getDate() instead
* Number of articles in currently selected group
* @see Net_NNTP::selectGroup()
return $this->_currentGroup['count'];
* Maximum article number in current group
* @return integer maximum
* @see Net_NNTP::selectGroup()
return $this->_currentGroup['last'];
* @return integer maximum
* @deprecated Use last() instead
* Minimum article number in current group
* @return integer minimum
* @see Net_NNTP::selectGroup()
return $this->_currentGroup['first'];
* @return integer minimum
* @deprecated Use first() instead
* Currently selected group
* @see Net_NNTP::selectGroup()
return $this->_currentGroup['group'];
* Get the headers of an article from the currently open connection, and parse them into a keyed array.
* @param mixed $article Either the (string) message-id or the (int) message-number on the server of the article to fetch.
* @return mixed (array) Assoc array with headers names as key on success or (object) pear_error on failure
if (PEAR ::isError ($headers)) {
return PEAR ::throwError ($headers);
// Loop through all header field lines
foreach ($headers as $field) {
// Separate header name and value
if (!preg_match('/([\S]+)\:\s*(.*)\s*/', $field, $matches)) {
// Add header to $return array
if (isset ($return[$name]) AND is_array($return[$name])) {
// The header name has already been used at least two times.
$return[$name][] = $value;
} elseif (isset ($return[$name])) {
// The header name has already been used one time -> change to nedted values.
$return[$name] = array ($return[$name], $value);
// The header name has not used until now.
* returns the response code of a newsserver command
* @param string $response newsserver answer
* @return integer response code
* Get data until a line with only a '.' in it is read and return data.
* @return mixed (string) data on success or (object) pear_error on failure
* @deprecated Use _getTextResponse() instead
return $this->_getTextResponse ();
return $this->_getData ();
* Issue a command to the NNTP server
* @param string $cmd The command to launch, ie: "ARTICLE 1004853"
* @return mixed (int) response code on success or (object) pear_error on failure
$code = $this->_sendCommand ($cmd);
if (PEAR ::isError ($code)) {
return PEAR ::throwError ($code);
return $code. ' '. $this->currentStatusResponse (). "\r\n";
Documentation generated on Mon, 11 Mar 2019 14:13:03 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|