Clippy clean
This commit is contained in:
parent
fc935bf884
commit
bce4831ccb
7 changed files with 20 additions and 21 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
|
|
||||||
name = "imap"
|
name = "imap"
|
||||||
version = "0.9.0"
|
version = "0.9.1"
|
||||||
authors = ["Matt McCoy <mattnenterprise@yahoo.com>",
|
authors = ["Matt McCoy <mattnenterprise@yahoo.com>",
|
||||||
"Jon Gjengset <jon@thesquareplanet.com>"]
|
"Jon Gjengset <jon@thesquareplanet.com>"]
|
||||||
documentation = "https://docs.rs/imap/"
|
documentation = "https://docs.rs/imap/"
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ fn main() {
|
||||||
let ssl_connector = TlsConnector::builder().build().unwrap();
|
let ssl_connector = TlsConnector::builder().build().unwrap();
|
||||||
let client = imap::connect(socket_addr, domain, &ssl_connector).unwrap();
|
let client = imap::connect(socket_addr, domain, &ssl_connector).unwrap();
|
||||||
|
|
||||||
let mut imap_session = match client.authenticate("XOAUTH2", gmail_auth) {
|
let mut imap_session = match client.authenticate("XOAUTH2", &gmail_auth) {
|
||||||
Ok(c) => c,
|
Ok(c) => c,
|
||||||
Err((e, _unauth_client)) => {
|
Err((e, _unauth_client)) => {
|
||||||
println!("error authenticating: {}", e);
|
println!("error authenticating: {}", e);
|
||||||
|
|
|
||||||
|
|
@ -305,7 +305,7 @@ impl<T: Read + Write> Client<T> {
|
||||||
/// let domain = "imap.example.com";
|
/// let domain = "imap.example.com";
|
||||||
/// let tls = TlsConnector::builder().build().unwrap();
|
/// let tls = TlsConnector::builder().build().unwrap();
|
||||||
/// let client = imap::connect((domain, 993), domain, &tls).unwrap();
|
/// let client = imap::connect((domain, 993), domain, &tls).unwrap();
|
||||||
/// match client.authenticate("XOAUTH2", auth) {
|
/// match client.authenticate("XOAUTH2", &auth) {
|
||||||
/// Ok(session) => {
|
/// Ok(session) => {
|
||||||
/// // you are successfully authenticated!
|
/// // you are successfully authenticated!
|
||||||
/// },
|
/// },
|
||||||
|
|
@ -320,13 +320,13 @@ impl<T: Read + Write> Client<T> {
|
||||||
pub fn authenticate<A: Authenticator>(
|
pub fn authenticate<A: Authenticator>(
|
||||||
mut self,
|
mut self,
|
||||||
auth_type: &str,
|
auth_type: &str,
|
||||||
authenticator: A,
|
authenticator: &A,
|
||||||
) -> ::std::result::Result<Session<T>, (Error, Client<T>)> {
|
) -> ::std::result::Result<Session<T>, (Error, Client<T>)> {
|
||||||
ok_or_unauth_client_err!(
|
ok_or_unauth_client_err!(
|
||||||
self.run_command(&format!("AUTHENTICATE {}", auth_type)),
|
self.run_command(&format!("AUTHENTICATE {}", auth_type)),
|
||||||
self
|
self
|
||||||
);
|
);
|
||||||
self.do_auth_handshake(&authenticator)
|
self.do_auth_handshake(authenticator)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This func does the handshake process once the authenticate command is made.
|
/// This func does the handshake process once the authenticate command is made.
|
||||||
|
|
@ -905,7 +905,7 @@ impl<T: Read + Write> Session<T> {
|
||||||
///
|
///
|
||||||
/// See [`extensions::idle::Handle`] for details.
|
/// See [`extensions::idle::Handle`] for details.
|
||||||
pub fn idle(&mut self) -> Result<extensions::idle::Handle<T>> {
|
pub fn idle(&mut self) -> Result<extensions::idle::Handle<T>> {
|
||||||
extensions::idle::Handle::new(self)
|
extensions::idle::Handle::make(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The [`APPEND` command](https://tools.ietf.org/html/rfc3501#section-6.3.11) appends
|
/// The [`APPEND` command](https://tools.ietf.org/html/rfc3501#section-6.3.11) appends
|
||||||
|
|
@ -986,7 +986,7 @@ impl<T: Read + Write> Session<T> {
|
||||||
/// - `SINCE <date>`: Messages whose internal date (disregarding time and timezone) is within or later than the specified date.
|
/// - `SINCE <date>`: Messages whose internal date (disregarding time and timezone) is within or later than the specified date.
|
||||||
pub fn search(&mut self, query: &str) -> Result<HashSet<Seq>> {
|
pub fn search(&mut self, query: &str) -> Result<HashSet<Seq>> {
|
||||||
self.run_command_and_read_response(&format!("SEARCH {}", query))
|
self.run_command_and_read_response(&format!("SEARCH {}", query))
|
||||||
.and_then(|lines| parse_ids(lines, &mut self.unsolicited_responses_tx))
|
.and_then(|lines| parse_ids(&lines, &mut self.unsolicited_responses_tx))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Equivalent to [`Session::search`], except that the returned identifiers
|
/// Equivalent to [`Session::search`], except that the returned identifiers
|
||||||
|
|
@ -994,7 +994,7 @@ impl<T: Read + Write> Session<T> {
|
||||||
/// command](https://tools.ietf.org/html/rfc3501#section-6.4.8).
|
/// command](https://tools.ietf.org/html/rfc3501#section-6.4.8).
|
||||||
pub fn uid_search(&mut self, query: &str) -> Result<HashSet<Uid>> {
|
pub fn uid_search(&mut self, query: &str) -> Result<HashSet<Uid>> {
|
||||||
self.run_command_and_read_response(&format!("UID SEARCH {}", query))
|
self.run_command_and_read_response(&format!("UID SEARCH {}", query))
|
||||||
.and_then(|lines| parse_ids(lines, &mut self.unsolicited_responses_tx))
|
.and_then(|lines| parse_ids(&lines, &mut self.unsolicited_responses_tx))
|
||||||
}
|
}
|
||||||
|
|
||||||
// these are only here because they are public interface, the rest is in `Connection`
|
// these are only here because they are public interface, the rest is in `Connection`
|
||||||
|
|
@ -1266,8 +1266,7 @@ mod tests {
|
||||||
b"foo".to_vec()
|
b"foo".to_vec()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let auth = Authenticate::Auth;
|
let session = client.authenticate("PLAIN", &Authenticate::Auth).unwrap();
|
||||||
let session = client.authenticate("PLAIN", auth).unwrap();
|
|
||||||
assert!(
|
assert!(
|
||||||
session.stream.get_ref().written_buf == command.as_bytes().to_vec(),
|
session.stream.get_ref().written_buf == command.as_bytes().to_vec(),
|
||||||
"Invalid authenticate command"
|
"Invalid authenticate command"
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ pub trait SetReadTimeout {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T: Read + Write + 'a> Handle<'a, T> {
|
impl<'a, T: Read + Write + 'a> Handle<'a, T> {
|
||||||
pub(crate) fn new(session: &'a mut Session<T>) -> Result<Self> {
|
pub(crate) fn make(session: &'a mut Session<T>) -> Result<Self> {
|
||||||
let mut h = Handle {
|
let mut h = Handle {
|
||||||
session,
|
session,
|
||||||
keepalive: Duration::from_secs(29 * 60),
|
keepalive: Duration::from_secs(29 * 60),
|
||||||
|
|
|
||||||
12
src/parse.rs
12
src/parse.rs
|
|
@ -82,7 +82,7 @@ where
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ZeroCopy::new(lines, f)
|
ZeroCopy::make(lines, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_names(
|
pub fn parse_names(
|
||||||
|
|
@ -209,7 +209,7 @@ pub fn parse_capabilities(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
unsafe { ZeroCopy::new(lines, f) }
|
unsafe { ZeroCopy::make(lines, f) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_mailbox(
|
pub fn parse_mailbox(
|
||||||
|
|
@ -294,7 +294,7 @@ pub fn parse_mailbox(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_ids(
|
pub fn parse_ids(
|
||||||
lines: Vec<u8>,
|
lines: &[u8],
|
||||||
unsolicited: &mut mpsc::Sender<UnsolicitedResponse>,
|
unsolicited: &mut mpsc::Sender<UnsolicitedResponse>,
|
||||||
) -> Result<HashSet<u32>> {
|
) -> Result<HashSet<u32>> {
|
||||||
let mut lines = &lines[..];
|
let mut lines = &lines[..];
|
||||||
|
|
@ -487,7 +487,7 @@ mod tests {
|
||||||
* 1 RECENT\r\n\
|
* 1 RECENT\r\n\
|
||||||
* STATUS INBOX (MESSAGES 10 UIDNEXT 11 UIDVALIDITY 1408806928 UNSEEN 0)\r\n";
|
* STATUS INBOX (MESSAGES 10 UIDNEXT 11 UIDVALIDITY 1408806928 UNSEEN 0)\r\n";
|
||||||
let (mut send, recv) = mpsc::channel();
|
let (mut send, recv) = mpsc::channel();
|
||||||
let ids = parse_ids(lines.to_vec(), &mut send).unwrap();
|
let ids = parse_ids(lines, &mut send).unwrap();
|
||||||
|
|
||||||
assert_eq!(ids, [23, 42, 4711].iter().cloned().collect());
|
assert_eq!(ids, [23, 42, 4711].iter().cloned().collect());
|
||||||
|
|
||||||
|
|
@ -511,7 +511,7 @@ mod tests {
|
||||||
let lines = b"* SEARCH 1600 1698 1739 1781 1795 1885 1891 1892 1893 1898 1899 1901 1911 1926 1932 1933 1993 1994 2007 2032 2033 2041 2053 2062 2063 2065 2066 2072 2078 2079 2082 2084 2095 2100 2101 2102 2103 2104 2107 2116 2120 2135 2138 2154 2163 2168 2172 2189 2193 2198 2199 2205 2212 2213 2221 2227 2267 2275 2276 2295 2300 2328 2330 2332 2333 2334\r\n\
|
let lines = b"* SEARCH 1600 1698 1739 1781 1795 1885 1891 1892 1893 1898 1899 1901 1911 1926 1932 1933 1993 1994 2007 2032 2033 2041 2053 2062 2063 2065 2066 2072 2078 2079 2082 2084 2095 2100 2101 2102 2103 2104 2107 2116 2120 2135 2138 2154 2163 2168 2172 2189 2193 2198 2199 2205 2212 2213 2221 2227 2267 2275 2276 2295 2300 2328 2330 2332 2333 2334\r\n\
|
||||||
* SEARCH 2335 2336 2337 2338 2339 2341 2342 2347 2349 2350 2358 2359 2362 2369 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2390 2392 2397 2400 2401 2403 2405 2409 2411 2414 2417 2419 2420 2424 2426 2428 2439 2454 2456 2467 2468 2469 2490 2515 2519 2520 2521\r\n";
|
* SEARCH 2335 2336 2337 2338 2339 2341 2342 2347 2349 2350 2358 2359 2362 2369 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2390 2392 2397 2400 2401 2403 2405 2409 2411 2414 2417 2419 2420 2424 2426 2428 2439 2454 2456 2467 2468 2469 2490 2515 2519 2520 2521\r\n";
|
||||||
let (mut send, recv) = mpsc::channel();
|
let (mut send, recv) = mpsc::channel();
|
||||||
let ids = parse_ids(lines.to_vec(), &mut send).unwrap();
|
let ids = parse_ids(lines, &mut send).unwrap();
|
||||||
assert!(recv.try_recv().is_err());
|
assert!(recv.try_recv().is_err());
|
||||||
let ids: HashSet<u32> = ids.iter().cloned().collect();
|
let ids: HashSet<u32> = ids.iter().cloned().collect();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
@ -534,7 +534,7 @@ mod tests {
|
||||||
|
|
||||||
let lines = b"* SEARCH\r\n";
|
let lines = b"* SEARCH\r\n";
|
||||||
let (mut send, recv) = mpsc::channel();
|
let (mut send, recv) = mpsc::channel();
|
||||||
let ids = parse_ids(lines.to_vec(), &mut send).unwrap();
|
let ids = parse_ids(lines, &mut send).unwrap();
|
||||||
assert!(recv.try_recv().is_err());
|
assert!(recv.try_recv().is_err());
|
||||||
let ids: HashSet<u32> = ids.iter().cloned().collect();
|
let ids: HashSet<u32> = ids.iter().cloned().collect();
|
||||||
assert_eq!(ids, HashSet::<u32>::new());
|
assert_eq!(ids, HashSet::<u32>::new());
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ pub struct Fetch {
|
||||||
|
|
||||||
impl Fetch {
|
impl Fetch {
|
||||||
/// A list of flags that are set for this message.
|
/// A list of flags that are set for this message.
|
||||||
pub fn flags<'a>(&'a self) -> &'a [Flag<'a>] {
|
pub fn flags(&self) -> &[Flag] {
|
||||||
&self.flags[..]
|
&self.flags[..]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -106,7 +106,7 @@ impl Fetch {
|
||||||
///
|
///
|
||||||
/// See [section 7.4.2 of RFC 3501](https://tools.ietf.org/html/rfc3501#section-7.4.2) for
|
/// See [section 7.4.2 of RFC 3501](https://tools.ietf.org/html/rfc3501#section-7.4.2) for
|
||||||
/// details.
|
/// details.
|
||||||
pub fn section(&self, path: SectionPath) -> Option<&[u8]> {
|
pub fn section(&self, path: &SectionPath) -> Option<&[u8]> {
|
||||||
self.fetch
|
self.fetch
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|av| match av {
|
.filter_map(|av| match av {
|
||||||
|
|
@ -114,7 +114,7 @@ impl Fetch {
|
||||||
section: Some(sp),
|
section: Some(sp),
|
||||||
data: Some(data),
|
data: Some(data),
|
||||||
..
|
..
|
||||||
} if sp == &path => Some(*data),
|
} if sp == path => Some(*data),
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
.next()
|
.next()
|
||||||
|
|
|
||||||
|
|
@ -285,7 +285,7 @@ impl<D> ZeroCopy<D> {
|
||||||
/// `&self`.
|
/// `&self`.
|
||||||
///
|
///
|
||||||
/// It is *not* safe for the error type `E` to borrow from the passed reference.
|
/// It is *not* safe for the error type `E` to borrow from the passed reference.
|
||||||
pub(crate) unsafe fn new<F, E>(owned: Vec<u8>, derive: F) -> Result<Self, E>
|
pub(crate) unsafe fn make<F, E>(owned: Vec<u8>, derive: F) -> Result<Self, E>
|
||||||
where
|
where
|
||||||
F: FnOnce(&'static [u8]) -> Result<D, E>,
|
F: FnOnce(&'static [u8]) -> Result<D, E>,
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue