From aae287c8b12fc423070ca638fcd9dff5cf73bff5 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Sun, 8 Aug 2021 18:45:18 -0500 Subject: [PATCH] get rid of warnings --- imap/bin/greenmail_test.rs | 14 +++++++++++++- imap/src/client/auth.rs | 2 +- imap/src/client/inner.rs | 2 +- imap/src/client/mod.rs | 5 +++-- imap/src/codec.rs | 4 ++-- imap/src/lib.rs | 10 ++++------ imap/src/proto/macros.rs | 28 ++++++++++++++-------------- imap/src/proto/parsers.rs | 38 +++++++++++++++++++++++++++++--------- imap/src/proto/rfc3501.rs | 12 ++++++------ 9 files changed, 73 insertions(+), 42 deletions(-) diff --git a/imap/bin/greenmail_test.rs b/imap/bin/greenmail_test.rs index 7f755fb..87aa1d3 100644 --- a/imap/bin/greenmail_test.rs +++ b/imap/bin/greenmail_test.rs @@ -1,2 +1,14 @@ +use anyhow::Result; +use imap::client::ConfigBuilder; + #[tokio::main] -async fn main() {} +async fn main() -> Result<()> { + let _client = ConfigBuilder::default() + .hostname(String::from("localhost")) + .port(3993) + .tls(true) + .connect() + .await?; + + Ok(()) +} diff --git a/imap/src/client/auth.rs b/imap/src/client/auth.rs index 7999858..775da45 100644 --- a/imap/src/client/auth.rs +++ b/imap/src/client/auth.rs @@ -28,6 +28,6 @@ impl AuthMethod for Login { password: &self.password, }); - let result = inner.execute(command).await; + let _result = inner.execute(command).await; } } diff --git a/imap/src/client/inner.rs b/imap/src/client/inner.rs index 9477f09..5e6e363 100644 --- a/imap/src/client/inner.rs +++ b/imap/src/client/inner.rs @@ -44,7 +44,7 @@ where }) } - pub async fn execute<'a>(&mut self, command: Command<'a>) {} + pub async fn execute<'a>(&mut self, _command: Command<'a>) {} pub async fn upgrade(self) -> Result>> { // TODO: check that this capability exists?? diff --git a/imap/src/client/mod.rs b/imap/src/client/mod.rs index 712a0dc..4071b3e 100644 --- a/imap/src/client/mod.rs +++ b/imap/src/client/mod.rs @@ -4,16 +4,17 @@ pub mod upgrade; use anyhow::Result; -#[derive(Debug, Builder)] +#[derive(Clone, Debug, Builder)] #[builder(build_fn(skip))] pub struct Config { // (required for TLS) hostname: String, + port: u16, tls: bool, } impl ConfigBuilder { - pub async fn build() -> Result { todo!() } + pub async fn connect(&self) -> Result { todo!() } } pub struct Client; diff --git a/imap/src/codec.rs b/imap/src/codec.rs index 0b4f5f2..2a15c6d 100644 --- a/imap/src/codec.rs +++ b/imap/src/codec.rs @@ -80,7 +80,7 @@ pub struct OwnedResponse { } impl OwnedResponse { - pub fn request_id(&self) -> Option<&Tag> { + pub fn _request_id(&self) -> Option<&Tag> { match self.response { Response::Done(ResponseDone { ref tag, .. }) => Some(tag), _ => None, @@ -88,5 +88,5 @@ impl OwnedResponse { } #[allow(clippy::needless_lifetimes)] - pub fn parsed<'a>(&'a self) -> &'a Response<'a> { &self.response } + pub fn _parsed<'a>(&'a self) -> &'a Response<'a> { &self.response } } diff --git a/imap/src/lib.rs b/imap/src/lib.rs index d88ae60..10ca898 100644 --- a/imap/src/lib.rs +++ b/imap/src/lib.rs @@ -1,8 +1,8 @@ -#[macro_use] +// #[macro_use] extern crate anyhow; #[macro_use] extern crate async_trait; -#[macro_use] +// #[macro_use] extern crate log; #[macro_use] extern crate futures; @@ -11,9 +11,7 @@ extern crate derive_builder; #[macro_use] extern crate bitflags; -// mod auth; pub mod client; -mod codec; -mod events; -// mod inner; +pub mod codec; +pub mod events; pub mod proto; diff --git a/imap/src/proto/macros.rs b/imap/src/proto/macros.rs index f0a4a0a..ddfc4bc 100644 --- a/imap/src/proto/macros.rs +++ b/imap/src/proto/macros.rs @@ -6,18 +6,18 @@ macro_rules! rule { }; } -macro_rules! pred { - ($($expr:tt)*) => { |c: u8| _pred!(expr { $($expr)* })(c) }; -} +// macro_rules! pred { +// ($($expr:tt)*) => { |c: u8| _pred!(expr { $($expr)* })(c) }; +// } -macro_rules! _pred { - (expr {}) => {}; - (expr { $name:ident }) => { |b| $name(b) }; - (expr { ! $($expr:tt)* }) => { |b| !_pred!(expr { $($expr)* })(b) }; - (expr { ($($L:tt)*) && ($($R:tt)*) }) => { - |b| { _pred!(expr { $($L)* })(b) && _pred!(expr { $($R)* })(b) } - }; - (expr { ($($L:tt)*) || ($($R:tt)*) }) => { - |b| { _pred!(expr { $($L)* })(b) || _pred!(expr { $($R)* })(b) } - }; -} +// macro_rules! _pred { +// (expr {}) => {}; +// (expr { $name:ident }) => { |b| $name(b) }; +// (expr { ! $($expr:tt)* }) => { |b| !_pred!(expr { $($expr)* })(b) }; +// (expr { ($($L:tt)*) && ($($R:tt)*) }) => { +// |b| { _pred!(expr { $($L)* })(b) && _pred!(expr { $($R)* })(b) } +// }; +// (expr { ($($L:tt)*) || ($($R:tt)*) }) => { +// |b| { _pred!(expr { $($L)* })(b) || _pred!(expr { $($R)* })(b) } +// }; +// } diff --git a/imap/src/proto/parsers.rs b/imap/src/proto/parsers.rs index 4ef6211..df6842f 100644 --- a/imap/src/proto/parsers.rs +++ b/imap/src/proto/parsers.rs @@ -7,20 +7,40 @@ use nom::{ macro_rules! sep_list { ($t:expr) => { - map(pair($t, many0(preceded(crate::proto::rfc2234::SP, $t))), - |(hd, mut tl)| { tl.insert(0, hd); tl }) + map( + pair($t, many0(preceded(crate::proto::rfc2234::SP, $t))), + |(hd, mut tl)| { + tl.insert(0, hd); + tl + }, + ) }; ($t:expr, $d:expr) => { - map(pair($t, many0(preceded($d, $t))), - |(hd, mut tl)| { tl.insert(0, hd); tl }) + map(pair($t, many0(preceded($d, $t))), |(hd, mut tl)| { + tl.insert(0, hd); + tl + }) }; (? $t:expr) => { - map(opt(pair($t, many0(preceded(crate::proto::rfc2234::SP, $t)))), - |opt| opt.map(|(hd, mut tl)| { tl.insert(0, hd); tl }).unwrap_or_else(Vec::new)) + map( + opt(pair($t, many0(preceded(crate::proto::rfc2234::SP, $t)))), + |opt| { + opt.map(|(hd, mut tl)| { + tl.insert(0, hd); + tl + }) + .unwrap_or_else(Vec::new) + }, + ) }; (? $t:expr, $d:expr) => { - map(opt(pair($t, many0(preceded($d, $t)))), - |opt| opt.map(|(hd, mut tl)| { tl.insert(0, hd); tl }).unwrap_or_else(Vec::new)) + map(opt(pair($t, many0(preceded($d, $t)))), |opt| { + opt.map(|(hd, mut tl)| { + tl.insert(0, hd); + tl + }) + .unwrap_or_else(Vec::new) + }) }; } @@ -28,7 +48,7 @@ pub fn never(i: I) -> IResult { Err(Err::Error(Error::new(i, ErrorKi pub fn skip(mut f: F) -> impl FnMut(I) -> IResult where -I: Clone, + I: Clone, F: Parser, { move |i: I| match f.parse(i.clone()) { diff --git a/imap/src/proto/rfc3501.rs b/imap/src/proto/rfc3501.rs index 19b0ed6..08ac95b 100644 --- a/imap/src/proto/rfc3501.rs +++ b/imap/src/proto/rfc3501.rs @@ -6,16 +6,16 @@ use nom::{ branch::alt, bytes::streaming::{tag_no_case, take, take_while1}, character::streaming::char, - combinator::{map, verify, map_res, opt}, - multi::{many0}, - sequence::{delimited, pair, tuple, preceded, separated_pair, terminated}, + combinator::{map, map_res, opt, verify}, + multi::many0, + sequence::{delimited, pair, preceded, separated_pair, terminated, tuple}, IResult, }; use super::parsers::{byte, never, satisfy}; use super::response::{ - Atom, Capability, Condition, CowU8, Flag, Mailbox, MailboxData, MailboxList, MailboxListFlag, - Response, ResponseCode, Status, Tag, MessageAttribute, Envelope, ResponseText, + Atom, Capability, Condition, CowU8, Envelope, Flag, Mailbox, MailboxData, MailboxList, + MailboxListFlag, MessageAttribute, Response, ResponseCode, ResponseText, Status, Tag, }; use super::rfc2234::{is_char, is_cr, is_ctl, is_digit, is_dquote, is_lf, is_sp, CRLF, DQUOTE, SP}; @@ -183,7 +183,7 @@ rule!(pub QUOTED_CHAR : u8 => alt((satisfy(is_quoted_char), preceded(byte(b'\\') pub(crate) fn is_quoted_specials(c: u8) -> bool { is_dquote(c) || c == b'\\' } rule!(pub quoted_specials : u8 => satisfy(is_quoted_specials)); -// TODO: technically, this is supposed to be +// TODO: technically, this is supposed to be rule!(pub response : Response => alt((continue_req, response_data, response_done))); rule!(pub response_data : Response => delimited(pair(byte(b'*'), SP), alt((