adjust examples to Client/UnauthenticatedClient splitup
This commit is contained in:
parent
820d1eccf7
commit
3d6dd58f19
2 changed files with 18 additions and 6 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
extern crate imap;
|
extern crate imap;
|
||||||
extern crate native_tls;
|
extern crate native_tls;
|
||||||
|
|
||||||
use imap::client::Client;
|
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 +12,15 @@ 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 mut imap_socket = Client::secure_connect(socket_addr, domain, &ssl_connector).unwrap();
|
let unauth_client = UnauthenticatedClient::secure_connect(socket_addr, domain, &ssl_connector).unwrap();
|
||||||
|
|
||||||
imap_socket.login("username", "password").unwrap();
|
let mut imap_socket = match unauth_client.login("username", "password") {
|
||||||
|
Ok(c) => c,
|
||||||
|
Err((e, _unauth_client)) => {
|
||||||
|
println!("failed to login: {}", e);
|
||||||
|
return;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
match imap_socket.capabilities() {
|
match imap_socket.capabilities() {
|
||||||
Ok(capabilities) => for capability in capabilities.iter() {
|
Ok(capabilities) => for capability in capabilities.iter() {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ extern crate native_tls;
|
||||||
|
|
||||||
use base64::encode;
|
use base64::encode;
|
||||||
use imap::authenticator::Authenticator;
|
use imap::authenticator::Authenticator;
|
||||||
use imap::client::Client;
|
use imap::client::UnauthenticatedClient;
|
||||||
use native_tls::TlsConnector;
|
use native_tls::TlsConnector;
|
||||||
|
|
||||||
struct GmailOAuth2 {
|
struct GmailOAuth2 {
|
||||||
|
|
@ -33,9 +33,15 @@ 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 mut imap_socket = Client::secure_connect(socket_addr, domain, &ssl_connector).unwrap();
|
let unauth_client = UnauthenticatedClient::secure_connect(socket_addr, domain, &ssl_connector).unwrap();
|
||||||
|
|
||||||
imap_socket.authenticate("XOAUTH2", gmail_auth).unwrap();
|
let mut imap_socket = match unauth_client.authenticate("XOAUTH2", gmail_auth) {
|
||||||
|
Ok(c) => c,
|
||||||
|
Err((e, _unauth_client)) => {
|
||||||
|
println!("error authenticating: {}", e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
match imap_socket.select("INBOX") {
|
match imap_socket.select("INBOX") {
|
||||||
Ok(mailbox) => println!("{}", mailbox),
|
Ok(mailbox) => println!("{}", mailbox),
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue