This commit is contained in:
Michael Zhang 2021-08-08 14:31:18 -05:00
parent c1e770e050
commit a22a2ee35c
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
9 changed files with 45 additions and 13 deletions

View file

@ -1,2 +1,5 @@
fmt:
cargo +nightly fmt --all
greenmail-test:
cargo run -p imap --bin greenmail-test

View file

@ -1,4 +1,2 @@
#[tokio::main]
async fn main() {
}
async fn main() {}

View file

@ -1,7 +1,7 @@
use tokio::io::{AsyncRead, AsyncWrite};
use crate::proto::command::{Command, CommandLogin};
use crate::client::inner::Inner;
use crate::proto::command::{Command, CommandLogin};
pub trait Client: AsyncRead + AsyncWrite + Unpin + Sync + Send + 'static {}

View file

@ -1,5 +1,5 @@
use anyhow::Result;
use futures::future::FutureExt;
use futures::{future::FutureExt, stream::StreamExt};
use tokio::{
io::{split, AsyncRead, AsyncWrite, ReadHalf, WriteHalf},
sync::oneshot,
@ -71,12 +71,18 @@ where
{
// set up framed communication
let codec = ImapCodec::default();
let framed = FramedRead::new(stream, codec);
let mut framed = FramedRead::new(stream, codec);
let exit = exit.fuse();
pin_mut!(exit);
loop {
let next = framed.next().fuse();
pin_mut!(next);
select! {
msg = next => {
println!("hellosu {:?}", msg);
}
_ = exit => break,
}
}

View file

@ -1,3 +1,19 @@
pub mod auth;
pub mod inner;
pub mod upgrade;
use anyhow::Result;
#[derive(Debug, Builder)]
#[builder(build_fn(skip))]
pub struct Config {
// (required for TLS)
hostname: String,
tls: bool,
}
impl ConfigBuilder {
pub async fn build() -> Result<Client> { todo!() }
}
pub struct Client;

View file

@ -1,6 +1,6 @@
use std::io;
use bytes::{BufMut, Bytes, BytesMut};
use bytes::{Bytes, BytesMut};
use tokio_util::codec::{Decoder, Encoder};
@ -15,7 +15,7 @@ pub struct ImapCodec {
}
impl<'a> Decoder for ImapCodec {
type Item = ResponseData;
type Item = OwnedResponse;
type Error = io::Error;
fn decode(&mut self, buf: &mut BytesMut) -> Result<Option<Self::Item>, io::Error> {
if self.decode_need_message_bytes > buf.len() {
@ -55,7 +55,7 @@ impl<'a> Decoder for ImapCodec {
impl<'a> Encoder<&'a Command<'a>> for ImapCodec {
type Error = io::Error;
fn encode(&mut self, msg: &Command, dst: &mut BytesMut) -> Result<(), io::Error> {
fn encode(&mut self, _msg: &Command, _dst: &mut BytesMut) -> Result<(), io::Error> {
todo!()
// dst.put(&*msg.0);
// dst.put_u8(b' ');
@ -66,7 +66,7 @@ impl<'a> Encoder<&'a Command<'a>> for ImapCodec {
}
#[derive(Debug)]
pub struct ResponseData {
pub struct OwnedResponse {
raw: Bytes,
// This reference is really scoped to the lifetime of the `raw`
// member, but unfortunately Rust does not allow that yet. It
@ -79,7 +79,7 @@ pub struct ResponseData {
response: Response<'static>,
}
impl ResponseData {
impl OwnedResponse {
pub fn request_id(&self) -> Option<&Tag> {
match self.response {
Response::Done(ResponseDone { ref tag, .. }) => Some(tag),

View file

@ -4,6 +4,7 @@ use std::borrow::Cow;
pub struct Tag(pub String);
#[derive(Debug)]
#[non_exhaustive]
pub enum Response<'a> {
Done(ResponseDone<'a>),
}
@ -16,6 +17,13 @@ pub struct ResponseDone<'a> {
pub info: Option<Cow<'a, str>>,
}
#[derive(Debug)]
pub struct Condition<'a> {
pub status: Status,
pub code: Option<ResponseCode<'a>>,
pub text: String,
}
#[derive(Debug)]
pub enum Status {
Ok,
@ -26,6 +34,7 @@ pub enum Status {
}
#[derive(Debug)]
#[non_exhaustive]
pub enum ResponseCode<'a> {
Alert,
Capabilities(Vec<Capability<'a>>),