Threads in example client
This commit is contained in:
@@ -12,25 +12,48 @@ extern crate log;
|
|||||||
extern crate env_logger;
|
extern crate env_logger;
|
||||||
extern crate smtp;
|
extern crate smtp;
|
||||||
|
|
||||||
|
use std::sync::{Arc, Mutex};
|
||||||
|
use std::collections::HashSet;
|
||||||
|
use std::thread;
|
||||||
|
|
||||||
use smtp::sender::{Sender, SenderBuilder};
|
use smtp::sender::{Sender, SenderBuilder};
|
||||||
use smtp::email::EmailBuilder;
|
use smtp::email::EmailBuilder;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
env_logger::init().unwrap();
|
env_logger::init().unwrap();
|
||||||
|
|
||||||
let email = EmailBuilder::new()
|
let mut sender = Arc::new(Mutex::new(SenderBuilder::localhost().hello_name("localhost")
|
||||||
|
.enable_connection_reuse(true).build()));
|
||||||
|
|
||||||
|
let mut threads = Vec::new();
|
||||||
|
for _ in 1..5 {
|
||||||
|
|
||||||
|
let th_sender = sender.clone();
|
||||||
|
threads.push(thread::spawn(move || {
|
||||||
|
println!("thpouet");
|
||||||
|
let email = EmailBuilder::new()
|
||||||
.to("user@localhost")
|
.to("user@localhost")
|
||||||
.from("user@localhost")
|
.from("user@localhost")
|
||||||
.body("Hello World!")
|
.body("Hello World!")
|
||||||
.subject("Hello")
|
.subject("Hello")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let mut sender: Sender = SenderBuilder::localhost().hello_name("localhost")
|
let _ = th_sender.lock().unwrap().send(email);
|
||||||
.enable_connection_reuse(true).build();
|
}));
|
||||||
|
|
||||||
for _ in (1..5) {
|
|
||||||
let _ = sender.send(email.clone());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for thread in threads {
|
||||||
|
let _ = thread.join();
|
||||||
|
}
|
||||||
|
|
||||||
|
let email = EmailBuilder::new()
|
||||||
|
.to("user@localhost")
|
||||||
|
.from("user@localhost")
|
||||||
|
.body("Hello World!")
|
||||||
|
.subject("Hello Bis")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
let mut sender = sender.lock().unwrap();
|
||||||
let result = sender.send(email);
|
let result = sender.send(email);
|
||||||
sender.close();
|
sender.close();
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ use crypto::mac::Mac;
|
|||||||
use NUL;
|
use NUL;
|
||||||
use error::Error;
|
use error::Error;
|
||||||
|
|
||||||
/// TODO
|
/// Represents authentication mecanisms
|
||||||
#[derive(PartialEq,Eq,Copy,Clone,Hash,Debug)]
|
#[derive(PartialEq,Eq,Copy,Clone,Hash,Debug)]
|
||||||
pub enum Mecanism {
|
pub enum Mecanism {
|
||||||
/// PLAIN authentication mecanism
|
/// PLAIN authentication mecanism
|
||||||
@@ -44,7 +44,7 @@ impl Display for Mecanism {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Mecanism {
|
impl Mecanism {
|
||||||
/// TODO
|
/// Does the mecanism supports initial response
|
||||||
pub fn supports_initial_response(&self) -> bool {
|
pub fn supports_initial_response(&self) -> bool {
|
||||||
match *self {
|
match *self {
|
||||||
Mecanism::Plain => true,
|
Mecanism::Plain => true,
|
||||||
@@ -52,7 +52,7 @@ impl Mecanism {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TODO
|
/// Returns the string to send to the server, using the provided username, password and challenge in some cases
|
||||||
pub fn response(&self, username: &str, password: &str, challenge: Option<&str>) -> Result<String, Error> {
|
pub fn response(&self, username: &str, password: &str, challenge: Option<&str>) -> Result<String, Error> {
|
||||||
match *self {
|
match *self {
|
||||||
Mecanism::Plain => {
|
Mecanism::Plain => {
|
||||||
|
|||||||
Reference in New Issue
Block a user