rustfmt
This commit is contained in:
parent
6e47ceb171
commit
1d4d6288c1
8 changed files with 35 additions and 40 deletions
|
|
@ -1,8 +1,8 @@
|
|||
extern crate imap;
|
||||
extern crate native_tls;
|
||||
|
||||
use native_tls::TlsConnector;
|
||||
use imap::client::Client;
|
||||
use native_tls::TlsConnector;
|
||||
|
||||
// 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
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@ extern crate base64;
|
|||
extern crate imap;
|
||||
extern crate native_tls;
|
||||
|
||||
use native_tls::TlsConnector;
|
||||
use base64::encode;
|
||||
use imap::client::Client;
|
||||
use imap::authenticator::Authenticator;
|
||||
use imap::client::Client;
|
||||
use native_tls::TlsConnector;
|
||||
|
||||
struct GmailOAuth2 {
|
||||
user: String,
|
||||
|
|
@ -18,8 +18,7 @@ impl Authenticator for GmailOAuth2 {
|
|||
encode(
|
||||
format!(
|
||||
"user={}\x01auth=Bearer {}\x01\x01",
|
||||
self.user,
|
||||
self.access_token
|
||||
self.user, self.access_token
|
||||
).as_bytes(),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
use std::net::{TcpStream, ToSocketAddrs};
|
||||
use native_tls::{TlsConnector, TlsStream};
|
||||
use std::io::{self, Read, Write};
|
||||
use std::time::Duration;
|
||||
use bufstream::BufStream;
|
||||
use native_tls::{TlsConnector, TlsStream};
|
||||
use nom::IResult;
|
||||
use std::io::{self, Read, Write};
|
||||
use std::net::{TcpStream, ToSocketAddrs};
|
||||
use std::time::Duration;
|
||||
|
||||
use super::types::*;
|
||||
use super::authenticator::Authenticator;
|
||||
use super::error::{Error, ParseError, Result, ValidateError};
|
||||
use super::parse::{parse_authenticate_response, parse_capabilities, parse_fetches, parse_mailbox,
|
||||
parse_names};
|
||||
use super::error::{Error, ParseError, Result, ValidateError};
|
||||
use super::types::*;
|
||||
|
||||
static TAG_PREFIX: &'static str = "a";
|
||||
const INITIAL_TAG: u32 = 0;
|
||||
|
|
@ -17,9 +17,9 @@ const CR: u8 = 0x0d;
|
|||
const LF: u8 = 0x0a;
|
||||
|
||||
macro_rules! quote {
|
||||
($x: expr) => (
|
||||
($x:expr) => {
|
||||
format!("\"{}\"", $x.replace(r"\", r"\\").replace("\"", "\\\""))
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
fn validate_str(value: &str) -> Result<String> {
|
||||
|
|
@ -447,9 +447,7 @@ impl<T: Read + Write> Client<T> {
|
|||
|
||||
/// The APPEND command adds a mail to a mailbox.
|
||||
pub fn append(&mut self, folder: &str, content: &[u8]) -> Result<()> {
|
||||
try!(self.run_command(
|
||||
&format!("APPEND \"{}\" {{{}}}", folder, content.len())
|
||||
));
|
||||
try!(self.run_command(&format!("APPEND \"{}\" {{{}}}", folder, content.len())));
|
||||
let mut v = Vec::new();
|
||||
try!(self.readline(&mut v));
|
||||
if !v.starts_with(b"+") {
|
||||
|
|
@ -538,14 +536,14 @@ impl<T: Read + Write> Client<T> {
|
|||
use imap_proto::Status;
|
||||
match status {
|
||||
Status::Bad => {
|
||||
break Err(Error::BadResponse(
|
||||
expl.unwrap_or("no explanation given".to_string()),
|
||||
))
|
||||
break Err(Error::BadResponse(expl.unwrap_or(
|
||||
"no explanation given".to_string(),
|
||||
)))
|
||||
}
|
||||
Status::No => {
|
||||
break Err(Error::NoResponse(
|
||||
expl.unwrap_or("no explanation given".to_string()),
|
||||
))
|
||||
break Err(Error::NoResponse(expl.unwrap_or(
|
||||
"no explanation given".to_string(),
|
||||
)))
|
||||
}
|
||||
_ => break Err(Error::Parse(ParseError::Invalid(data.split_off(0)))),
|
||||
}
|
||||
|
|
@ -597,9 +595,9 @@ impl<T: Read + Write> Client<T> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use super::super::mock_stream::MockStream;
|
||||
use super::super::error::Result;
|
||||
use super::super::mock_stream::MockStream;
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn read_response() {
|
||||
|
|
@ -610,7 +608,6 @@ mod tests {
|
|||
assert_eq!(Vec::<u8>::new(), actual_response);
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn fetch_body() {
|
||||
let response = "a0 OK Logged in.\r\n\
|
||||
|
|
@ -622,7 +619,6 @@ mod tests {
|
|||
client.read_response().unwrap();
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn read_greeting() {
|
||||
let greeting = "* OK Dovecot ready.\r\n";
|
||||
|
|
|
|||
12
src/error.rs
12
src/error.rs
|
|
@ -1,14 +1,14 @@
|
|||
use std::io::Error as IoError;
|
||||
use std::result;
|
||||
use std::fmt;
|
||||
use std::error::Error as StdError;
|
||||
use std::fmt;
|
||||
use std::io::Error as IoError;
|
||||
use std::net::TcpStream;
|
||||
use std::result;
|
||||
use std::string::FromUtf8Error;
|
||||
|
||||
use imap_proto::Response;
|
||||
use native_tls::HandshakeError as TlsHandshakeError;
|
||||
use native_tls::Error as TlsError;
|
||||
use bufstream::IntoInnerError as BufError;
|
||||
use imap_proto::Response;
|
||||
use native_tls::Error as TlsError;
|
||||
use native_tls::HandshakeError as TlsHandshakeError;
|
||||
|
||||
pub type Result<T> = result::Result<T, Error>;
|
||||
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ extern crate native_tls;
|
|||
extern crate nom;
|
||||
extern crate regex;
|
||||
|
||||
mod types;
|
||||
mod parse;
|
||||
mod types;
|
||||
|
||||
pub mod authenticator;
|
||||
pub mod client;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use std::io::{Error, ErrorKind, Read, Result, Write};
|
||||
use std::cmp::min;
|
||||
use std::io::{Error, ErrorKind, Read, Result, Write};
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
|
||||
pub struct MockStream {
|
||||
|
|
|
|||
10
src/parse.rs
10
src/parse.rs
|
|
@ -1,9 +1,9 @@
|
|||
use regex::Regex;
|
||||
use nom::IResult;
|
||||
use imap_proto::{self, Response};
|
||||
use nom::IResult;
|
||||
use regex::Regex;
|
||||
|
||||
use super::types::*;
|
||||
use super::error::{Error, ParseError, Result};
|
||||
use super::types::*;
|
||||
|
||||
pub fn parse_authenticate_response(line: String) -> Result<String> {
|
||||
let authenticate_regex = Regex::new("^+(.*)\r\n").unwrap();
|
||||
|
|
@ -59,8 +59,8 @@ pub fn parse_names(lines: Vec<u8>) -> ZeroCopyResult<Vec<Name>> {
|
|||
flags,
|
||||
delimiter,
|
||||
name,
|
||||
}) |
|
||||
Response::MailboxData(MailboxDatum::SubList {
|
||||
})
|
||||
| Response::MailboxData(MailboxDatum::SubList {
|
||||
flags,
|
||||
delimiter,
|
||||
name,
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ use std::collections::HashSet;
|
|||
use std::collections::hash_set::Iter;
|
||||
pub struct Capabilities(pub(crate) HashSet<&'static str>);
|
||||
|
||||
use std::hash::Hash;
|
||||
use std::borrow::Borrow;
|
||||
use std::hash::Hash;
|
||||
impl Capabilities {
|
||||
pub fn has<S: ?Sized>(&self, s: &S) -> bool
|
||||
where
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue