forked from mattnenterprise/rust-pop3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.rs
60 lines (51 loc) · 1.48 KB
/
example.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
extern crate pop3;
use pop3::POP3Result::{POP3List, POP3Message, POP3Stat};
use pop3::POP3Stream;
use rustls::ClientConfig;
use webpki_roots;
fn main() {
let mut client_config = ClientConfig::new();
client_config
.root_store
.add_server_trust_anchors(&webpki_roots::TLS_SERVER_ROOTS);
let mut gmail_socket = match POP3Stream::connect(
("pop.gmail.com", 995),
Some(client_config),
"pop.gmail.com",
) {
Ok(s) => s,
Err(e) => panic!("{}", e),
};
let res = gmail_socket.login("username", "password");
println!("{:#?}", res);
let stat = gmail_socket.stat();
match stat {
POP3Stat {
num_email,
mailbox_size,
} => println!("num_email: {}, mailbox_size:{}", num_email, mailbox_size),
_ => println!("Err for stat"),
}
let list_all = gmail_socket.list(None);
match list_all {
POP3List { emails_metadata } => {
for i in emails_metadata.iter() {
println!(
"message_id: {}, message_size: {}",
i.message_id, i.message_size
);
}
}
_ => println!("Err for list_all"),
}
let message_25 = gmail_socket.retr(25);
match message_25 {
POP3Message { raw } => {
for i in raw.iter() {
println!("{}", i);
}
}
_ => println!("Error for message_25"),
}
gmail_socket.quit();
}