Updating README.md and the basic example
This commit is contained in:
parent
4b8a294689
commit
b593d943ef
2 changed files with 31 additions and 46 deletions
75
README.md
75
README.md
|
|
@ -2,70 +2,53 @@ rust-imap
|
||||||
================
|
================
|
||||||
IMAP Client for Rust
|
IMAP Client for Rust
|
||||||
|
|
||||||
This client has SSL support. SSL is configured using an SSLContext that is passed into the connect method of a IMAPStream. If no SSL
|
|
||||||
support is wanted just pass in None. The library rust-openssl is used to support SSL for this project.
|
|
||||||
|
|
||||||
|
|
||||||
[](https://travis-ci.org/mattnenterprise/rust-imap)
|
[](https://travis-ci.org/mattnenterprise/rust-imap)
|
||||||
[](https://crates.io/crates/imap)
|
[](https://crates.io/crates/imap)
|
||||||
|
|
||||||
[Documentation](http://mattnenterprise.github.io/rust-imap)
|
[Documentation](http://mattnenterprise.github.io/rust-imap)
|
||||||
|
|
||||||
### Installation
|
|
||||||
|
|
||||||
Add imap via your `Cargo.toml`:
|
|
||||||
```toml
|
|
||||||
[dependencies]
|
|
||||||
imap = "*"
|
|
||||||
```
|
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
Here is a basic example of using the client. See the examples directory for more examples.
|
||||||
```rust
|
```rust
|
||||||
extern crate imap;
|
extern crate imap;
|
||||||
extern crate openssl;
|
extern crate openssl;
|
||||||
|
|
||||||
use openssl::ssl::{SslContext, SslMethod};
|
use openssl::ssl::{SslContext, SslMethod};
|
||||||
use imap::client::IMAPStream;
|
use imap::client::Client;
|
||||||
use imap::client::IMAPMailbox;
|
|
||||||
|
|
||||||
|
// To connect to the gmail IMAP server with this you will need to allow unsecure apps access.
|
||||||
|
// See: https://support.google.com/accounts/answer/6010255?hl=en
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut imap_socket = match IMAPStream::connect("imap.gmail.com", 993, Some(SslContext::new(SslMethod::Sslv23).unwrap())) {
|
let mut imap_socket = Client::secure_connect(("imap.gmail.com", 993), SslContext::new(SslMethod::Sslv23).unwrap()).unwrap();
|
||||||
Ok(s) => s,
|
|
||||||
Err(e) => panic!("{}", e)
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Err(e) = imap_socket.login("username", "password") {
|
imap_socket.login("username", "password").unwrap();
|
||||||
println!("Error: {}", e)
|
|
||||||
};
|
|
||||||
|
|
||||||
match imap_socket.capability() {
|
match imap_socket.capability() {
|
||||||
Ok(capabilities) => {
|
Ok(capabilities) => {
|
||||||
for capability in capabilities.iter() {
|
for capability in capabilities.iter() {
|
||||||
println!("{}", capability);
|
println!("{}", capability);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(_) => println!("Error retreiving capabilities")
|
Err(e) => println!("Error parsing capability: {}", e)
|
||||||
};
|
};
|
||||||
|
|
||||||
match imap_socket.select("INBOX") {
|
match imap_socket.select("INBOX") {
|
||||||
Ok(IMAPMailbox{flags, exists, recent, unseen, permanent_flags, uid_next, uid_validity}) => {
|
Ok(mailbox) => {
|
||||||
println!("flags: {}, exists: {}, recent: {}, unseen: {:?}, permanent_flags: {:?}, uid_next: {:?}, uid_validity: {:?}", flags, exists, recent, unseen, permanent_flags, uid_next, uid_validity);
|
println!("{}", mailbox);
|
||||||
},
|
},
|
||||||
Err(_) => println!("Error selecting INBOX")
|
Err(e) => println!("Error selecting INBOX: {}", e)
|
||||||
};
|
};
|
||||||
|
|
||||||
match imap_socket.fetch("2", "body[text]") {
|
match imap_socket.fetch("2", "body[text]") {
|
||||||
Ok(lines) => {
|
Ok(lines) => {
|
||||||
for line in lines.iter() {
|
for line in lines.iter() {
|
||||||
print!("{}", line);
|
print!("{}", line);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(_) => println!("Error Fetching email 2")
|
Err(e) => println!("Error Fetching email 2: {}", e)
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Err(e) = imap_socket.logout() {
|
imap_socket.logout().unwrap();
|
||||||
println!("Error: {}", e)
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ extern crate openssl;
|
||||||
use openssl::ssl::{SslContext, SslMethod};
|
use openssl::ssl::{SslContext, SslMethod};
|
||||||
use imap::client::Client;
|
use imap::client::Client;
|
||||||
|
|
||||||
|
// To connect to the gmail IMAP server with this you will need to allow unsecure apps access.
|
||||||
|
// See: https://support.google.com/accounts/answer/6010255?hl=en
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut imap_socket = Client::secure_connect(("imap.gmail.com", 993), SslContext::new(SslMethod::Sslv23).unwrap()).unwrap();
|
let mut imap_socket = Client::secure_connect(("imap.gmail.com", 993), SslContext::new(SslMethod::Sslv23).unwrap()).unwrap();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue