Crates.io | rek2_nntp |
lib.rs | rek2_nntp |
version | 0.1.5 |
source | src |
created_at | 2023-09-19 02:56:22.199781 |
updated_at | 2023-10-01 23:02:33.223133 |
description | This is a Rust library that provides a way to interact with NNTP servers, compliant with RFC 3977 and RFC 4643. |
homepage | https://git.sr.ht/~rek2/rek2_nntp |
repository | https://git.sr.ht/~rek2/rek2_nntp |
max_upload_size | |
id | 976457 |
size | 49,313 |
This is a Rust library that provides a way to interact with NNTP servers, compliant with RFC 3977 and RFC 4643.
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.
First, add the following import to your code:
extern crate rek2_nntp;
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);
}
}
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);
}
}
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);
}
}
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),
}
Feel free to contribute to this project by creating issues, pull requests or improving the documentation.
This project is licensed under the GNU General Public License v3.0.