#nntp #usenet #api-bindings

rek2_nntp

This is a Rust library that provides a way to interact with NNTP servers, compliant with RFC 3977 and RFC 4643

6 releases

0.1.5 Oct 1, 2023
0.1.4 Oct 1, 2023
0.1.1 Sep 26, 2023

#696 in Network programming

41 downloads per month

GPL-3.0-or-later

17KB
263 lines

ReK2 NNTP RFC4643 RFC3977 Library

This is a Rust library that provides a way to interact with NNTP servers, compliant with RFC 3977 and RFC 4643.

Features

  • Article Posting
  • Newsgroup Listing
  • Article Reading from a Group
  • Authentication (TLS/SSL)

Installation

Add the following to your Cargo.toml:

[dependencies]
rek2_nntp = "0.1.3"  # Replace with the actual version

Run cargo build to build the dependencies.

Usage

Importing the Library

First, add the following import to your code:

extern crate rek2_nntp;

Authentication

To authenticate, use the authenticate function:

use rek2_nntp::authenticate;

// Example of how to authenticate using the library
let result = authenticate("host.com", "username", "password").await;
match result {
    Ok(connection) => {
        // Do something with the authenticated connection
    }
    Err(err) => {
        println!("Failed to authenticate: {}", err);
    }
}

Listing Newsgroups

To list newsgroups, use the list_newsgroups function:

use rek2_nntp::list_newsgroups;

let result = list_newsgroups(&mut authenticated_connection).await;
match result {
    Ok(newsgroups) => {
        for newsgroup in newsgroups {
            println!("Newsgroup: {}", newsgroup.name);
        }
    }
    Err(err) => {
        println!("Failed to list newsgroups: {}", err);
    }
}

Reading from a Group

To read articles from a newsgroup:

use rek2_nntp::read_from_group;

let result = read_from_group(&mut authenticated_connection, "group.name", None).await;
match result {
    Ok(articles) => {
        for article in articles {
            println!("Article: {}", article.header);
        }
    }
    Err(err) => {
        println!("Failed to read articles: {}", err);
    }
}

Posting to a Group

To post an article to a newsgroup:

use rek2_nntp::post_to_group;
use rek2_nntp::Article;

let article = Article {
    from: "from@example.com".to_string(),
    subject: "Hello".to_string(),
    body: "World".to_string(),
};

let result = post_to_group(&mut authenticated_connection, &article, &"newsgroup.name".to_string()).await;
match result {
    Ok(_) => println!("Posted successfully"),
    Err(err) => println!("Failed to post: {}", err),
}

Contributing

Feel free to contribute to this project by creating issues, pull requests or improving the documentation.

License

This project is licensed under the GNU General Public License v3.0.

Dependencies

~10–23MB
~406K SLoC