Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@sanxiyn
Last active December 3, 2019 03:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sanxiyn/15493ca613a837721efc5a89fa11f952 to your computer and use it in GitHub Desktop.
Save sanxiyn/15493ca613a837721efc5a89fa11f952 to your computer and use it in GitHub Desktop.
use std::error::Error;
use std::fs;
use argparse::{ArgumentParser, Store};
fn main() -> Result<(), Box<Error>> {
let mut mailbox_name = String::new();
{
let mut parser = ArgumentParser::new();
parser.refer(&mut mailbox_name)
.add_argument("label", Store, "");
parser.parse_args_or_exit();
}
let domain = "imap.gmail.com";
let username = fs::read_to_string("username")?;
let password = fs::read_to_string("password")?;
let tls = native_tls::TlsConnector::new()?;
let client = imap::connect((domain, 993), domain, &tls)?;
let mut session = client.login(username, password)
.map_err(|(error, _)| error)?;
let mailbox = session.select(&mailbox_name)?;
println!("{}: {}", mailbox_name, mailbox.exists);
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment