-
Notifications
You must be signed in to change notification settings - Fork 5
/
get_article_conn.rs
29 lines (21 loc) · 1.03 KB
/
get_article_conn.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//! This example demonstrates how to use the NntpConnection to retrieve an article
use std::convert::TryFrom;
use brokaw::types::command as cmd;
use brokaw::types::prelude::*;
use brokaw::{ConnectionConfig, NntpConnection};
fn main() -> anyhow::Result<()> {
env_logger::from_env(env_logger::Env::default().default_filter_or("debug")).init();
let (mut conn, _resp) =
NntpConnection::connect(("news.mozilla.org", 119), ConnectionConfig::default())?;
let group_resp = conn.command(&cmd::Group("mozilla.dev.platform".to_string()))?;
let group = Group::try_from(&group_resp)?;
let raw_article = conn.command(&cmd::Article::Number(group.high))?;
let article = BinaryArticle::try_from(&raw_article)?;
println!("Article ID {}", article.message_id());
println!("Article # {}", article.number());
println!("Article has {} headers", article.headers().len());
println!("Article body:\n");
let text_article = article.to_text()?;
text_article.lines().for_each(|line| println!("{}", line));
Ok(())
}