rename the old shit

This commit is contained in:
Michael Zhang 2021-02-22 14:43:09 -06:00
parent aa3578999c
commit 4f3af86211
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
3 changed files with 42 additions and 107 deletions

View file

@ -5,13 +5,12 @@ use std::task::{Context, Poll, Waker};
use anyhow::{Context as AnyhowContext, Result}; use anyhow::{Context as AnyhowContext, Result};
use futures::future::{self, Either, Future, FutureExt}; use futures::future::{self, Either, Future, FutureExt};
use parking_lot::{Mutex, RwLock}; use parking_lot::RwLock;
use tokio::{ use tokio::{
io::{ io::{
self, AsyncBufRead, AsyncBufReadExt, AsyncRead, AsyncWrite, AsyncWriteExt, BufReader, self, AsyncBufReadExt, AsyncRead, AsyncWrite, AsyncWriteExt, BufReader, ReadHalf, WriteHalf,
ReadHalf, WriteHalf,
}, },
sync::{mpsc, oneshot}, sync::mpsc,
task::JoinHandle, task::JoinHandle,
}; };
use tokio_rustls::{ use tokio_rustls::{
@ -19,8 +18,8 @@ use tokio_rustls::{
}; };
use crate::command::Command; use crate::command::Command;
use crate::response::{Capability, Response, ResponseCode}; use crate::response::{Capability, Response, ResponseCode, Status};
use crate::types::{Capability as Capability_, Status}; // use crate::types::{Capability as Capability_, Status};
use super::ClientConfig; use super::ClientConfig;
@ -166,17 +165,17 @@ where
let cap_bytes = cap.as_bytes(); let cap_bytes = cap.as_bytes();
debug!("cap_bytes {:?}", cap_bytes); debug!("cap_bytes {:?}", cap_bytes);
let (_, cap) = match crate::oldparser::rfc3501::capability(cap_bytes) { // let (_, cap) = match crate::oldparser::rfc3501::capability(cap_bytes) {
Ok(v) => v, // Ok(v) => v,
Err(err) => { // Err(err) => {
error!("ERROR PARSING {:?} {} {:?}", cap, err, err); // error!("ERROR PARSING {:?} {} {:?}", cap, err, err);
use std::error::Error; // use std::error::Error;
let bt = err.backtrace().unwrap(); // let bt = err.backtrace().unwrap();
error!("{}", bt); // error!("{}", bt);
std::process::exit(1); // std::process::exit(1);
} // }
}; // };
let cap = Capability::from(cap); let cap = Capability::from(Capability::Atom(cap));
let caps = &*self.caps.read(); let caps = &*self.caps.read();
// TODO: refresh caps // TODO: refresh caps
@ -258,13 +257,14 @@ where
} }
debug!("got a new line {:?}", next_line); debug!("got a new line {:?}", next_line);
let (_, resp) = match crate::oldparser::parse_response(next_line.as_bytes()) { let resp = Response::Capabilities(vec![]);
Ok(v) => v, // let (_, resp) = match crate::oldparser::parse_response(next_line.as_bytes()) {
Err(err) => { // Ok(v) => v,
debug!("shiet: {:?}", err); // Err(err) => {
continue; // debug!("shiet: {:?}", err);
} // continue;
}; // }
// };
if let Some(greeting) = greeting.take() { if let Some(greeting) = greeting.take() {
let (greeting, waker) = &mut *greeting.write(); let (greeting, waker) = &mut *greeting.write();
@ -299,9 +299,8 @@ where
} }
Response::Done { tag, .. } => { Response::Done { tag, .. } => {
let tag_str = &tag.0; if tag.starts_with(TAG_PREFIX) {
if tag_str.starts_with(TAG_PREFIX) { let id = tag.trim_start_matches(TAG_PREFIX).parse::<usize>()?;
let id = tag_str.trim_start_matches(TAG_PREFIX).parse::<usize>()?;
let mut results = results.write(); let mut results = results.write();
if let Some((c, waker)) = results.get_mut(&id) { if let Some((c, waker)) = results.get_mut(&id) {
*c = Some(resp); *c = Some(resp);

View file

@ -1,5 +1,3 @@
#![feature(backtrace)]
#[macro_use] #[macro_use]
extern crate anyhow; extern crate anyhow;
#[macro_use] #[macro_use]
@ -9,12 +7,13 @@ extern crate futures;
#[macro_use] #[macro_use]
extern crate log; extern crate log;
pub mod builders;
pub mod client; pub mod client;
pub mod command; pub mod command;
pub mod oldparser;
pub mod response; pub mod response;
pub mod types;
pub use crate::oldparser::ParseResult; // pub mod builders;
pub use crate::types::*; // pub mod oldparser;
// pub mod types;
// pub use crate::oldparser::ParseResult;
// pub use crate::types::*;

View file

@ -1,10 +1,5 @@
use std::ops::RangeInclusive; 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)] #[derive(Clone, Debug)]
pub enum Response { pub enum Response {
Capabilities(Vec<Capability>), Capabilities(Vec<Capability>),
@ -13,7 +8,7 @@ pub enum Response {
information: Option<String>, information: Option<String>,
}, },
Done { Done {
tag: RequestId, tag: String,
status: Status, status: Status,
code: Option<ResponseCode>, code: Option<ResponseCode>,
information: Option<String>, information: Option<String>,
@ -32,44 +27,6 @@ pub enum Response {
MailboxData(MailboxDatum), MailboxData(MailboxDatum),
} }
impl<'a> From<Response_<'a>> 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)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub enum Capability { pub enum Capability {
Imap4rev1, Imap4rev1,
@ -77,17 +34,6 @@ pub enum Capability {
Atom(String), Atom(String),
} }
impl<'a> From<Capability_<'a>> 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)] #[derive(Clone, Debug)]
pub enum ResponseCode { pub enum ResponseCode {
Alert, Alert,
@ -107,24 +53,6 @@ pub enum ResponseCode {
UidNotSticky, UidNotSticky,
} }
impl<'a> From<ResponseCode_<'a>> 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)] #[derive(Clone, Debug)]
pub enum UidSetMember { pub enum UidSetMember {
UidRange(RangeInclusive<u32>), UidRange(RangeInclusive<u32>),
@ -136,3 +64,12 @@ pub enum AttributeValue {}
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub enum MailboxDatum {} pub enum MailboxDatum {}
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum Status {
Ok,
No,
Bad,
PreAuth,
Bye,
}