Skip to main content

DotStufferState

Struct DotStufferState 

Source
pub struct DotStufferState { /* private fields */ }
Expand description

Streaming version of the RFC 5321 dot-stuffer.

Unlike dot_stuff_and_terminate, this processes the message body one chunk at a time, keeping memory usage at O(chunk size) rather than O(body size). Suitable for large messages and memory-constrained runtimes.

§Usage

use wasm_smtp::protocol::DotStufferState;

let mut stuffer = DotStufferState::new();

// Process each chunk.
let chunk1 = b"Subject: test\r\n\r\n";
let out1 = stuffer.process_chunk(chunk1);

let chunk2 = b".dotted line\r\nend\r\n";
let out2 = stuffer.process_chunk(chunk2);

// Produce the end-of-data terminator.
let terminator = stuffer.finish();

// on-wire: out1 + out2 + terminator
assert_eq!(&out2[..2], b".."); // dot-stuffed
assert_eq!(terminator, b".\r\n");

Implementations§

Source§

impl DotStufferState

Source

pub const fn new() -> Self

Create a new state machine, ready to process the first chunk.

Source

pub fn process_chunk(&mut self, chunk: &[u8]) -> Vec<u8>

Dot-stuff one chunk and return the processed bytes.

The returned Vec is slightly larger than chunk only when one or more lines in the chunk begin with .. All other bytes pass through unchanged.

process_chunk with an empty slice is a no-op and returns an empty Vec.

§Cross-chunk dot-stuffing

The state machine correctly handles dots that appear at the start of a line which spans two consecutive chunks. For example, if chunk N ends with \r\n and chunk N+1 starts with ., the leading dot in chunk N+1 will be stuffed.

Source

pub fn finish(self) -> Vec<u8>

Consume the state machine and produce the end-of-DATA bytes.

The output is:

  • \r\n.\r\n if the body did not end with \r\n (or was empty).
  • .\r\n if the body already ended with \r\n.

This matches the semantics of dot_stuff_and_terminate exactly.

Trait Implementations§

Source§

impl Clone for DotStufferState

Source§

fn clone(&self) -> DotStufferState

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DotStufferState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for DotStufferState

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.