adjust examples to the latest changes
This commit is contained in:
parent
da2ac87ca7
commit
abad1f4171
2 changed files with 11 additions and 13 deletions
|
|
@ -1,7 +1,6 @@
|
|||
extern crate imap;
|
||||
extern crate native_tls;
|
||||
|
||||
use imap::client::UnauthenticatedClient;
|
||||
use native_tls::TlsConnector;
|
||||
|
||||
// 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 socket_addr = (domain, port);
|
||||
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,
|
||||
Err((e, _unauth_client)) => {
|
||||
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() {
|
||||
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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ extern crate native_tls;
|
|||
|
||||
use base64::encode;
|
||||
use imap::authenticator::Authenticator;
|
||||
use imap::client::UnauthenticatedClient;
|
||||
use native_tls::TlsConnector;
|
||||
|
||||
struct GmailOAuth2 {
|
||||
|
|
@ -33,9 +32,9 @@ fn main() {
|
|||
let port = 993;
|
||||
let socket_addr = (domain, port);
|
||||
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,
|
||||
Err((e, _unauth_client)) => {
|
||||
println!("error authenticating: {}", e);
|
||||
|
|
@ -43,17 +42,17 @@ fn main() {
|
|||
}
|
||||
};
|
||||
|
||||
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();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue