NNTP.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914
  1. <?php
  2. //
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4 |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.0 of the PHP license, |
  9. // | that is bundled with this package in the file LICENSE, and is |
  10. // | available at through the world-wide-web at |
  11. // | http://www.php.net/license/2_02.txt. |
  12. // | If you did not receive a copy of the PHP license and are unable to |
  13. // | obtain it through the world-wide-web, please send a note to |
  14. // | license@php.net so we can mail you a copy immediately. |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Martin Kaltoft <martin@nitro.dk> |
  17. // | Tomas V.V.Cox <cox@idecnet.com> |
  18. // | Heino H. Gehlsen <heino@gehlsen.dk> |
  19. // +----------------------------------------------------------------------+
  20. //
  21. // $Id: NNTP.php,v 1.28 2003/10/10 20:37:27 heino Exp $
  22. require_once 'Net/NNTP/Protocol.php';
  23. /* NNTP Authentication modes */
  24. define('NET_NNTP_AUTHORIGINAL', 'original');
  25. define('NET_NNTP_AUTHSIMPLE', 'simple');
  26. define('NET_NNTP_AUTHGENERIC', 'generic');
  27. // Deprecated due to naming
  28. define('PEAR_NNTP_AUTHORIGINAL', NET_NNTP_AUTHORIGINAL);
  29. define('PEAR_NNTP_AUTHSIMPLE', NET_NNTP_AUTHSIMPLE);
  30. define('PEAR_NNTP_AUTHGENERIC', NET_NNTP_AUTHGENERIC);
  31. /**
  32. * The Net_NNTP class is an almost 100 % backward compatible
  33. * frontend class to the Net_NNTP_Protocol class.
  34. *
  35. * ATTENTION!!!
  36. * This class should NOT be used in new projects. It is meant
  37. * as a drop in replacement to the outdated v0.2, and uses
  38. * excatly the same protocol implementation as the new
  39. * Net_NNTP_Realtime class, but has a lot of deprecated
  40. * methods etc. While this class is still maintained, it is
  41. * officially dead...
  42. *
  43. * @author Martin Kaltoft <martin@nitro.dk>
  44. * @author Tomas V.V.Cox <cox@idecnet.com>
  45. * @author Heino H. Gehlsen <heino@gehlsen.dk>
  46. */
  47. class Net_NNTP extends Net_NNTP_Protocol
  48. {
  49. // {{{ properties
  50. /**
  51. * @var int
  52. * @access public
  53. * @deprecated use last() instead
  54. */
  55. var $max;
  56. /**
  57. * @var int
  58. * @access public
  59. * @deprecated use first() instead
  60. */
  61. var $min;
  62. /**
  63. * Used for storing information about the currently selected group
  64. *
  65. * @var array
  66. * @access private
  67. * @since 0.3
  68. */
  69. var $_currentGroup = null;
  70. // }}}
  71. // {{{ constructor
  72. /**
  73. * Constructor
  74. */
  75. function Net_NNTP()
  76. {
  77. parent::Net_NNTP_Protocol();
  78. }
  79. // }}}
  80. // {{{ connect()
  81. /**
  82. * Connect to the newsserver.
  83. *
  84. * The function currently allows automatic authentication via the three last parameters,
  85. * but this feature is to be considered depresated (use connectAuthenticated instead)
  86. *
  87. * In the future, this function will just be inherrited from the parent,
  88. * and thus the last three parameters will no longer be used to authenticate.
  89. *
  90. * @param optional string $host The adress of the NNTP-server to connect to.
  91. * @param optional int $port The port to connect to.
  92. * @param optional string $user Deprecated!
  93. * @param optional string $pass Deprecated!
  94. * @param optional string $authmode Deprecated!
  95. *
  96. * @return mixed (bool) true on success or (object) pear_error on failure
  97. * @access public
  98. * @see Net_NNTP::quit()
  99. * @see Net_NNTP::connectAuthenticated()
  100. * @see Net_NNTP::authenticate()
  101. */
  102. function connect($host = NET_NNTP_PROTOCOL_DEFAULT_HOST,
  103. $port = NET_NNTP_PROTOCOL_DEFAULT_PORT,
  104. $user = null,
  105. $pass = null,
  106. $authmode = NET_NNTP_AUTHORIGINAL)
  107. {
  108. // Currently this function just 'forwards' to connectAuthenticated().
  109. return $this->connectAuthenticated($user, $pass, $host, $port, $authmode);
  110. }
  111. // }}}
  112. // {{{ connectAuthenticated()
  113. /**
  114. * Connect to the newsserver, and authenticate. If no user/pass is specified, just connect.
  115. *
  116. * @param optional string $user The user name to authenticate with
  117. * @param optional string $pass The password
  118. * @param optional string $host The adress of the NNTP-server to connect to.
  119. * @param optional int $port The port to connect to.
  120. * @param optional string $authmode The authentication mode
  121. *
  122. * @return mixed (bool) true on success or (object) pear_error on failure
  123. * @access public
  124. * @since 0.3
  125. * @see Net_NNTP::connect()
  126. * @see Net_NNTP::authenticate()
  127. * @see Net_NNTP::quit()
  128. */
  129. function connectAuthenticated($user = null,
  130. $pass = null,
  131. $host = NET_NNTP_PROTOCOL_DEFAULT_HOST,
  132. $port = NET_NNTP_PROTOCOL_DEFAULT_PORT,
  133. $authmode = NET_NNTP_AUTHORIGINAL)
  134. {
  135. // Until connect() is changed, connect() is called directly from the parent...
  136. $R = parent::connect($host, $port);
  137. if (PEAR::isError($R)) {
  138. return $R;
  139. }
  140. // Authenticate if username is given
  141. if ($user != null) {
  142. $R = $this->authenticate($user, $pass, $authmode);
  143. if (PEAR::isError($R)) {
  144. return $R;
  145. }
  146. }
  147. return true;
  148. }
  149. // }}}
  150. // {{{ quit()
  151. /**
  152. * Close connection to the newsserver
  153. *
  154. * @access public
  155. * @see Net_NNTP::connect()
  156. */
  157. function quit()
  158. {
  159. return $this->cmdQuit();
  160. }
  161. // }}}
  162. // {{{ prepareConnection()
  163. /**
  164. * Connect to the newsserver, and issue a GROUP command
  165. * Once connection is prepared, we can only fetch articles from one group
  166. * at a time, to fetch from another group, a new connection has to be made.
  167. *
  168. * This is to avoid the GROUP command for every article, as it is very
  169. * ressource intensive on the newsserver especially when used for
  170. * groups with many articles.
  171. *
  172. * @param string $host The adress of the NNTP-server to connect to.
  173. * @param optional int $port the port-number to connect to, defaults to 119.
  174. * @param string $newsgroup The name of the newsgroup to use.
  175. * @param optional string $user The user name to authenticate with
  176. * @param optional string $pass The password
  177. * @param optional string $authmode The authentication mode
  178. *
  179. * @return mixed (bool) true on success or (object) pear_error on failure
  180. * @access public
  181. *
  182. * @deprecated Use connect() or connectAuthenticated() instead
  183. */
  184. function prepareConnection($host,
  185. $port = 119,
  186. $newsgroup,
  187. $user = null,
  188. $pass = null,
  189. $authmode = NET_NNTP_AUTHORIGINAL)
  190. {
  191. /* connect to the server */
  192. $R = $this->connect($host, $port, $user, $pass, $authmode);
  193. if ($this->isError($R)) {
  194. return $R;
  195. }
  196. /* issue a GROUP command */
  197. $R = $this->selectGroup($newsgroup);
  198. if ($this->isError($R)) {
  199. return $R;
  200. }
  201. return true;
  202. }
  203. // }}}
  204. // {{{ authenticate()
  205. /**
  206. * Auth process (not yet standarized but used any way)
  207. * http://www.mibsoftware.com/userkt/nntpext/index.html
  208. *
  209. * @param string $user The user name
  210. * @param optional string $pass The password if needed
  211. * @param optional string $mode Authinfo type: original, simple, generic
  212. *
  213. * @return mixed (bool) true on success or (object) pear_error on failure
  214. * @access public
  215. * @since 0.3
  216. * @see Net_NNTP::connect()
  217. */
  218. function authenticate($user, $pass, $mode = NET_NNTP_AUTHORIGINAL)
  219. {
  220. // Username is a must...
  221. if ($user == null) {
  222. return $this->throwError('No username supplied', null);
  223. }
  224. // Use selected authentication method
  225. switch ($mode) {
  226. case NET_NNTP_AUTHORIGINAL:
  227. return $this->cmdAuthinfo($user, $pass);
  228. break;
  229. case NET_NNTP_AUTHSIMPLE:
  230. return $this->cmdAuthinfoSimple($user, $pass);
  231. break;
  232. case NET_NNTP_AUTHGENERIC:
  233. return $this->cmdAuthinfoGeneric($user, $pass);
  234. break;
  235. default:
  236. return $this->throwError("The auth mode: '$mode' is unknown", null);
  237. }
  238. }
  239. // }}}
  240. // {{{ isConnected()
  241. /**
  242. * Test whether we are connected or not.
  243. *
  244. * @return bool true or false
  245. * @access public
  246. * @see Net_NNTP::connect()
  247. * @see Net_NNTP::quit()
  248. */
  249. function isConnected()
  250. {
  251. return parent::isConnected();
  252. }
  253. // }}}
  254. // {{{ selectGroup()
  255. /**
  256. * Selects a news group (issue a GROUP command to the server)
  257. *
  258. * @param string $newsgroup The newsgroup name
  259. *
  260. * @return mixed (array) Groups info on success or (object) pear_error on failure
  261. * @access public
  262. * @see group()
  263. * @see count()
  264. * @see first()
  265. * @see last()
  266. */
  267. function selectGroup($newsgroup)
  268. {
  269. $response_arr = $this->cmdGroup($newsgroup);
  270. if (PEAR::isError($response_arr)) {
  271. return $response_arr;
  272. }
  273. $this->_currentGroup = $response_arr;
  274. // Deprecated / historical
  275. $response_arr['min'] =& $response_arr['first'];
  276. $response_arr['max'] =& $response_arr['last'];
  277. $this->min =& $response_arr['min'];
  278. $this->max =& $response_arr['max'];
  279. return $response_arr;
  280. }
  281. // }}}
  282. // {{{ getGroups()
  283. /**
  284. * Fetches a list of all avaible newsgroups
  285. *
  286. * @return mixed (array) nested array with informations about existing newsgroups on success or (object) pear_error on failure
  287. * @access public
  288. */
  289. function getGroups()
  290. {
  291. // Get groups
  292. $groups = $this->cmdList();
  293. if (PEAR::isError($groups)) {
  294. return $groups;
  295. }
  296. // Deprecated / historical
  297. foreach (array_keys($groups) as $k) {
  298. $groups[$k]['posting_allowed'] =& $groups[$k][3];
  299. }
  300. // Get group descriptions
  301. $descriptions = $this->cmdListNewsgroups();
  302. if (PEAR::isError($descriptions)) {
  303. return $descriptions;
  304. }
  305. // Set known descriptions for groups
  306. if (count($descriptions) > 0) {
  307. foreach ($descriptions as $k=>$v) {
  308. $groups[$k]['desc'] = $v;
  309. }
  310. }
  311. return $groups;
  312. }
  313. // }}}
  314. // {{{ getOverview()
  315. /**
  316. * Fetch message header from message number $first to $last
  317. *
  318. * The format of the returned array is:
  319. * $messages[message_id][header_name]
  320. *
  321. * @param integer $first first article to fetch
  322. * @param integer $last last article to fetch
  323. *
  324. * @return mixed (array) nested array of message and there headers on success or (object) pear_error on failure
  325. * @access public
  326. * @see Net_NNTP::getOverviewFormat()
  327. * @see Net_NNTP::getReferencesOverview()
  328. */
  329. function getOverview($first, $last)
  330. {
  331. $overview = $this->cmdXOver($first, $last);
  332. if (PEAR::isError($overview)) {
  333. return $overview;
  334. }
  335. return $overview;
  336. }
  337. // }}}
  338. // {{{ getOverviewFormat()
  339. /**
  340. * Returns a list of avaible headers which are send from newsserver to client for every news message
  341. *
  342. * @return mixed (array) header names on success or (object) pear_error on failure
  343. * @access public
  344. * @see Net_NNTP::getOverview()
  345. */
  346. function getOverviewFormat()
  347. {
  348. return $this->cmdListOverviewFMT();
  349. }
  350. // }}}
  351. // {{{ getOverviewFmt()
  352. /**
  353. * Returns a list of avaible headers which are send from newsserver to client for every news message
  354. *
  355. * @return mixed (array) header names on success or (object) pear_error on failure
  356. * @access public
  357. * @deprecated use getOverviewFormat() instead
  358. */
  359. function getOverviewFmt()
  360. {
  361. return $this->getOverviewFormat();
  362. }
  363. // }}}
  364. // {{{ getReferencesOverview()
  365. /**
  366. * Fetch a list of each message's reference header.
  367. *
  368. * @param integer $first first article to fetch
  369. * @param integer $last last article to fetch
  370. *
  371. * @return mixed (array) nested array of references on success or (object) pear_error on failure
  372. *
  373. * @return mixed (array) nested array of message and there headers on success or (object) pear_error on failure
  374. * @access public
  375. * @see Net_NNTP::getOverview()
  376. */
  377. function getReferencesOverview($first, $last)
  378. {
  379. $overview = $this->cmdXROver($first, $last);
  380. if (PEAR::isError($overview)) {
  381. return $overview;
  382. }
  383. return $overview;
  384. }
  385. // }}}
  386. // {{{ post()
  387. /**
  388. * Post an article to a number of newsgroups.
  389. *
  390. * (Among the aditional headers you might think of adding could be:
  391. * "NNTP-Posting-Host: <ip-of-author>", which should contain the IP-adress
  392. * of the author of the post, so the message can be traced back to him.
  393. * Or "Organization: <org>" which contain the name of the organization
  394. * the post originates from)
  395. *
  396. * @param string $subject The subject of the post.
  397. * @param string $newsgroup The newsgroup to post to.
  398. * @param string $from Name + email-adress of sender.
  399. * @param string $body The body of the post itself.
  400. * @param optional string $aditional Aditional headers to send.
  401. *
  402. * @return mixed (string) server response on success or (object) pear_error on failure
  403. * @access public
  404. */
  405. function post($subject, $newsgroup, $from, $body, $aditional = '')
  406. {
  407. return $this->cmdPost($newsgroup, $subject, $body, $from, $aditional);
  408. }
  409. // }}}
  410. // {{{ getArticleRaw()
  411. /**
  412. * Get an article (raw data)
  413. *
  414. * @param mixed $article Either the message-id or the message-number on the server of the article to fetch.
  415. * @param bool $implode When true the result array is imploded to a string, defaults to true.
  416. *
  417. * @return mixed (array/string) The headers on success or (object) pear_error on failure
  418. * @access public
  419. * @since 0.3
  420. * @see getHeaderRaw()
  421. * @see getBodyRaw()
  422. */
  423. function getArticleRaw($article, $implode = true)
  424. {
  425. $data = $this->cmdArticle($article);
  426. if (PEAR::isError($data)) {
  427. return $data;
  428. }
  429. if ($implode == true) {
  430. $data = implode("\r\n", $data);
  431. }
  432. return $data;
  433. }
  434. // }}}
  435. // {{{ getArticle()
  436. /**
  437. * Get an article (deprecated)
  438. *
  439. * @param mixed $article Either the message-id or the message-number on the server of the article to fetch.
  440. *
  441. * @return mixed (string) The headers on success or (object) pear_error on failure
  442. * @access public
  443. * @deprecated Use getArticleRaw() instead
  444. */
  445. function getArticle($article)
  446. {
  447. return $this->getArticleRaw($article);
  448. }
  449. // }}}
  450. // {{{ getHeaderRaw()
  451. /**
  452. * Get the headers of an article (raw data)
  453. *
  454. * @param mixed $article Either the (string) message-id or the (int) message-number on the server of the article to fetch.
  455. * @param bool $implode When true the result array is imploded to a string, defaults to true.
  456. *
  457. * @return mixed (array/string) headers on success or (object) pear_error on failure
  458. * @access public
  459. * @since 0.3
  460. * @see getArticleRaw()
  461. * @see getBodyRaw()
  462. */
  463. function getHeaderRaw($article, $implode = true)
  464. {
  465. $data = $this->cmdHead($article);
  466. if (PEAR::isError($data)) {
  467. return $data;
  468. }
  469. if ($implode == true) {
  470. $data = implode("\r\n", $data);
  471. }
  472. return $data;
  473. }
  474. // }}}
  475. // {{{ getHeaders()
  476. /**
  477. * Get the headers of an article (deprecated)
  478. *
  479. * @param mixed $article Either the (string) message-id or the (int) message-number on the server of the article to fetch.
  480. *
  481. * @return mixed (string) headers on success or (object) pear_error on failure
  482. * @access public
  483. * @deprecated Use getHeaderRaw() instead
  484. */
  485. function getHeaders($article)
  486. {
  487. return $this->getHeaderRaw($article);
  488. }
  489. // }}}
  490. // {{{ getBodyRaw()
  491. /**
  492. * Get the body of an article (raw data)
  493. *
  494. * @param mixed $article Either the message-id or the message-number on the server of the article to fetch.
  495. * @param bool $implode When true the result array is imploded to a string, defaults to true.
  496. *
  497. * @return mixed (array/string) headers on success or (object) pear_error on failure
  498. * @access public
  499. * @since 0.3
  500. * @see getHeaderRaw()
  501. * @see getArticleRaw()
  502. */
  503. function getBodyRaw($article, $implode = true)
  504. {
  505. $data = $this->cmdBody($article);
  506. if (PEAR::isError($data)) {
  507. return $data;
  508. }
  509. if ($implode == true) {
  510. $data = implode("\r\n", $data);
  511. }
  512. return $data;
  513. }
  514. // }}}
  515. // {{{ getBody()
  516. /**
  517. * Get the body of an article (deprecated)
  518. *
  519. * @param mixed $article Either the message-id or the message-number on the server of the article to fetch.
  520. *
  521. * @return mixed (string) headers on success or (object) pear_error on failure
  522. * @access public
  523. * @deprecated Use getBodyRaw() instead
  524. */
  525. function getBody($article)
  526. {
  527. return $this->getBodyRaw($article);
  528. }
  529. // }}}
  530. // {{{ getGroupArticles()
  531. /**
  532. * Experimental
  533. *
  534. * @access public
  535. * @since 0.3
  536. */
  537. function getGroupArticles($newsgroup)
  538. {
  539. return $this->cmdListgroup($newsgroup);
  540. }
  541. // }}}
  542. // {{{ getNewGroups()
  543. /**
  544. * Experimental
  545. *
  546. * @access public
  547. * @since 0.3
  548. */
  549. function getNewGroups($time)
  550. {
  551. switch (gettype($time)) {
  552. case 'integer':
  553. break;
  554. case 'string':
  555. $time = (int) strtotime($time);
  556. break;
  557. default:
  558. return $this->throwError('');
  559. }
  560. return $this->cmdNewgroups($time);
  561. }
  562. // }}}
  563. // {{{ getNewNews()
  564. /**
  565. * Experimental
  566. *
  567. * @access public
  568. * @since 0.3
  569. */
  570. function getNewNews($time, $newsgroups = '*')
  571. {
  572. switch (gettype($time)) {
  573. case 'integer':
  574. break;
  575. case 'string':
  576. $time = (int) strtotime($time);
  577. break;
  578. default:
  579. return $this->throwError('UPS...');
  580. }
  581. return $this->cmdNewnews($time, $newsgroups);
  582. }
  583. // }}}
  584. // {{{ getDate()
  585. /**
  586. * Get the NNTP-server's internal date
  587. *
  588. * Get the date from the newsserver format of returned date:
  589. *
  590. * @param optional int $format
  591. * - 0: $date - timestamp
  592. * - 1: $date['y'] - year
  593. * $date['m'] - month
  594. * $date['d'] - day
  595. *
  596. * @return mixed (mixed) date on success or (object) pear_error on failure
  597. * @access public
  598. * @since 0.3
  599. */
  600. function getDate($format = 1)
  601. {
  602. $date = $this->cmdDate();
  603. if (PEAR::isError($date)) {
  604. return $date;
  605. }
  606. switch ($format) {
  607. case 1:
  608. return array('y' => substr($date, 0, 4), 'm' => substr($date, 4, 2), 'd' => substr($date, 6, 2));
  609. break;
  610. case 0:
  611. default:
  612. return $date;
  613. break;
  614. }
  615. }
  616. // }}}
  617. // {{{ date()
  618. /**
  619. * @return mixed (array) date on success or (object) pear_error on failure
  620. * @access public
  621. *
  622. * @deprecated Use getDate() instead
  623. */
  624. function date()
  625. {
  626. return $this->getDate();
  627. }
  628. // }}}
  629. // {{{ count()
  630. /**
  631. * Number of articles in currently selected group
  632. *
  633. * @return integer count
  634. * @access public
  635. * @since 0.3
  636. * @see Net_NNTP::selectGroup()
  637. * @see Net_NNTP::group()
  638. * @see Net_NNTP::first()
  639. * @see Net_NNTP::last()
  640. */
  641. function count()
  642. {
  643. return $this->_currentGroup['count'];
  644. }
  645. // }}}
  646. // {{{ last()
  647. /**
  648. * Maximum article number in current group
  649. *
  650. * @return integer maximum
  651. * @access public
  652. * @since 0.3
  653. * @see Net_NNTP::selectGroup()
  654. * @see Net_NNTP::group()
  655. * @see Net_NNTP::first()
  656. * @see Net_NNTP::count()
  657. */
  658. function last()
  659. {
  660. return $this->_currentGroup['last'];
  661. }
  662. // }}}
  663. // {{{ max()
  664. /**
  665. * @return integer maximum
  666. * @access public
  667. *
  668. * @deprecated Use last() instead
  669. */
  670. function max()
  671. {
  672. return $this->last();
  673. }
  674. // }}}
  675. // {{{ first()
  676. /**
  677. * Minimum article number in current group
  678. *
  679. * @return integer minimum
  680. * @access public
  681. * @since 0.3
  682. * @see Net_NNTP::selectGroup()
  683. * @see Net_NNTP::group()
  684. * @see Net_NNTP::last()
  685. * @see Net_NNTP::count()
  686. */
  687. function first()
  688. {
  689. return $this->_currentGroup['first'];
  690. }
  691. // }}}
  692. // {{{ min()
  693. /**
  694. * @return integer minimum
  695. * @access public
  696. *
  697. * @deprecated Use first() instead
  698. */
  699. function min()
  700. {
  701. return $this->first();
  702. }
  703. // }}}
  704. // {{{ group()
  705. /**
  706. * Currently selected group
  707. *
  708. * @return string group
  709. * @access public
  710. * @since 0.3
  711. * @see Net_NNTP::selectGroup()
  712. * @see Net_NNTP::first()
  713. * @see Net_NNTP::last()
  714. * @see Net_NNTP::count()
  715. */
  716. function group()
  717. {
  718. return $this->_currentGroup['group'];
  719. }
  720. // }}}
  721. // {{{ splitHeaders()
  722. /**
  723. * Get the headers of an article from the currently open connection, and parse them into a keyed array.
  724. *
  725. * @param mixed $article Either the (string) message-id or the (int) message-number on the server of the article to fetch.
  726. *
  727. * @return mixed (array) Assoc array with headers names as key on success or (object) pear_error on failure
  728. * @access public
  729. */
  730. function splitHeaders($article)
  731. {
  732. // Retrieve headers
  733. $headers = $this->getHeaderRaw($article, false);
  734. if (PEAR::isError($headers)) {
  735. return $this->throwError($headers);
  736. }
  737. $return = array();
  738. // Loop through all header field lines
  739. foreach ($headers as $field) {
  740. // Separate header name and value
  741. if (!preg_match('/([\S]+)\:\s*(.*)\s*/', $field, $matches)) {
  742. // Fail...
  743. }
  744. $name = $matches[1];
  745. $value = $matches[2];
  746. unset($matches);
  747. // Add header to $return array
  748. if (isset($return[$name]) AND is_array($return[$name])) {
  749. // The header name has already been used at least two times.
  750. $return[$name][] = $value;
  751. } elseif (isset($return[$name])) {
  752. // The header name has already been used one time -> change to nedted values.
  753. $return[$name] = array($return[$name], $value);
  754. } else {
  755. // The header name has not used until now.
  756. $return[$name] = $value;
  757. }
  758. }
  759. return $return;
  760. }
  761. // }}}
  762. // {{{ responseCode()
  763. /**
  764. * returns the response code of a newsserver command
  765. *
  766. * @param string $response newsserver answer
  767. *
  768. * @return integer response code
  769. * @access public
  770. *
  771. * @deprecated
  772. */
  773. function responseCode($response)
  774. {
  775. $parts = explode(' ', ltrim($response), 2);
  776. return (int) $parts[0];
  777. }
  778. // }}}
  779. // {{{ _getData()
  780. /**
  781. * Get data until a line with only a '.' in it is read and return data.
  782. *
  783. * @return mixed (string) data on success or (object) pear_error on failure
  784. * @access private
  785. *
  786. * @deprecated Use _getTextResponse() instead
  787. */
  788. function _getData()
  789. {
  790. return $this->_getTextResponse();
  791. }
  792. // }}}
  793. // {{{ command()
  794. /**
  795. * Issue a command to the NNTP server
  796. *
  797. * @param string $cmd The command to launch, ie: "ARTICLE 1004853"
  798. *
  799. * @return mixed (int) response code on success or (object) pear_error on failure
  800. * @access public
  801. */
  802. function command($cmd)
  803. {
  804. return $this->_sendCommand($cmd);
  805. }
  806. // }}}
  807. }
  808. ?>