Update all modules to use registry - part 1
This commit is contained in:
@@ -12,6 +12,7 @@ utils = { path = "../utils" }
|
||||
trc = { path = "../trc" }
|
||||
types = { path = "../types" }
|
||||
email = { path = "../email" }
|
||||
registry = { path = "../registry" }
|
||||
mail-parser = { version = "0.11", features = ["full_encoding"] }
|
||||
mail-send = { version = "0.5", default-features = false, features = ["cram-md5", "ring", "tls12"] }
|
||||
rustls = { version = "0.23.5", default-features = false, features = ["std", "ring", "tls12"] }
|
||||
|
||||
@@ -4,17 +4,16 @@
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
|
||||
*/
|
||||
|
||||
use common::{
|
||||
KV_RATE_LIMIT_IMAP,
|
||||
listener::{SessionResult, SessionStream},
|
||||
};
|
||||
use mail_send::Credentials;
|
||||
use trc::{AddContext, SecurityEvent};
|
||||
|
||||
use crate::{
|
||||
Session, State,
|
||||
protocol::{Command, Mechanism, request::Error},
|
||||
};
|
||||
use common::{
|
||||
KV_RATE_LIMIT_IMAP,
|
||||
network::{SessionResult, SessionStream},
|
||||
};
|
||||
use directory::Credentials;
|
||||
use trc::{AddContext, SecurityEvent};
|
||||
|
||||
impl<T: SessionStream> Session<T> {
|
||||
pub async fn ingest(&mut self, bytes: &[u8]) -> SessionResult {
|
||||
@@ -101,7 +100,7 @@ impl<T: SessionStream> Session<T> {
|
||||
} else {
|
||||
unreachable!()
|
||||
};
|
||||
self.handle_auth(Credentials::Plain {
|
||||
self.handle_auth(Credentials::Basic {
|
||||
username,
|
||||
secret: string,
|
||||
})
|
||||
@@ -239,9 +238,7 @@ impl<T: SessionStream> Session<T> {
|
||||
if let Some(rate) = &self.server.core.imap.rate_requests {
|
||||
if self
|
||||
.server
|
||||
.core
|
||||
.storage
|
||||
.lookup
|
||||
.in_memory_store()
|
||||
.is_rate_allowed(
|
||||
KV_RATE_LIMIT_IMAP,
|
||||
&mailbox.account_id.to_be_bytes(),
|
||||
|
||||
@@ -9,7 +9,7 @@ use std::{net::IpAddr, sync::Arc};
|
||||
use common::{
|
||||
Inner, Server,
|
||||
auth::AccessToken,
|
||||
listener::{ServerInstance, SessionStream, limiter::InFlight},
|
||||
network::{ServerInstance, SessionStream, limiter::InFlight},
|
||||
};
|
||||
use mailbox::Mailbox;
|
||||
use protocol::request::Parser;
|
||||
@@ -52,7 +52,7 @@ pub enum State {
|
||||
Authenticated {
|
||||
mailbox: Mailbox,
|
||||
in_flight: Option<InFlight>,
|
||||
access_token: Arc<AccessToken>,
|
||||
access_token: AccessToken,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ impl State {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn access_token(&self) -> &Arc<AccessToken> {
|
||||
pub fn access_token(&self) -> &AccessToken {
|
||||
match self {
|
||||
State::Authenticated { access_token, .. } => access_token,
|
||||
_ => unreachable!(),
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
use crate::Session;
|
||||
use common::listener::SessionStream;
|
||||
use common::network::SessionStream;
|
||||
use email::{
|
||||
cache::{MessageCacheFetch, mailbox::MailboxCacheAccess},
|
||||
mailbox::INBOX_ID,
|
||||
|
||||
@@ -4,21 +4,17 @@
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
|
||||
*/
|
||||
|
||||
use common::{
|
||||
auth::{
|
||||
AuthRequest,
|
||||
sasl::{sasl_decode_challenge_oauth, sasl_decode_challenge_plain},
|
||||
},
|
||||
listener::{SessionStream, limiter::LimiterResult},
|
||||
};
|
||||
use registry::schema::enums::Permission;
|
||||
use mail_parser::decoders::base64::base64_decode;
|
||||
use mail_send::Credentials;
|
||||
|
||||
use crate::{
|
||||
Session, State,
|
||||
protocol::{Command, Mechanism, request},
|
||||
};
|
||||
use common::{
|
||||
auth::AuthRequest,
|
||||
network::{SessionStream, limiter::LimiterResult},
|
||||
};
|
||||
use directory::Credentials;
|
||||
use mail_parser::decoders::base64::base64_decode;
|
||||
use registry::schema::enums::Permission;
|
||||
|
||||
impl<T: SessionStream> Session<T> {
|
||||
pub async fn handle_sasl(
|
||||
@@ -32,9 +28,9 @@ impl<T: SessionStream> Session<T> {
|
||||
let credentials = base64_decode(params.pop().unwrap().as_bytes())
|
||||
.and_then(|challenge| {
|
||||
if mechanism == Mechanism::Plain {
|
||||
sasl_decode_challenge_plain(&challenge)
|
||||
Credentials::decode_sasl_challenge_plain(&challenge)
|
||||
} else {
|
||||
sasl_decode_challenge_oauth(&challenge)
|
||||
Credentials::decode_sasl_challenge_oauth(&challenge)
|
||||
}
|
||||
})
|
||||
.ok_or_else(|| {
|
||||
@@ -64,7 +60,7 @@ impl<T: SessionStream> Session<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn handle_auth(&mut self, credentials: Credentials<String>) -> trc::Result<()> {
|
||||
pub async fn handle_auth(&mut self, credentials: Credentials) -> trc::Result<()> {
|
||||
// Authenticate
|
||||
let access_token = self
|
||||
.server
|
||||
@@ -94,11 +90,7 @@ impl<T: SessionStream> Session<T> {
|
||||
|
||||
err
|
||||
})
|
||||
.and_then(|token| {
|
||||
token
|
||||
.assert_has_permission(Permission::Pop3Authenticate)
|
||||
.map(|_| token)
|
||||
})?;
|
||||
.and_then(|token| token.assert_has_permission(Permission::Pop3Authenticate))?;
|
||||
|
||||
// Enforce concurrency limits
|
||||
let in_flight = match access_token.is_imap_request_allowed() {
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
|
||||
use std::time::Instant;
|
||||
|
||||
use common::listener::SessionStream;
|
||||
use registry::schema::enums::Permission;
|
||||
use common::network::SessionStream;
|
||||
use email::message::delete::EmailDeletion;
|
||||
use registry::schema::enums::Permission;
|
||||
use store::{roaring::RoaringBitmap, write::BatchBuilder};
|
||||
use trc::AddContext;
|
||||
|
||||
@@ -19,7 +19,7 @@ impl<T: SessionStream> Session<T> {
|
||||
// Validate access
|
||||
self.state
|
||||
.access_token()
|
||||
.assert_has_permission(Permission::Pop3Dele)?;
|
||||
.enforce_permission(Permission::Pop3Dele)?;
|
||||
|
||||
let op_start = Instant::now();
|
||||
let mailbox = self.state.mailbox_mut();
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
*/
|
||||
|
||||
use crate::{Session, protocol::response::Response};
|
||||
use common::listener::SessionStream;
|
||||
use registry::schema::enums::Permission;
|
||||
use common::network::SessionStream;
|
||||
use email::message::metadata::MessageMetadata;
|
||||
use registry::schema::enums::Permission;
|
||||
use std::time::Instant;
|
||||
use store::{
|
||||
ValueKey,
|
||||
@@ -22,7 +22,7 @@ impl<T: SessionStream> Session<T> {
|
||||
// Validate access
|
||||
self.state
|
||||
.access_token()
|
||||
.assert_has_permission(Permission::Pop3Retr)?;
|
||||
.enforce_permission(Permission::Pop3Retr)?;
|
||||
|
||||
let op_start = Instant::now();
|
||||
let mailbox = self.state.mailbox();
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
use std::time::Instant;
|
||||
|
||||
use common::listener::SessionStream;
|
||||
use common::network::SessionStream;
|
||||
use registry::schema::enums::Permission;
|
||||
|
||||
use crate::{Session, protocol::response::Response};
|
||||
@@ -16,7 +16,7 @@ impl<T: SessionStream> Session<T> {
|
||||
// Validate access
|
||||
self.state
|
||||
.access_token()
|
||||
.assert_has_permission(Permission::Pop3List)?;
|
||||
.enforce_permission(Permission::Pop3List)?;
|
||||
|
||||
let op_start = Instant::now();
|
||||
let mailbox = self.state.mailbox();
|
||||
@@ -57,7 +57,7 @@ impl<T: SessionStream> Session<T> {
|
||||
// Validate access
|
||||
self.state
|
||||
.access_token()
|
||||
.assert_has_permission(Permission::Pop3Uidl)?;
|
||||
.enforce_permission(Permission::Pop3Uidl)?;
|
||||
|
||||
let op_start = Instant::now();
|
||||
let mailbox = self.state.mailbox();
|
||||
@@ -106,7 +106,7 @@ impl<T: SessionStream> Session<T> {
|
||||
// Validate access
|
||||
self.state
|
||||
.access_token()
|
||||
.assert_has_permission(Permission::Pop3Stat)?;
|
||||
.enforce_permission(Permission::Pop3Stat)?;
|
||||
|
||||
let op_start = Instant::now();
|
||||
let mailbox = self.state.mailbox();
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
|
||||
*/
|
||||
|
||||
use common::listener::SessionStream;
|
||||
use common::network::SessionStream;
|
||||
|
||||
use crate::{
|
||||
Session,
|
||||
|
||||
@@ -4,14 +4,6 @@
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
|
||||
*/
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
||||
use common::{
|
||||
core::BuildServer,
|
||||
listener::{SessionData, SessionManager, SessionResult, SessionStream},
|
||||
};
|
||||
use tokio_rustls::server::TlsStream;
|
||||
|
||||
use crate::{
|
||||
Pop3SessionManager, SERVER_GREETING, Session, State,
|
||||
protocol::{
|
||||
@@ -19,8 +11,13 @@ use crate::{
|
||||
response::{Response, SerializeResponse},
|
||||
},
|
||||
};
|
||||
|
||||
use common::{
|
||||
BuildServer,
|
||||
network::{SessionData, SessionManager, SessionResult, SessionStream},
|
||||
};
|
||||
use std::borrow::Cow;
|
||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||
use tokio_rustls::server::TlsStream;
|
||||
|
||||
impl SessionManager for Pop3SessionManager {
|
||||
#[allow(clippy::manual_async_fn)]
|
||||
|
||||
Reference in New Issue
Block a user