Giter Site home page Giter Site logo

php-nntp's Introduction

NNTP

Client for communicating with servers throught the Network News Transfer Protocol (NNTP) protocol.

Latest Stable Version Build Status Scrutinizer Code Quality Code Coverage StyleCI

Installation

The recommended way to install the library is through composer.

composer require rvdv/nntp:^0.9.0

NNTP?

NNTP specifies a protocol for the distribution, inquiry, retrieval, and posting of news articles using a reliable stream (such as TCP) server-client model. NNTP is designed so that news articles need only be stored on one (presumably central) host, and subscribers on other hosts attached to the LAN may read news articles using stream connections to the news host.

-- RFC Abstract (source)

Usage

Here is an example that fetches 100 articles from the php.doc of the news.php.net server:

<?php

use Rvdv\Nntp\Connection\Connection;
use Rvdv\Nntp\Client;

$connection = new Connection('news.php.net', 119);
$client = new Client($connection);

$client->connect();

$overviewFormat = $client->overviewFormat();
$group = $client->group('php.doc');
$articles = $client->xover($group['first'], $group['first'] + 100, $overviewFormat);

// Process the articles further...

$client->disconnect();

Tests

To run the test suite, you need install the dependencies via composer, then run PHPUnit.

$ composer install
$ php vendor/bin/phpunit

License

MIT © Robin van der Vleuten

php-nntp's People

Contributors

anahkiasen avatar ctrl-f5 avatar elabz avatar kissifrot avatar mnapoli avatar robinvdvleuten avatar scrutinizer-auto-fixer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-nntp's Issues

Article command?

I didn't find a way to get an article's contents from the package, through the ARTICLE command, is it not possible without writing my own implementation?

listGroups

I'm not sure (at least at my private news server this issue exists), but for me the listGroups function does not work, because the called response method is 'onInformationFollows' and not 'onListFollows'.

is this a bug or only an issue on the news server?

Getting InvalidArgumentException with overviewFormat

I'm using a custom command to fetch the BODY of an article:

class Body extends Command
{
    /**
     * @var integer
     */
    const BODY_RECEIVED = 222;

    /**
     * @var integer
     */
    const NO_SUCH_ARTICLE = 423;

    /**
     * @var string
     */
    private $article;

    /**
     * Constructor
     *
     * @param string $article The name of the group.
     */
    public function __construct($article)
    {
        $this->article = $article;

        parent::__construct([], true);
    }

    /**
     * @return string
     */
    public function execute()
    {
        return sprintf('BODY %s', $this->article);
    }

    /**
     * @return array
     */
    public function getExpectedResponseCodes()
    {
        return [
            self::BODY_RECEIVED   => 'onBodyReceived',
            self::NO_SUCH_ARTICLE => 'onArticleNotFound',
        ];
    }

    /**
     * @param MultiLineResponseInterface $response
     */
    public function onBodyReceived(MultiLineResponseInterface $response)
    {
        // Convert to array and remove encoding lines
        $body = (array) $response->getLines();
        $body = implode(PHP_EOL, $body);

        $this->result = trim($body);
    }

    /**
     * @param ResponseInterface $response
     */
    public function onArticleNotFound(ResponseInterface $response)
    {
        $this->result = $response->getMessage();
    }
}

However when I call $client->overviewFormat()->getResult() after calling this command I inevitably get the following:

PHP Fatal error:  Uncaught exception 'Rvdv\Nntp\Exception\InvalidArgumentException' with message 'Invalid response given: "> >"' in /Users/anahkiasen/Sites/anahkiasen/rfc-history/vendor/rvdv/nntp/src/Response/Response.php:62
Stack trace:
#0 /Users/anahkiasen/Sites/anahkiasen/rfc-history/vendor/rvdv/nntp/src/Connection/Connection.php(157): Rvdv\Nntp\Response\Response::createFromString('> >\r\n')
#1 /Users/anahkiasen/Sites/anahkiasen/rfc-history/vendor/rvdv/nntp/src/Connection/Connection.php(108): Rvdv\Nntp\Connection\Connection->getResponse()
#2 /Users/anahkiasen/Sites/anahkiasen/rfc-history/vendor/rvdv/nntp/src/Client.php(171): Rvdv\Nntp\Connection\Connection->sendCommand(Object(Rvdv\Nntp\Command\OverviewFormatCommand))
#3 /Users/anahkiasen/Sites/anahkiasen/rfc-history/vendor/rvdv/nntp/src/Client.php(131): Rvdv\Nntp\Client->sendCommand(Object(Rvdv\Nntp\Command\OverviewFormatCommand))
#4 /Users/anahkiasen/Sites/anahkiasen/rfc-history/test.php(15): Rvdv\Nntp\Client->overviewFormat()
#5 {main}
  thrown in /Users/anahkiasen/Sites/anahkiasen/rfc-history/vendor/rvdv/nntp/src/Response/Response.php on line 62

This code per example fails every time:

<?php
use History\Services\Internals\Commands\Body;
use Rvdv\Nntp\Client;
use Rvdv\Nntp\Connection\Connection;

require 'vendor/autoload.php';

$connection = new Connection('news.php.net', 119);
$client     = new Client($connection);
$client->connect();

$client->group('php.internals');
$article = $client->sendCommand(new Body(88855))->getResult();
$format  = $client->overviewFormat()->getResult();

While the contents is nonetheless properly fetched and $article holds the right value.

Error when I try to connect with the code exemple (Laravel 5)

Hi,

My name is Adrien, and I have some problems with your library PHP-NNTP. I am using your library with the framework Laravel 5.

When I use your library, I have the same error all time : 'Invalid response given: response string should be terminated by \r\n'. I do not know why I have this error.

I am using you exemple to connect with the server of php news. I do a copy/paste with your exemple code but I always have this error.

Can you explain me with i have this error all time ?

Regards Adrien.

My code is :

//Code in my controller

/**
**  This is the route when I try to call my function
**  Route::get('/test', 'MainController@index');
**/

public function index()
{
    $connection = new Connection('news.php.net', 119);
    $client = new Client($connection);

    $client->connect();  //Error here 

    $command = $client->overviewFormat();
    $overviewFormat = $command->getResult();

    $command = $client->group('php.doc');
    $group = $command->getResult();

    $command = $client->xover($group['first'], $group['first'] + 100, $overviewFormat);
    $articles = $command->getResult();

    dd($articles); //laravel var_dump and die

    $client->disconnect();
    return false;
}

Best regards

Usable for http://externals.io?

Hi! I'm currently considering moving http://externals.io from using IMAP (to fetch the mailing list's emails) to using NNTP. I figured that before jumping into it it might be better to ask your opinion: do you think your library is ready/stable and could cover that need? (i.e. getting the list of posts by date, fetching the thread of message, fetching each message individually)

One important feature in externals.io is that messages are displayed as thread (for example): http://externals.io/thread/539 To do that I use a feature in IMAP that allows to know which emails answers to which other email (so I can rebuild the tree). Is that possible with NNTP?

Thanks for your advice

Ouch what happened?

My project just upgraded to 0.7 and now times out on trying to connect to the news server. I even switched it back to plain 119 and not ssl to see if it was an issue there. No luck :(

I can access the server and port and see it's open using nmap.

 [ErrorException]
  stream_socket_client(): unable to connect to tcp://newsreader60.eweka.nl:11
  9 (Connection timed out)

and the laravel log:

[2016-02-16 21:53:53] local.ERROR: exception 'ErrorException' with message 'stream_socket_client(): unable to connect to tcp://newsreader60.eweka.nl:119 (Connection timed out)' in /var/www/Nassau/vendor/rvdv/nntp/src/Socket/Socket.php:46
Stack trace:
#0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'stream_socket_c...', '/var/www/Nassau...', 46, Array)
#1 /var/www/Nassau/vendor/rvdv/nntp/src/Socket/Socket.php(46): stream_socket_client('tcp://newsreade...', 110, 'Connection time...', 0, 4)
#2 /var/www/Nassau/vendor/rvdv/nntp/src/Connection/Connection.php(81): Rvdv\Nntp\Socket\Socket->connect('tcp://newsreade...', NULL)
#3 /var/www/Nassau/vendor/rvdv/nntp/src/Client.php(54): Rvdv\Nntp\Connection\Connection->connect()
#4 /var/www/Nassau/vendor/rvdv/nntp/src/Client.php(94): Rvdv\Nntp\Client->connect()
Starting Nmap 6.47 ( http://nmap.org ) at 2016-02-16 22:01 GMT
Nmap scan report for newsreader60.eweka.nl (81.171.92.205)
Host is up (0.035s latency).
PORT    STATE SERVICE
119/tcp open  nntp
563/tcp open  snews

Nmap done: 1 IP address (1 host up) scanned in 0.11 seconds

Blank lines in the body of messages are missing

Hi there, bumping on #28 -> I'm trying to use NNTP instead of IMAP for https://externals.io

I've got the whole thing working but I'm still stuck with a big issue: whether I get the body of messages using the ARTICLE or BODY command, all blank lines are missing (i.e. there are no blank lines).

Because of that:

  • with the ARTICLE command I cannot parse the content (a blank line is supposed to separate the headers and the body)
  • because of the problem above I ended up using the BODY command, but then the body is missing all the blank lines that users put in there… Because of that all the formatting is broken

I've read bits of the NNTP specs and it seems blank lines are allowed in the BODY, so there shouldn't be any issue.

Would you have any idea why I'm getting this issue? I've debugged with xdebug and it seems in the multiline response there are no empty lines received through the socket… I'm really lost since I'm not familiar with NNTP.

@Anahkiasen you've used that library for https://github.com/madewithlove/why-cant-we-have-nice-things (which by the way is a huge help, thanks for that) and it seems you don't have that problem: you also use the https://github.com/php-mime-mail-parser/php-mime-mail-parser library and it seems to parse the messages correctly. Am I missing something?

Here is an example of a response to a BODY command (click to expand)
Newsgroups: php.internals
Path: news.php.net
Xref: news.php.net php.internals:99668
Return-Path: <[email protected]>
Mailing-List: contact [email protected]; run by ezmlm
Delivered-To: mailing list [email protected]
Received: (qmail 83047 invoked from network); 29 Jun 2017 02:50:28 -0000
Received: from unknown (HELO lists.php.net) (127.0.0.1)
  by localhost with SMTP; 29 Jun 2017 02:50:28 -0000
Authentication-Results: pb1.pair.com [email protected]; spf=pass; sender-id=pass
Authentication-Results: pb1.pair.com [email protected]; sender-id=pass
Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.44 as permitted sender)
X-PHP-List-Original-Sender: [email protected]
X-Host-Fingerprint: 209.85.214.44 mail-it0-f44.google.com  
Received: from [209.85.214.44] ([209.85.214.44:36377] helo=mail-it0-f44.google.com)
	by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP
	id 9F/C6-07609-1FA64595 for <[email protected]>; Wed, 28 Jun 2017 22:50:26 -0400
Received: by mail-it0-f44.google.com with SMTP id m68so39337669ith.1
        for <[email protected]>; Wed, 28 Jun 2017 19:50:25 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=mime-version:sender:in-reply-to:references:from:date:message-id
         :subject:to:cc;
        bh=yolEbnwwc16CZ+8MEm4q8yUIIqtogjDB8+zfsnNDVOM=;
        b=qc+LgNNak0l4zz97gtCLNOUBF7EwYG960ai7RKbBkdCe5cvR9MIZW0oU6V/p+iJF/Z
         rP4vFoNhhlCphQ6b57xUPHWpdpRBXDymi7l9mRDKiwMP9kBEjc1Q+jm1enMfUWBEyZ2n
         CLNWgTHUB5pIusYa4G2iKa3V8G+p4+bsjV+vKxm6W2Mfkw/dZxTvqExZocZSQWA364l9
         2cD7y9HweXZ/7kpFom/39MyLb+/GMdug9c+xXjSk7sB8BrAwLClsMmp98bYWoGR3yPhB
         Y7msD1sC/FkxZzp73G7xaojEkWNN8+wi80ElcEDhq0ascZX6Tf4xyNoYyg0i8twoKNGG
         o7ug==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:sender:in-reply-to:references:from
         :date:message-id:subject:to:cc;
        bh=yolEbnwwc16CZ+8MEm4q8yUIIqtogjDB8+zfsnNDVOM=;
        b=aDn589ePcohEanNE8GQvOXv93+pqgGPTWl0E7jFB8RXL/IbY3JGgrhmKk20jJnFsQr
         WepLy62lFxliPLzNQtyRbCAFCwD3QeTX5TbbSi1kZL4Eq2kqBlAL/JYwWFrUqsZJywJG
         UHpInqZqIvdzVaD0widWxgwnZDJ+PJp7UDR1naFg8/VWbDDr69LX6bej86NXBjh4C7me
         VIk26qlb6D9ipsJxkRxHx6kQ2EYC2D2ZD0M3GXVknU7S94+S8fsAXvvMAxnCtFV8Sqho
         IYrj6BStmrnLgyssl5JjAlCNn5c3Vbp+6MpesrQE5NSE3cDuNwKoHciGEJtTochsmmvJ
         5qnQ==
X-Gm-Message-State: AKS2vOxle1I4KlPmdWlJjNlNmE+1QHc/jtP9XIa6pbUVxwaTpf9jsfos
	zDjL3OD5+o6sP86Tougp/Rmgr3ayEg==
X-Received: by 10.36.74.195 with SMTP id k186mr11319335itb.63.1498704622975;
 Wed, 28 Jun 2017 19:50:22 -0700 (PDT)
MIME-Version: 1.0
Sender: [email protected]
Received: by 10.107.150.196 with HTTP; Wed, 28 Jun 2017 19:50:22 -0700 (PDT)
In-Reply-To: <CAEsg9X3EbgYiMdA8eUV1usKBTfJSbiJFG7E7mU4-hBRaAP+uyg@mail.gmail.com>
References: <CAEsg9X0sJ=JYxHfAs6a2Pp4Oymtkqi+JcDfX2+u4MP_pZTK9NA@mail.gmail.com>
 <CAJW__o3ynh3C=CBxD4LaLyE9DsLPhBExyvCgtabvn4cYuz4Vxg@mail.gmail.com> <CAEsg9X3EbgYiMdA8eUV1usKBTfJSbiJFG7E7mU4-hBRaAP+uyg@mail.gmail.com>
Date: Thu, 29 Jun 2017 04:50:22 +0200
X-Google-Sender-Auth: -jBVE1Rz7tCTbE6rKVbwm0xtjB4
Message-ID: <CAJW__o1inEjDPpF3Fz=0DdO7gBc2T9e=8t8iKb3E8FgWtBdodA@mail.gmail.com>
To: David Rodrigues <[email protected]>
Cc: PHP Internals <[email protected]>
Content-Type: text/plain; charset="UTF-8"
Subject: Re: [PHP-DEV] Final variables
From: [email protected] (Kalle Sommer Nielsen)
Hi
2017-06-28 20:46 GMT+02:00 David Rodrigues <[email protected]>:
> The "final" keyworks make a "local scope" variable value "blocked to
> rewrite" after instantiate it.
> Okay, it sounds like a "const", and it is, but "not as we known it".
I get that, but I still don't understand why you would forcefully need
it to be a variable still then if you know the value is gonna be
constant, of course besides global visibility or in iterations
-- 
regards,
Kalle Sommer Nielsen
[email protected]

This is the same message as displayed on the official UI: http://news.php.net/php.internals/99668

capture d ecran 2017-07-01 a 16 21 22

As you can see, there are blank lines here.

There are also blank lines when fetching the email (that's what I do in the current version of externals.io) : https://externals.io/thread/980#email-15703
And here is the source of the email: https://externals.io/email/15703/source

So it seems to be an issue very specific to NNTP…

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.