1use std::env::args;
2use std::io::{stdin, Read};
3use std::process::exit;
4use std::str::FromStr;
5use tokio;
6use tokio_xmpp::SimpleClient as Client;
7use xmpp_parsers::message::{Body, Message};
8use xmpp_parsers::Jid;
9
10#[tokio::main]
11async fn main() {
12 env_logger::init();
13
14 let args: Vec<String> = args().collect();
15 if args.len() != 4 {
16 println!("Usage: {} <jid> <password> <recipient>", args[0]);
17 exit(1);
18 }
19 // Configuration
20 let jid = &args[1];
21 let password = &args[2];
22 let recipient = Jid::from_str(&args[3]).unwrap();
23
24 // Client instance
25 let mut client = Client::new(jid, password.to_owned()).await.unwrap();
26
27 // Read from stdin
28 println!("Client connected, type message and submit with Ctrl-D");
29 let mut body = String::new();
30 stdin().lock().read_to_string(&mut body).unwrap();
31
32 // Send message
33 let mut message = Message::new(Some(recipient));
34 message.bodies.insert(String::new(), Body(body.to_owned()));
35 client.send_stanza(message).await.unwrap();
36
37 // Close client connection
38 client.end().await.unwrap();
39}