Compare commits
2 commits
fc5f093564
...
01ee8c872b
Author | SHA1 | Date | |
---|---|---|---|
01ee8c872b | |||
2af6a7d781 |
8 changed files with 116 additions and 39 deletions
|
@ -1,32 +0,0 @@
|
||||||
use imap_codec::types::response::Data as ImapData;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum Body {
|
|
||||||
Once(Vec<ImapData>),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Body {
|
|
||||||
pub(crate) fn into_data(self) -> Vec<ImapData> {
|
|
||||||
match self {
|
|
||||||
Body::Once(data) => data,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FromIterator<ImapData> for Body {
|
|
||||||
fn from_iter<T: IntoIterator<Item = ImapData>>(iter: T) -> Self {
|
|
||||||
Body::Once(Vec::from_iter(iter))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<Vec<ImapData>> for Body {
|
|
||||||
fn from(data: Vec<ImapData>) -> Self {
|
|
||||||
Body::from_iter(data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<ImapData> for Body {
|
|
||||||
fn from(data: ImapData) -> Self {
|
|
||||||
Body::from_iter([data])
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,6 +1,5 @@
|
||||||
pub use self::req::Request;
|
pub use self::req::Request;
|
||||||
pub use self::res::Response;
|
pub use self::res::Response;
|
||||||
|
|
||||||
pub mod body;
|
|
||||||
pub mod req;
|
pub mod req;
|
||||||
pub mod res;
|
pub mod res;
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
use imap_codec::types::command::Command;
|
|
||||||
|
|
||||||
pub type Request = Command;
|
|
5
src/proto/req/mod.rs
Normal file
5
src/proto/req/mod.rs
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
use imap_codec::types::command::Command;
|
||||||
|
|
||||||
|
pub struct Request {
|
||||||
|
pub command: Command,
|
||||||
|
}
|
74
src/proto/res/body.rs
Normal file
74
src/proto/res/body.rs
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
use std::io;
|
||||||
|
|
||||||
|
use imap_codec::codec::Encode;
|
||||||
|
use imap_codec::types::response::{Data as ImapData, Status as ImapStatus};
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum Body {
|
||||||
|
Once(Vec<Data>),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Body {
|
||||||
|
pub(crate) fn into_data(self) -> Vec<Data> {
|
||||||
|
match self {
|
||||||
|
Body::Once(data) => data,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromIterator<Data> for Body {
|
||||||
|
fn from_iter<T: IntoIterator<Item = Data>>(iter: T) -> Self {
|
||||||
|
Body::Once(Vec::from_iter(iter))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromIterator<ImapData> for Body {
|
||||||
|
fn from_iter<T: IntoIterator<Item = ImapData>>(iter: T) -> Self {
|
||||||
|
Body::from_iter(iter.into_iter().map(Data::Data))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Vec<Data>> for Body {
|
||||||
|
fn from(body: Vec<Data>) -> Self {
|
||||||
|
Body::from_iter(body)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Vec<ImapData>> for Body {
|
||||||
|
fn from(data: Vec<ImapData>) -> Self {
|
||||||
|
Body::from_iter(data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<ImapData> for Body {
|
||||||
|
fn from(data: ImapData) -> Self {
|
||||||
|
Body::from_iter([data])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub enum Data {
|
||||||
|
Data(ImapData),
|
||||||
|
Status(ImapStatus),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Encode for Data {
|
||||||
|
fn encode(&self, writer: &mut impl io::Write) -> std::io::Result<()> {
|
||||||
|
match self {
|
||||||
|
Data::Data(ref data) => data.encode(writer),
|
||||||
|
Data::Status(ref status) => status.encode(writer),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<ImapData> for Data {
|
||||||
|
fn from(data: ImapData) -> Self {
|
||||||
|
Data::Data(data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<ImapStatus> for Data {
|
||||||
|
fn from(status: ImapStatus) -> Self {
|
||||||
|
Data::Status(status)
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,9 +3,11 @@ use imap_codec::types::{
|
||||||
response::{Code as ImapCode, Status as ImapStatus},
|
response::{Code as ImapCode, Status as ImapStatus},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::body::Body;
|
use self::body::Body;
|
||||||
use crate::errors::{Error, Result};
|
use crate::errors::{Error, Result};
|
||||||
|
|
||||||
|
pub mod body;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Response {
|
pub struct Response {
|
||||||
pub(crate) status: Status,
|
pub(crate) status: Status,
|
|
@ -157,7 +157,7 @@ where
|
||||||
fn call(&mut self, req: Request) -> Self::Future {
|
fn call(&mut self, req: Request) -> Self::Future {
|
||||||
use futures::{FutureExt, TryFutureExt};
|
use futures::{FutureExt, TryFutureExt};
|
||||||
|
|
||||||
let tag = req.tag.clone();
|
let tag = req.command.tag.clone();
|
||||||
|
|
||||||
self.inner.call(req).map_ok(|res| (Some(tag), res)).boxed()
|
self.inner.call(req).map_ok(|res| (Some(tag), res)).boxed()
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ where
|
||||||
|
|
||||||
*this.read_buf = input.into();
|
*this.read_buf = input.into();
|
||||||
|
|
||||||
let req = command;
|
let req = Request { command };
|
||||||
return Poll::Ready(Some(Ok(req)));
|
return Poll::Ready(Some(Ok(req)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -146,3 +146,35 @@ where
|
||||||
Poll::Ready(Ok(()))
|
Poll::Ready(Ok(()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<C> Sink<Response> for Connection<C>
|
||||||
|
where
|
||||||
|
Self: Sink<(Option<Tag>, Response)>,
|
||||||
|
{
|
||||||
|
type Error = <Connection<C> as Sink<(Option<Tag>, Response)>>::Error;
|
||||||
|
|
||||||
|
fn poll_ready(
|
||||||
|
self: Pin<&mut Self>,
|
||||||
|
cx: &mut task::Context<'_>,
|
||||||
|
) -> Poll<Result<(), Self::Error>> {
|
||||||
|
<Self as Sink<(Option<Tag>, Response)>>::poll_ready(self, cx)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn start_send(self: Pin<&mut Self>, item: Response) -> Result<(), Self::Error> {
|
||||||
|
<Self as Sink<(Option<Tag>, Response)>>::start_send(self, (None, item))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn poll_flush(
|
||||||
|
self: Pin<&mut Self>,
|
||||||
|
cx: &mut task::Context<'_>,
|
||||||
|
) -> Poll<Result<(), Self::Error>> {
|
||||||
|
<Self as Sink<(Option<Tag>, Response)>>::poll_flush(self, cx)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn poll_close(
|
||||||
|
self: Pin<&mut Self>,
|
||||||
|
cx: &mut task::Context<'_>,
|
||||||
|
) -> Poll<Result<(), Self::Error>> {
|
||||||
|
<Self as Sink<(Option<Tag>, Response)>>::poll_close(self, cx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue