47 lines
1.2 KiB
Rust
47 lines
1.2 KiB
Rust
extern crate imap;
|
|
extern crate openssl;
|
|
extern crate base64;
|
|
|
|
use openssl::ssl::{SslContext, SslMethod};
|
|
use base64::{encode, decode};
|
|
use imap::client::Client;
|
|
use imap::authenticator::Authenticator;
|
|
|
|
struct GmailOAuth2 {
|
|
user: String,
|
|
access_token: String
|
|
}
|
|
|
|
impl Authenticator for GmailOAuth2 {
|
|
fn process(&self, data: String) -> String {
|
|
String::from("dXNlcj1tYXR0bWNjb3kxMTBAZ21haWwuY29tAWF1dGg9QmVhcmVyIHlhMjkuQ2k4UUEzQ1Y5SW1OQ0Z1NDNpbkZRcngtSUR0cjVFSkZHNXdEM1IySzBXdTdiM1dzVG1Md")
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
let mut gmail_auth = GmailOAuth2{
|
|
user: String::from("email@gmail.com"),
|
|
access_token: String::from("")
|
|
};
|
|
let mut imap_socket = Client::secure_connect(("imap.gmail.com", 993), SslContext::new(SslMethod::Sslv23).unwrap()).unwrap();
|
|
|
|
imap_socket.authenticate("XOAUTH2", gmail_auth).unwrap();
|
|
|
|
match imap_socket.select("INBOX") {
|
|
Ok(mailbox) => {
|
|
println!("{}", mailbox);
|
|
},
|
|
Err(e) => println!("Error selecting INBOX: {}", e)
|
|
};
|
|
|
|
match imap_socket.fetch("2", "body[text]") {
|
|
Ok(lines) => {
|
|
for line in lines.iter() {
|
|
print!("{}", line);
|
|
}
|
|
},
|
|
Err(e) => println!("Error Fetching email 2: {}", e)
|
|
};
|
|
|
|
imap_socket.logout().unwrap();
|
|
}
|