Import upstream v0.16.22, stripped
Upstream commit: 474dd0229cb20cf513036619781ed97bd8073c3f Enterprise-only files removed or emptied: 63 Enterprise-only snippets removed: 117 in 50 files Dangling module declarations removed: 5 Cargo edits turning enterprise off: 14 Verification: clean Enterprise feature gates left for rebuilt features: 19 in 18 files Produced by tools/fork/strip.py. The full report is in docs/fork/strip-reports/ on main.
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2020 Stalwart Labs LLC <[email protected]>
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
|
||||
*/
|
||||
|
||||
use std::time::Instant;
|
||||
|
||||
use common::network::SessionStream;
|
||||
use registry::schema::enums::Permission;
|
||||
|
||||
use crate::{Session, protocol::response::Response};
|
||||
|
||||
impl<T: SessionStream> Session<T> {
|
||||
pub async fn handle_list(&mut self, msg: Option<u32>) -> trc::Result<()> {
|
||||
// Validate access
|
||||
self.state
|
||||
.access_token()
|
||||
.enforce_permission(Permission::Pop3List)?;
|
||||
|
||||
let op_start = Instant::now();
|
||||
let mailbox = self.state.mailbox();
|
||||
if let Some(msg) = msg {
|
||||
if let Some(message) = mailbox.messages.get(msg.saturating_sub(1) as usize) {
|
||||
trc::event!(
|
||||
Pop3(trc::Pop3Event::ListMessage),
|
||||
SpanId = self.session_id,
|
||||
DocumentId = message.id,
|
||||
Size = message.size,
|
||||
Elapsed = op_start.elapsed()
|
||||
);
|
||||
|
||||
self.write_ok(format!("{} {}", msg, message.size)).await
|
||||
} else {
|
||||
Err(trc::Pop3Event::Error
|
||||
.into_err()
|
||||
.details("No such message.")
|
||||
.caused_by(trc::location!()))
|
||||
}
|
||||
} else {
|
||||
trc::event!(
|
||||
Pop3(trc::Pop3Event::List),
|
||||
SpanId = self.session_id,
|
||||
Total = mailbox.messages.len(),
|
||||
Elapsed = op_start.elapsed()
|
||||
);
|
||||
|
||||
self.write_bytes(
|
||||
Response::List(mailbox.messages.iter().map(|m| m.size).collect::<Vec<_>>())
|
||||
.serialize(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn handle_uidl(&mut self, msg: Option<u32>) -> trc::Result<()> {
|
||||
// Validate access
|
||||
self.state
|
||||
.access_token()
|
||||
.enforce_permission(Permission::Pop3Uidl)?;
|
||||
|
||||
let op_start = Instant::now();
|
||||
let mailbox = self.state.mailbox();
|
||||
if let Some(msg) = msg {
|
||||
if let Some(message) = mailbox.messages.get(msg.saturating_sub(1) as usize) {
|
||||
trc::event!(
|
||||
Pop3(trc::Pop3Event::UidlMessage),
|
||||
SpanId = self.session_id,
|
||||
DocumentId = message.id,
|
||||
Uid = message.uid,
|
||||
UidValidity = mailbox.uid_validity,
|
||||
Elapsed = op_start.elapsed()
|
||||
);
|
||||
|
||||
self.write_ok(format!("{} {}{}", msg, mailbox.uid_validity, message.uid))
|
||||
.await
|
||||
} else {
|
||||
Err(trc::Pop3Event::Error
|
||||
.into_err()
|
||||
.details("No such message.")
|
||||
.caused_by(trc::location!()))
|
||||
}
|
||||
} else {
|
||||
trc::event!(
|
||||
Pop3(trc::Pop3Event::Uidl),
|
||||
SpanId = self.session_id,
|
||||
Total = mailbox.messages.len(),
|
||||
Elapsed = op_start.elapsed()
|
||||
);
|
||||
|
||||
self.write_bytes(
|
||||
Response::List(
|
||||
mailbox
|
||||
.messages
|
||||
.iter()
|
||||
.map(|m| format!("{}{}", mailbox.uid_validity, m.uid))
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
.serialize(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn handle_stat(&mut self) -> trc::Result<()> {
|
||||
// Validate access
|
||||
self.state
|
||||
.access_token()
|
||||
.enforce_permission(Permission::Pop3Stat)?;
|
||||
|
||||
let op_start = Instant::now();
|
||||
let mailbox = self.state.mailbox();
|
||||
|
||||
trc::event!(
|
||||
Pop3(trc::Pop3Event::Stat),
|
||||
SpanId = self.session_id,
|
||||
Total = mailbox.total,
|
||||
Size = mailbox.size,
|
||||
Elapsed = op_start.elapsed()
|
||||
);
|
||||
|
||||
self.write_ok(format!("{} {}", mailbox.total, mailbox.size))
|
||||
.await
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user