From 4f3af86211e48ba7e92b5b603d66d8816694b09e Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Mon, 22 Feb 2021 14:43:09 -0600 Subject: [PATCH] rename the old shit --- imap/src/client/inner.rs | 53 +++++++++++++------------ imap/src/lib.rs | 13 +++---- imap/src/response/mod.rs | 83 +++++----------------------------------- 3 files changed, 42 insertions(+), 107 deletions(-) diff --git a/imap/src/client/inner.rs b/imap/src/client/inner.rs index 9f73a39..c529aa0 100644 --- a/imap/src/client/inner.rs +++ b/imap/src/client/inner.rs @@ -5,13 +5,12 @@ use std::task::{Context, Poll, Waker}; use anyhow::{Context as AnyhowContext, Result}; use futures::future::{self, Either, Future, FutureExt}; -use parking_lot::{Mutex, RwLock}; +use parking_lot::RwLock; use tokio::{ io::{ - self, AsyncBufRead, AsyncBufReadExt, AsyncRead, AsyncWrite, AsyncWriteExt, BufReader, - ReadHalf, WriteHalf, + self, AsyncBufReadExt, AsyncRead, AsyncWrite, AsyncWriteExt, BufReader, ReadHalf, WriteHalf, }, - sync::{mpsc, oneshot}, + sync::mpsc, task::JoinHandle, }; use tokio_rustls::{ @@ -19,8 +18,8 @@ use tokio_rustls::{ }; use crate::command::Command; -use crate::response::{Capability, Response, ResponseCode}; -use crate::types::{Capability as Capability_, Status}; +use crate::response::{Capability, Response, ResponseCode, Status}; +// use crate::types::{Capability as Capability_, Status}; use super::ClientConfig; @@ -166,17 +165,17 @@ where let cap_bytes = cap.as_bytes(); debug!("cap_bytes {:?}", cap_bytes); - let (_, cap) = match crate::oldparser::rfc3501::capability(cap_bytes) { - Ok(v) => v, - Err(err) => { - error!("ERROR PARSING {:?} {} {:?}", cap, err, err); - use std::error::Error; - let bt = err.backtrace().unwrap(); - error!("{}", bt); - std::process::exit(1); - } - }; - let cap = Capability::from(cap); + // let (_, cap) = match crate::oldparser::rfc3501::capability(cap_bytes) { + // Ok(v) => v, + // Err(err) => { + // error!("ERROR PARSING {:?} {} {:?}", cap, err, err); + // use std::error::Error; + // let bt = err.backtrace().unwrap(); + // error!("{}", bt); + // std::process::exit(1); + // } + // }; + let cap = Capability::from(Capability::Atom(cap)); let caps = &*self.caps.read(); // TODO: refresh caps @@ -258,13 +257,14 @@ where } debug!("got a new line {:?}", next_line); - let (_, resp) = match crate::oldparser::parse_response(next_line.as_bytes()) { - Ok(v) => v, - Err(err) => { - debug!("shiet: {:?}", err); - continue; - } - }; + let resp = Response::Capabilities(vec![]); + // let (_, resp) = match crate::oldparser::parse_response(next_line.as_bytes()) { + // Ok(v) => v, + // Err(err) => { + // debug!("shiet: {:?}", err); + // continue; + // } + // }; if let Some(greeting) = greeting.take() { let (greeting, waker) = &mut *greeting.write(); @@ -299,9 +299,8 @@ where } Response::Done { tag, .. } => { - let tag_str = &tag.0; - if tag_str.starts_with(TAG_PREFIX) { - let id = tag_str.trim_start_matches(TAG_PREFIX).parse::()?; + if tag.starts_with(TAG_PREFIX) { + let id = tag.trim_start_matches(TAG_PREFIX).parse::()?; let mut results = results.write(); if let Some((c, waker)) = results.get_mut(&id) { *c = Some(resp); diff --git a/imap/src/lib.rs b/imap/src/lib.rs index b7a5439..4846616 100644 --- a/imap/src/lib.rs +++ b/imap/src/lib.rs @@ -1,5 +1,3 @@ -#![feature(backtrace)] - #[macro_use] extern crate anyhow; #[macro_use] @@ -9,12 +7,13 @@ extern crate futures; #[macro_use] extern crate log; -pub mod builders; pub mod client; pub mod command; -pub mod oldparser; pub mod response; -pub mod types; -pub use crate::oldparser::ParseResult; -pub use crate::types::*; +// pub mod builders; +// pub mod oldparser; +// pub mod types; + +// pub use crate::oldparser::ParseResult; +// pub use crate::types::*; diff --git a/imap/src/response/mod.rs b/imap/src/response/mod.rs index ba009f1..df8af08 100644 --- a/imap/src/response/mod.rs +++ b/imap/src/response/mod.rs @@ -1,10 +1,5 @@ use std::ops::RangeInclusive; -use crate::types::{ - AttributeValue as AttributeValue_, Capability as Capability_, MailboxDatum as MailboxDatum_, - RequestId, Response as Response_, ResponseCode as ResponseCode_, State, Status, -}; - #[derive(Clone, Debug)] pub enum Response { Capabilities(Vec), @@ -13,7 +8,7 @@ pub enum Response { information: Option, }, Done { - tag: RequestId, + tag: String, status: Status, code: Option, information: Option, @@ -32,44 +27,6 @@ pub enum Response { MailboxData(MailboxDatum), } -impl<'a> From> for Response { - fn from(b: Response_) -> Self { - use Response_::*; - match b { - Capabilities(caps) => { - Response::Capabilities(caps.into_iter().map(Capability::from).collect()) - } - Continue { code, information } => Response::Continue { - code: code.map(ResponseCode::from), - information: information.map(str::to_owned), - }, - Done { - tag, - status, - code, - information, - } => Response::Done { - tag, - status, - code: code.map(ResponseCode::from), - information: information.map(str::to_owned), - }, - Data { - status, - code, - information, - } => Response::Data { - status, - code: code.map(ResponseCode::from), - information: information.map(str::to_owned), - }, - Expunge(n) => Response::Expunge(n), - Vanished { earlier, uids } => Response::Vanished { earlier, uids }, - _ => todo!("nyi: {:?}", b), - } - } -} - #[derive(Clone, Debug, Hash, PartialEq, Eq)] pub enum Capability { Imap4rev1, @@ -77,17 +34,6 @@ pub enum Capability { Atom(String), } -impl<'a> From> for Capability { - fn from(b: Capability_) -> Self { - use Capability_::*; - match b { - Imap4rev1 => Capability::Imap4rev1, - Auth(s) => Capability::Auth(s.to_owned()), - Atom(s) => Capability::Atom(s.to_owned()), - } - } -} - #[derive(Clone, Debug)] pub enum ResponseCode { Alert, @@ -107,24 +53,6 @@ pub enum ResponseCode { UidNotSticky, } -impl<'a> From> for ResponseCode { - fn from(b: ResponseCode_) -> Self { - use ResponseCode_::*; - match b { - Alert => ResponseCode::Alert, - BadCharset(s) => { - ResponseCode::BadCharset(s.map(|v| v.into_iter().map(str::to_owned).collect())) - } - Capabilities(v) => { - ResponseCode::Capabilities(v.into_iter().map(Capability::from).collect()) - } - HighestModSeq(n) => ResponseCode::HighestModSeq(n), - Parse => ResponseCode::Parse, - _ => todo!("nyi: {:?}", b), - } - } -} - #[derive(Clone, Debug)] pub enum UidSetMember { UidRange(RangeInclusive), @@ -136,3 +64,12 @@ pub enum AttributeValue {} #[derive(Clone, Debug)] pub enum MailboxDatum {} + +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum Status { + Ok, + No, + Bad, + PreAuth, + Bye, +}