Skip to content

Commit

Permalink
Merge 73efb03 into 61ffb00
Browse files Browse the repository at this point in the history
  • Loading branch information
dario23 committed Aug 30, 2018
2 parents 61ffb00 + 73efb03 commit 1d2b29d
Show file tree
Hide file tree
Showing 4 changed files with 335 additions and 148 deletions.
19 changes: 12 additions & 7 deletions examples/basic.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
extern crate imap;
extern crate native_tls;

use imap::client::Client;
use native_tls::TlsConnector;

// To connect to the gmail IMAP server with this you will need to allow unsecure apps access.
Expand All @@ -12,30 +11,36 @@ fn main() {
let port = 993;
let socket_addr = (domain, port);
let ssl_connector = TlsConnector::builder().build().unwrap();
let mut imap_socket = Client::secure_connect(socket_addr, domain, &ssl_connector).unwrap();
let client = imap::client::secure_connect(socket_addr, domain, &ssl_connector).unwrap();

imap_socket.login("username", "password").unwrap();
let mut imap_session = match client.login("username", "password") {
Ok(c) => c,
Err((e, _unauth_client)) => {
eprintln!("failed to login: {}", e);
return;
}
};

match imap_socket.capabilities() {
match imap_session.capabilities() {
Ok(capabilities) => for capability in capabilities.iter() {
println!("{}", capability);
},
Err(e) => println!("Error parsing capability: {}", e),
};

match imap_socket.select("INBOX") {
match imap_session.select("INBOX") {
Ok(mailbox) => {
println!("{}", mailbox);
}
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 {
print!("{:?}", msg);
},
Err(e) => println!("Error Fetching email 2: {}", e),
};

imap_socket.logout().unwrap();
imap_session.logout().unwrap();
}
19 changes: 12 additions & 7 deletions examples/gmail_oauth2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ extern crate native_tls;

use base64::encode;
use imap::authenticator::Authenticator;
use imap::client::Client;
use native_tls::TlsConnector;

struct GmailOAuth2 {
Expand Down Expand Up @@ -33,21 +32,27 @@ fn main() {
let port = 993;
let socket_addr = (domain, port);
let ssl_connector = TlsConnector::builder().build().unwrap();
let mut imap_socket = Client::secure_connect(socket_addr, domain, &ssl_connector).unwrap();

imap_socket.authenticate("XOAUTH2", gmail_auth).unwrap();
let client = imap::client::secure_connect(socket_addr, domain, &ssl_connector).unwrap();

let mut imap_session = match client.authenticate("XOAUTH2", gmail_auth) {
Ok(c) => c,
Err((e, _unauth_client)) => {
println!("error authenticating: {}", e);
return;
}
};

match imap_socket.select("INBOX") {
match imap_session.select("INBOX") {
Ok(mailbox) => println!("{}", mailbox),
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 {
print!("{:?}", msg);
},
Err(e) => println!("Error Fetching email 2: {}", e),
};

imap_socket.logout().unwrap();
imap_session.logout().unwrap();
}

0 comments on commit 1d2b29d

Please sign in to comment.