adjust examples to the latest changes

This commit is contained in:
Johannes Schilling 2018-08-29 16:08:53 +02:00
parent da2ac87ca7
commit abad1f4171
2 changed files with 11 additions and 13 deletions

View file

@ -1,7 +1,6 @@
extern crate imap; extern crate imap;
extern crate native_tls; extern crate native_tls;
use imap::client::UnauthenticatedClient;
use native_tls::TlsConnector; use native_tls::TlsConnector;
// To connect to the gmail IMAP server with this you will need to allow unsecure apps access. // To connect to the gmail IMAP server with this you will need to allow unsecure apps access.
@ -12,9 +11,9 @@ fn main() {
let port = 993; let port = 993;
let socket_addr = (domain, port); let socket_addr = (domain, port);
let ssl_connector = TlsConnector::builder().build().unwrap(); let ssl_connector = TlsConnector::builder().build().unwrap();
let unauth_client = UnauthenticatedClient::secure_connect(socket_addr, domain, &ssl_connector).unwrap(); let client = imap::client::secure_connect(socket_addr, domain, &ssl_connector).unwrap();
let mut imap_socket = match unauth_client.login("username", "password") { let mut imap_session = match client.login("username", "password") {
Ok(c) => c, Ok(c) => c,
Err((e, _unauth_client)) => { Err((e, _unauth_client)) => {
println!("failed to login: {}", e); println!("failed to login: {}", e);
@ -22,26 +21,26 @@ fn main() {
}, },
}; };
match imap_socket.capabilities() { match imap_session.capabilities() {
Ok(capabilities) => for capability in capabilities.iter() { Ok(capabilities) => for capability in capabilities.iter() {
println!("{}", capability); println!("{}", capability);
}, },
Err(e) => println!("Error parsing capability: {}", e), Err(e) => println!("Error parsing capability: {}", e),
}; };
match imap_socket.select("INBOX") { match imap_session.select("INBOX") {
Ok(mailbox) => { Ok(mailbox) => {
println!("{}", mailbox); println!("{}", mailbox);
} }
Err(e) => println!("Error selecting INBOX: {}", e), Err(e) => println!("Error selecting INBOX: {}", e),
}; };
match imap_socket.fetch("2", "body[text]") { match imap_session.fetch("2", "body[text]") {
Ok(msgs) => for msg in &msgs { Ok(msgs) => for msg in &msgs {
print!("{:?}", msg); print!("{:?}", msg);
}, },
Err(e) => println!("Error Fetching email 2: {}", e), Err(e) => println!("Error Fetching email 2: {}", e),
}; };
imap_socket.logout().unwrap(); imap_session.logout().unwrap();
} }

View file

@ -4,7 +4,6 @@ extern crate native_tls;
use base64::encode; use base64::encode;
use imap::authenticator::Authenticator; use imap::authenticator::Authenticator;
use imap::client::UnauthenticatedClient;
use native_tls::TlsConnector; use native_tls::TlsConnector;
struct GmailOAuth2 { struct GmailOAuth2 {
@ -33,9 +32,9 @@ fn main() {
let port = 993; let port = 993;
let socket_addr = (domain, port); let socket_addr = (domain, port);
let ssl_connector = TlsConnector::builder().build().unwrap(); let ssl_connector = TlsConnector::builder().build().unwrap();
let unauth_client = UnauthenticatedClient::secure_connect(socket_addr, domain, &ssl_connector).unwrap(); let client = imap::client::secure_connect(socket_addr, domain, &ssl_connector).unwrap();
let mut imap_socket = match unauth_client.authenticate("XOAUTH2", gmail_auth) { let mut imap_session = match client.authenticate("XOAUTH2", gmail_auth) {
Ok(c) => c, Ok(c) => c,
Err((e, _unauth_client)) => { Err((e, _unauth_client)) => {
println!("error authenticating: {}", e); println!("error authenticating: {}", e);
@ -43,17 +42,17 @@ fn main() {
} }
}; };
match imap_socket.select("INBOX") { match imap_session.select("INBOX") {
Ok(mailbox) => println!("{}", mailbox), Ok(mailbox) => println!("{}", mailbox),
Err(e) => println!("Error selecting INBOX: {}", e), Err(e) => println!("Error selecting INBOX: {}", e),
}; };
match imap_socket.fetch("2", "body[text]") { match imap_session.fetch("2", "body[text]") {
Ok(msgs) => for msg in &msgs { Ok(msgs) => for msg in &msgs {
print!("{:?}", msg); print!("{:?}", msg);
}, },
Err(e) => println!("Error Fetching email 2: {}", e), Err(e) => println!("Error Fetching email 2: {}", e),
}; };
imap_socket.logout().unwrap(); imap_session.logout().unwrap();
} }