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 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::<usize>()?;
if tag.starts_with(TAG_PREFIX) {
let id = tag.trim_start_matches(TAG_PREFIX).parse::<usize>()?;
let mut results = results.write();
if let Some((c, waker)) = results.get_mut(&id) {
*c = Some(resp);

View file

@ -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::*;

View file

@ -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<Capability>),
@ -13,7 +8,7 @@ pub enum Response {
information: Option<String>,
},
Done {
tag: RequestId,
tag: String,
status: Status,
code: Option<ResponseCode>,
information: Option<String>,
@ -32,44 +27,6 @@ pub enum Response {
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)]
pub enum Capability {
Imap4rev1,
@ -77,17 +34,6 @@ pub enum Capability {
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)]
pub enum ResponseCode {
Alert,
@ -107,24 +53,6 @@ pub enum ResponseCode {
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)]
pub enum UidSetMember {
UidRange(RangeInclusive<u32>),
@ -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,
}