rek2_nntp

Crates.iorek2_nntp
lib.rsrek2_nntp
version0.1.5
sourcesrc
created_at2023-09-19 02:56:22.199781
updated_at2023-10-01 23:02:33.223133
descriptionThis is a Rust library that provides a way to interact with NNTP servers, compliant with RFC 3977 and RFC 4643.
homepagehttps://git.sr.ht/~rek2/rek2_nntp
repositoryhttps://git.sr.ht/~rek2/rek2_nntp
max_upload_size
id976457
size49,313
ReK2 (r3k2)

documentation

https://git.sr.ht/~rek2/rek2_nntp

README

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.

Commit count: 0

cargo fmt