Skip to content

Commit

Permalink
feat: Make literal accept/reject text configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
duesee committed Oct 18, 2023
1 parent f9cd846 commit 5647d64
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
5 changes: 1 addition & 4 deletions proxy/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,7 @@ impl Proxy<ConnectedState> {

let mut client_to_proxy = {
// TODO: Read options from config
let options = ServerFlowOptions {
crlf_relaxed: true,
max_literal_size: u32::MAX,
};
let options = ServerFlowOptions::default();

let result =
ServerFlow::send_greeting(self.state.client_to_proxy, options, greeting).await;
Expand Down
21 changes: 18 additions & 3 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use imap_codec::{
decode::CommandDecodeError,
imap_types::{
command::Command,
core::Text,
response::{CommandContinuationRequest, Data, Greeting, Response, Status},
},
CommandCodec, GreetingCodec, ResponseCodec,
Expand All @@ -15,10 +16,12 @@ use crate::{
stream::AnyStream,
};

#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Debug, Clone, PartialEq)]
pub struct ServerFlowOptions {
pub crlf_relaxed: bool,
pub max_literal_size: u32,
pub literal_accept_text: Text<'static>,
pub literal_reject_text: Text<'static>,
}

impl Default for ServerFlowOptions {
Expand All @@ -28,6 +31,10 @@ impl Default for ServerFlowOptions {
crlf_relaxed: true,
// 25 MiB is a common maximum email size (Oct. 2023)
max_literal_size: 25 * 1024 * 1024,
// Short unmeaning text
literal_accept_text: Text::unvalidated("..."),
// Short unmeaning text
literal_reject_text: Text::unvalidated("..."),
}
}
}
Expand All @@ -40,6 +47,9 @@ pub struct ServerFlow {
next_response_handle: ServerFlowResponseHandle,
send_response_state: SendResponseState<ResponseCodec, Option<ServerFlowResponseHandle>>,
receive_command_state: ReceiveState<CommandCodec>,

literal_accept_text: Text<'static>,
literal_reject_text: Text<'static>,
}

impl ServerFlow {
Expand Down Expand Up @@ -67,6 +77,8 @@ impl ServerFlow {
next_response_handle: ServerFlowResponseHandle(0),
send_response_state,
receive_command_state,
literal_accept_text: options.literal_accept_text,
literal_reject_text: options.literal_reject_text,
};

Ok(server_flow)
Expand Down Expand Up @@ -131,7 +143,8 @@ impl ServerFlow {

// Inform the client that the literal was rejected.
// This should never fail because the text is not Base64.
let status = Status::no(Some(tag), None, "Computer says no").unwrap();
let status =
Status::no(Some(tag), None, self.literal_reject_text.clone()).unwrap();
self.send_response_state
.enqueue(None, Response::Status(status));

Expand All @@ -141,7 +154,9 @@ impl ServerFlow {

// Inform the client that the literal was accepted.
// This should never fail because the text is not Base64.
let cont = CommandContinuationRequest::basic(None, "Please, continue").unwrap();
let cont =
CommandContinuationRequest::basic(None, self.literal_accept_text.clone())
.unwrap();
self.send_response_state
.enqueue(None, Response::CommandContinuationRequest(cont));

Expand Down

0 comments on commit 5647d64

Please sign in to comment.