No description
Find a file
Jon Gjengset e5b4346114 Add IMAP IDLE support (#27)
* Add IMAP IDLE support

This patch adds support for the IMAP IDLE command specified in RFC 2177.
It allows clients to block while waiting for changes to a selected
mailbox, without having to poll the server. This is especially useful
for monitoring a mailbox for new messages.

The API is currently somewhat primitive: users can call `Client::idle()`
to get an IDLE "handle", which they can then call `wait()` on to block
until a change is detected. The implementation also provides
`wait_keepalive()` (which tries to avoid connection timeouts) and
`wait_timeout()` (which allows the user to specify the maximum time to
block).

Further down the line, the handle should probably also implement
`Iterator` to allow clients to watch new events as they happen. This
*could* be implemented today, but given that most other `Client` methods
just return unparsed strings at the moment, I didn't feel like that
enhancement was a high priority. For now, users will have to manually
query the mailbox for what changed.

Fixes #26.

* Avoid unnecessary as_bytes()

* Make wait_keepalive interval configurable

* Avoid ?, which requires Rust 1.13
2017-03-02 17:55:32 -05:00
examples Add comment to reference secure gmail connection 2016-07-14 16:32:44 -04:00
src Add IMAP IDLE support (#27) 2017-03-02 17:55:32 -05:00
.gitignore Initial Commit 2015-04-15 16:23:58 -04:00
.travis.yml Compile using only the stable and beta versions of Rust 2017-03-02 17:31:56 -05:00
Cargo.toml Updating version 2017-03-02 17:17:25 -05:00
LICENSE-APACHE Relicense as Apache 2.0 / MIT 2016-01-10 17:34:19 -05:00
LICENSE-MIT Relicense as Apache 2.0 / MIT 2016-01-10 17:34:19 -05:00
README.md Adding more line to get coverage to show on README.md 2016-06-29 19:15:31 -04:00

rust-imap

IMAP Client for Rust

Build Status crates.io Coverage Status

Documentation

Usage

Here is a basic example of using the client. See the examples directory for more examples.

extern crate imap;
extern crate openssl;

use openssl::ssl::{SslContext, SslMethod};
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() {
	let mut imap_socket = Client::secure_connect(("imap.gmail.com", 993), SslContext::new(SslMethod::Sslv23).unwrap()).unwrap();

	imap_socket.login("username", "password").unwrap();

	match imap_socket.capability() {
		Ok(capabilities) => {
			for capability in capabilities.iter() {
				println!("{}", capability);
			}
		},
		Err(e) => println!("Error parsing capability: {}", e)
	};

	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();
}

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.