aboutsummaryrefslogtreecommitdiff
path: root/aero-proto
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2024-03-08 09:55:33 +0100
committerQuentin Dufour <quentin@deuxfleurs.fr>2024-03-08 09:55:33 +0100
commit11462f80c4ae25696c7436ed7aacb92074d7e911 (patch)
tree333677df5ea981b0e1468b43fc00df9d242ad4fa /aero-proto
parent1edf0b15ecaa73d55bb72c6f3c6e25d4f231f322 (diff)
downloadaerogramme-11462f80c4ae25696c7436ed7aacb92074d7e911.tar.gz
aerogramme-11462f80c4ae25696c7436ed7aacb92074d7e911.zip
Re-enable proto
Diffstat (limited to 'aero-proto')
-rw-r--r--aero-proto/Cargo.toml35
-rw-r--r--aero-proto/src/dav.rs (renamed from aero-proto/dav.rs)11
-rw-r--r--aero-proto/src/imap/attributes.rs (renamed from aero-proto/imap/attributes.rs)0
-rw-r--r--aero-proto/src/imap/capability.rs (renamed from aero-proto/imap/capability.rs)0
-rw-r--r--aero-proto/src/imap/command/anonymous.rs (renamed from aero-proto/imap/command/anonymous.rs)5
-rw-r--r--aero-proto/src/imap/command/anystate.rs (renamed from aero-proto/imap/command/anystate.rs)0
-rw-r--r--aero-proto/src/imap/command/authenticated.rs (renamed from aero-proto/imap/command/authenticated.rs)15
-rw-r--r--aero-proto/src/imap/command/mod.rs (renamed from aero-proto/imap/command/mod.rs)2
-rw-r--r--aero-proto/src/imap/command/selected.rs (renamed from aero-proto/imap/command/selected.rs)5
-rw-r--r--aero-proto/src/imap/flags.rs (renamed from aero-proto/imap/flags.rs)0
-rw-r--r--aero-proto/src/imap/flow.rs (renamed from aero-proto/imap/flow.rs)3
-rw-r--r--aero-proto/src/imap/imf_view.rs (renamed from aero-proto/imap/imf_view.rs)0
-rw-r--r--aero-proto/src/imap/index.rs (renamed from aero-proto/imap/index.rs)4
-rw-r--r--aero-proto/src/imap/mail_view.rs (renamed from aero-proto/imap/mail_view.rs)2
-rw-r--r--aero-proto/src/imap/mailbox_view.rs (renamed from aero-proto/imap/mailbox_view.rs)12
-rw-r--r--aero-proto/src/imap/mime_view.rs (renamed from aero-proto/imap/mime_view.rs)2
-rw-r--r--aero-proto/src/imap/mod.rs (renamed from aero-proto/imap/mod.rs)12
-rw-r--r--aero-proto/src/imap/request.rs (renamed from aero-proto/imap/request.rs)0
-rw-r--r--aero-proto/src/imap/response.rs (renamed from aero-proto/imap/response.rs)0
-rw-r--r--aero-proto/src/imap/search.rs (renamed from aero-proto/imap/search.rs)3
-rw-r--r--aero-proto/src/imap/session.rs (renamed from aero-proto/imap/session.rs)8
-rw-r--r--aero-proto/src/lib.rs6
-rw-r--r--aero-proto/src/lmtp.rs (renamed from aero-proto/lmtp.rs)14
-rw-r--r--aero-proto/src/sasl.rs (renamed from aero-proto/sasl.rs)6
24 files changed, 95 insertions, 50 deletions
diff --git a/aero-proto/Cargo.toml b/aero-proto/Cargo.toml
new file mode 100644
index 0000000..df8c696
--- /dev/null
+++ b/aero-proto/Cargo.toml
@@ -0,0 +1,35 @@
+[package]
+name = "aero-proto"
+version = "0.3.0"
+authors = ["Alex Auvolat <alex@adnab.me>", "Quentin Dufour <quentin@dufour.io>"]
+edition = "2021"
+license = "EUPL-1.2"
+description = "Binding between Aerogramme's internal components and well-known protocols"
+
+[dependencies]
+aero-sasl.workspace = true
+aero-dav.workspace = true
+aero-user.workspace = true
+aero-collections.workspace = true
+
+async-trait.workspace = true
+anyhow.workspace = true
+hyper.workspace = true
+base64.workspace = true
+hyper-util.workspace = true
+http-body-util.workspace = true
+futures.workspace = true
+tokio.workspace = true
+tokio-util.workspace = true
+tokio-rustls.workspace = true
+rustls.workspace = true
+rustls-pemfile.workspace = true
+imap-codec.workspace = true
+imap-flow.workspace = true
+chrono.workspace = true
+eml-codec.workspace = true
+thiserror.workspace = true
+duplexify.workspace = true
+smtp-message.workspace = true
+smtp-server.workspace = true
+tracing.workspace = true
diff --git a/aero-proto/dav.rs b/aero-proto/src/dav.rs
index fa2023a..2852d34 100644
--- a/aero-proto/dav.rs
+++ b/aero-proto/src/dav.rs
@@ -11,9 +11,9 @@ use futures::stream::{FuturesUnordered, StreamExt};
use tokio::net::TcpListener;
use tokio::sync::watch;
-use crate::config::DavUnsecureConfig;
-use crate::login::ArcLoginProvider;
-use crate::user::User;
+use aero_user::config::DavUnsecureConfig;
+use aero_user::login::ArcLoginProvider;
+use aero_collections::user::User;
pub struct Server {
bind_addr: SocketAddr,
@@ -110,7 +110,7 @@ async fn auth(
// Call login provider
let creds = match login.login(username, password).await {
Ok(c) => c,
- Err(e) => return Ok(Response::builder()
+ Err(_) => return Ok(Response::builder()
.status(401)
.body(Full::new(Bytes::from("Wrong credentials")))?),
};
@@ -140,6 +140,7 @@ async fn router(user: std::sync::Arc<User>, req: Request<impl hyper::body::Body>
Ok(Response::new(Full::new(Bytes::from("Hello World!"))))
}
-async fn collections(user: std::sync::Arc<User>, req: Request<impl hyper::body::Body>) -> Result<Response<Full<Bytes>>> {
+#[allow(dead_code)]
+async fn collections(_user: std::sync::Arc<User>, _req: Request<impl hyper::body::Body>) -> Result<Response<Full<Bytes>>> {
unimplemented!();
}
diff --git a/aero-proto/imap/attributes.rs b/aero-proto/src/imap/attributes.rs
index 89446a8..89446a8 100644
--- a/aero-proto/imap/attributes.rs
+++ b/aero-proto/src/imap/attributes.rs
diff --git a/aero-proto/imap/capability.rs b/aero-proto/src/imap/capability.rs
index c76b51c..c76b51c 100644
--- a/aero-proto/imap/capability.rs
+++ b/aero-proto/src/imap/capability.rs
diff --git a/aero-proto/imap/command/anonymous.rs b/aero-proto/src/imap/command/anonymous.rs
index 811d1e4..2848c30 100644
--- a/aero-proto/imap/command/anonymous.rs
+++ b/aero-proto/src/imap/command/anonymous.rs
@@ -4,12 +4,13 @@ use imap_codec::imap_types::core::AString;
use imap_codec::imap_types::response::Code;
use imap_codec::imap_types::secret::Secret;
+use aero_user::login::ArcLoginProvider;
+use aero_collections::user::User;
+
use crate::imap::capability::ServerCapability;
use crate::imap::command::anystate;
use crate::imap::flow;
use crate::imap::response::Response;
-use crate::login::ArcLoginProvider;
-use crate::user::User;
//--- dispatching
diff --git a/aero-proto/imap/command/anystate.rs b/aero-proto/src/imap/command/anystate.rs
index 718ba3f..718ba3f 100644
--- a/aero-proto/imap/command/anystate.rs
+++ b/aero-proto/src/imap/command/anystate.rs
diff --git a/aero-proto/imap/command/authenticated.rs b/aero-proto/src/imap/command/authenticated.rs
index 3d332ec..4c8d8c1 100644
--- a/aero-proto/imap/command/authenticated.rs
+++ b/aero-proto/src/imap/command/authenticated.rs
@@ -14,17 +14,16 @@ use imap_codec::imap_types::mailbox::{ListMailbox, Mailbox as MailboxCodec};
use imap_codec::imap_types::response::{Code, CodeOther, Data};
use imap_codec::imap_types::status::{StatusDataItem, StatusDataItemName};
+use aero_collections::mail::uidindex::*;
+use aero_collections::user::User;
+use aero_collections::mail::IMF;
+use aero_collections::mail::namespace::MAILBOX_HIERARCHY_DELIMITER as MBX_HIER_DELIM_RAW;
+
use crate::imap::capability::{ClientCapability, ServerCapability};
use crate::imap::command::{anystate, MailboxName};
use crate::imap::flow;
-use crate::imap::mailbox_view::{MailboxView, UpdateParameters};
+use crate::imap::mailbox_view::MailboxView;
use crate::imap::response::Response;
-use crate::imap::Body;
-
-use crate::mail::uidindex::*;
-use crate::user::User;
-use crate::mail::IMF;
-use crate::mail::namespace::MAILBOX_HIERARCHY_DELIMITER as MBX_HIER_DELIM_RAW;
pub struct AuthenticatedContext<'a> {
pub req: &'a Command<'static>,
@@ -611,7 +610,7 @@ impl<'a> AuthenticatedContext<'a> {
Some(mb) => mb,
None => bail!("Mailbox does not exist"),
};
- let mut view = MailboxView::new(mb, self.client_capabilities.condstore.is_enabled()).await;
+ let view = MailboxView::new(mb, self.client_capabilities.condstore.is_enabled()).await;
if date.is_some() {
tracing::warn!("Cannot set date when appending message");
diff --git a/aero-proto/imap/command/mod.rs b/aero-proto/src/imap/command/mod.rs
index f201eb6..5382d06 100644
--- a/aero-proto/imap/command/mod.rs
+++ b/aero-proto/src/imap/command/mod.rs
@@ -3,7 +3,7 @@ pub mod anystate;
pub mod authenticated;
pub mod selected;
-use crate::mail::namespace::INBOX;
+use aero_collections::mail::namespace::INBOX;
use imap_codec::imap_types::mailbox::Mailbox as MailboxCodec;
/// Convert an IMAP mailbox name/identifier representation
diff --git a/aero-proto/imap/command/selected.rs b/aero-proto/src/imap/command/selected.rs
index eedfbd6..190949b 100644
--- a/aero-proto/imap/command/selected.rs
+++ b/aero-proto/src/imap/command/selected.rs
@@ -3,7 +3,7 @@ use std::sync::Arc;
use anyhow::Result;
use imap_codec::imap_types::command::{Command, CommandBody, FetchModifier, StoreModifier};
-use imap_codec::imap_types::core::{Charset, Vec1};
+use imap_codec::imap_types::core::Charset;
use imap_codec::imap_types::fetch::MacroOrMessageDataItemNames;
use imap_codec::imap_types::flag::{Flag, StoreResponse, StoreType};
use imap_codec::imap_types::mailbox::Mailbox as MailboxCodec;
@@ -11,13 +11,14 @@ use imap_codec::imap_types::response::{Code, CodeOther};
use imap_codec::imap_types::search::SearchKey;
use imap_codec::imap_types::sequence::SequenceSet;
+use aero_collections::user::User;
+
use crate::imap::attributes::AttributesProxy;
use crate::imap::capability::{ClientCapability, ServerCapability};
use crate::imap::command::{anystate, authenticated, MailboxName};
use crate::imap::flow;
use crate::imap::mailbox_view::{MailboxView, UpdateParameters};
use crate::imap::response::Response;
-use crate::user::User;
pub struct SelectedContext<'a> {
pub req: &'a Command<'static>,
diff --git a/aero-proto/imap/flags.rs b/aero-proto/src/imap/flags.rs
index 0f6ec64..0f6ec64 100644
--- a/aero-proto/imap/flags.rs
+++ b/aero-proto/src/imap/flags.rs
diff --git a/aero-proto/imap/flow.rs b/aero-proto/src/imap/flow.rs
index 86eb12e..1986447 100644
--- a/aero-proto/imap/flow.rs
+++ b/aero-proto/src/imap/flow.rs
@@ -5,8 +5,9 @@ use std::sync::Arc;
use imap_codec::imap_types::core::Tag;
use tokio::sync::Notify;
+use aero_collections::user::User;
+
use crate::imap::mailbox_view::MailboxView;
-use crate::user::User;
#[derive(Debug)]
pub enum Error {
diff --git a/aero-proto/imap/imf_view.rs b/aero-proto/src/imap/imf_view.rs
index a4ca2e8..a4ca2e8 100644
--- a/aero-proto/imap/imf_view.rs
+++ b/aero-proto/src/imap/imf_view.rs
diff --git a/aero-proto/imap/index.rs b/aero-proto/src/imap/index.rs
index 9b794b8..3de46be 100644
--- a/aero-proto/imap/index.rs
+++ b/aero-proto/src/imap/index.rs
@@ -3,8 +3,8 @@ use std::num::{NonZeroU32, NonZeroU64};
use anyhow::{anyhow, Result};
use imap_codec::imap_types::sequence::{SeqOrUid, Sequence, SequenceSet};
-use crate::mail::uidindex::{ImapUid, ModSeq, UidIndex};
-use crate::mail::unique_ident::UniqueIdent;
+use aero_collections::mail::uidindex::{ImapUid, ModSeq, UidIndex};
+use aero_collections::mail::unique_ident::UniqueIdent;
pub struct Index<'a> {
pub imap_index: Vec<MailIndex<'a>>,
diff --git a/aero-proto/imap/mail_view.rs b/aero-proto/src/imap/mail_view.rs
index a8db733..054014a 100644
--- a/aero-proto/imap/mail_view.rs
+++ b/aero-proto/src/imap/mail_view.rs
@@ -16,7 +16,7 @@ use eml_codec::{
part::{composite::Message, AnyPart},
};
-use crate::mail::query::QueryResult;
+use aero_collections::mail::query::QueryResult;
use crate::imap::attributes::AttributesProxy;
use crate::imap::flags;
diff --git a/aero-proto/imap/mailbox_view.rs b/aero-proto/src/imap/mailbox_view.rs
index 1c53b93..5154359 100644
--- a/aero-proto/imap/mailbox_view.rs
+++ b/aero-proto/src/imap/mailbox_view.rs
@@ -6,18 +6,18 @@ use anyhow::{anyhow, Error, Result};
use futures::stream::{StreamExt, TryStreamExt};
-use imap_codec::imap_types::core::{Charset, Vec1};
+use imap_codec::imap_types::core::Charset;
use imap_codec::imap_types::fetch::MessageDataItem;
use imap_codec::imap_types::flag::{Flag, FlagFetch, FlagPerm, StoreResponse, StoreType};
use imap_codec::imap_types::response::{Code, CodeOther, Data, Status};
use imap_codec::imap_types::search::SearchKey;
use imap_codec::imap_types::sequence::SequenceSet;
-use crate::mail::mailbox::Mailbox;
-use crate::mail::query::QueryScope;
-use crate::mail::snapshot::FrozenMailbox;
-use crate::mail::uidindex::{ImapUid, ImapUidvalidity, ModSeq};
-use crate::mail::unique_ident::UniqueIdent;
+use aero_collections::mail::mailbox::Mailbox;
+use aero_collections::mail::query::QueryScope;
+use aero_collections::mail::snapshot::FrozenMailbox;
+use aero_collections::mail::uidindex::{ImapUid, ImapUidvalidity, ModSeq};
+use aero_collections::mail::unique_ident::UniqueIdent;
use crate::imap::attributes::AttributesProxy;
use crate::imap::flags;
diff --git a/aero-proto/imap/mime_view.rs b/aero-proto/src/imap/mime_view.rs
index 8bbbd2d..720f20a 100644
--- a/aero-proto/imap/mime_view.rs
+++ b/aero-proto/src/imap/mime_view.rs
@@ -384,6 +384,8 @@ impl<'a> NodeMsg<'a> {
})
}
}
+
+#[allow(dead_code)]
struct NodeMult<'a>(&'a NodeMime<'a>, &'a composite::Multipart<'a>);
impl<'a> NodeMult<'a> {
fn structure(&self, is_ext: bool) -> Result<BodyStructure<'static>> {
diff --git a/aero-proto/imap/mod.rs b/aero-proto/src/imap/mod.rs
index 02ab9ce..ae3b58f 100644
--- a/aero-proto/imap/mod.rs
+++ b/aero-proto/src/imap/mod.rs
@@ -15,13 +15,11 @@ mod session;
use std::net::SocketAddr;
-use anyhow::{anyhow, bail, Context, Result};
+use anyhow::{anyhow, bail, Result};
use futures::stream::{FuturesUnordered, StreamExt};
-
use tokio::net::TcpListener;
use tokio::sync::mpsc;
use tokio::sync::watch;
-
use imap_codec::imap_types::response::{Code, CommandContinuationRequest, Response, Status};
use imap_codec::imap_types::{core::Text, response::Greeting};
use imap_flow::server::{ServerFlow, ServerFlowEvent, ServerFlowOptions};
@@ -29,12 +27,13 @@ use imap_flow::stream::AnyStream;
use rustls_pemfile::{certs, private_key};
use tokio_rustls::TlsAcceptor;
-use crate::config::{ImapConfig, ImapUnsecureConfig};
+use aero_user::config::{ImapConfig, ImapUnsecureConfig};
+use aero_user::login::ArcLoginProvider;
+
use crate::imap::capability::ServerCapability;
use crate::imap::request::Request;
use crate::imap::response::{Body, ResponseOrIdle};
use crate::imap::session::Instance;
-use crate::login::ArcLoginProvider;
/// Server is a thin wrapper to register our Services in BàL
pub struct Server {
@@ -140,7 +139,6 @@ impl Server {
use std::sync::Arc;
use tokio::sync::mpsc::*;
use tokio::sync::Notify;
-use tokio_util::bytes::BytesMut;
const PIPELINABLE_COMMANDS: usize = 64;
@@ -325,8 +323,6 @@ impl NetLoop {
self.server.enqueue_status(Status::bye(None, "Internal session exited").unwrap());
tracing::error!("session task exited for {:?}, quitting", self.ctx.addr);
},
- Some(_) => unreachable!(),
-
},
// When receiving a CTRL+C
diff --git a/aero-proto/imap/request.rs b/aero-proto/src/imap/request.rs
index cff18a3..cff18a3 100644
--- a/aero-proto/imap/request.rs
+++ b/aero-proto/src/imap/request.rs
diff --git a/aero-proto/imap/response.rs b/aero-proto/src/imap/response.rs
index b6a0e98..b6a0e98 100644
--- a/aero-proto/imap/response.rs
+++ b/aero-proto/src/imap/response.rs
diff --git a/aero-proto/imap/search.rs b/aero-proto/src/imap/search.rs
index 37a7e9e..3634a3a 100644
--- a/aero-proto/imap/search.rs
+++ b/aero-proto/src/imap/search.rs
@@ -4,9 +4,10 @@ use imap_codec::imap_types::core::Vec1;
use imap_codec::imap_types::search::{MetadataItemSearch, SearchKey};
use imap_codec::imap_types::sequence::{SeqOrUid, Sequence, SequenceSet};
+use aero_collections::mail::query::QueryScope;
+
use crate::imap::index::MailIndex;
use crate::imap::mail_view::MailView;
-use crate::mail::query::QueryScope;
pub enum SeqType {
Undefined,
diff --git a/aero-proto/imap/session.rs b/aero-proto/src/imap/session.rs
index fa3232a..92b5eb6 100644
--- a/aero-proto/imap/session.rs
+++ b/aero-proto/src/imap/session.rs
@@ -1,11 +1,13 @@
+use anyhow::{anyhow, bail, Context, Result};
+use imap_codec::imap_types::{command::Command, core::Tag};
+
+use aero_user::login::ArcLoginProvider;
+
use crate::imap::capability::{ClientCapability, ServerCapability};
use crate::imap::command::{anonymous, authenticated, selected};
use crate::imap::flow;
use crate::imap::request::Request;
use crate::imap::response::{Response, ResponseOrIdle};
-use crate::login::ArcLoginProvider;
-use anyhow::{anyhow, bail, Context, Result};
-use imap_codec::imap_types::{command::Command, core::Tag};
//-----
pub struct Instance {
diff --git a/aero-proto/src/lib.rs b/aero-proto/src/lib.rs
new file mode 100644
index 0000000..d5154cd
--- /dev/null
+++ b/aero-proto/src/lib.rs
@@ -0,0 +1,6 @@
+#![feature(async_closure)]
+
+pub mod dav;
+pub mod imap;
+pub mod lmtp;
+pub mod sasl;
diff --git a/aero-proto/lmtp.rs b/aero-proto/src/lmtp.rs
index dcd4bcc..9d40296 100644
--- a/aero-proto/lmtp.rs
+++ b/aero-proto/src/lmtp.rs
@@ -10,18 +10,16 @@ use futures::{
stream::{FuturesOrdered, FuturesUnordered},
StreamExt,
};
-use log::*;
use tokio::net::TcpListener;
use tokio::select;
use tokio::sync::watch;
use tokio_util::compat::*;
-
use smtp_message::{DataUnescaper, Email, EscapedDataReader, Reply, ReplyCode};
use smtp_server::{reply, Config, ConnectionMetadata, Decision, MailMetadata};
-use crate::config::*;
-use crate::login::*;
-use crate::mail::incoming::EncryptedMessage;
+use aero_user::config::*;
+use aero_user::login::*;
+use aero_collections::mail::incoming::EncryptedMessage;
pub struct LmtpServer {
bind_addr: SocketAddr,
@@ -43,7 +41,7 @@ impl LmtpServer {
pub async fn run(self: &Arc<Self>, mut must_exit: watch::Receiver<bool>) -> Result<()> {
let tcp = TcpListener::bind(self.bind_addr).await?;
- info!("LMTP server listening on {:#}", self.bind_addr);
+ tracing::info!("LMTP server listening on {:#}", self.bind_addr);
let mut connections = FuturesUnordered::new();
@@ -60,7 +58,7 @@ impl LmtpServer {
_ = wait_conn_finished => continue,
_ = must_exit.changed() => continue,
};
- info!("LMTP: accepted connection from {}", remote_addr);
+ tracing::info!("LMTP: accepted connection from {}", remote_addr);
let conn = tokio::spawn(smtp_server::interact(
socket.compat(),
@@ -73,7 +71,7 @@ impl LmtpServer {
}
drop(tcp);
- info!("LMTP server shutting down, draining remaining connections...");
+ tracing::info!("LMTP server shutting down, draining remaining connections...");
while connections.next().await.is_some() {}
Ok(())
diff --git a/aero-proto/sasl.rs b/aero-proto/src/sasl.rs
index fe292e1..dae89eb 100644
--- a/aero-proto/sasl.rs
+++ b/aero-proto/src/sasl.rs
@@ -6,10 +6,11 @@ use tokio::io::BufStream;
use tokio::io::{AsyncBufReadExt, AsyncWriteExt};
use tokio::net::{TcpListener, TcpStream};
use tokio::sync::watch;
+use tokio_util::bytes::BytesMut;
use aero_user::config::AuthConfig;
use aero_user::login::ArcLoginProvider;
-
+use aero_sasl::{flow::State, decode::client_command, encode::Encode};
pub struct AuthServer {
login_provider: ArcLoginProvider,
@@ -108,7 +109,8 @@ impl NetLoop {
tracing::trace!(cmd=?cmd, "Received command");
// Make some progress in our local state
- self.state.progress(cmd, &self.login).await;
+ let login = async |user: String, pass: String| self.login.login(user.as_str(), pass.as_str()).await.is_ok();
+ self.state.progress(cmd, login).await;
if matches!(self.state, State::Error) {
bail!("Internal state is in error, previous logs explain what went wrong");
}