Struct smtp_message::DataUnescaper
source · [−]pub struct DataUnescaper { /* private fields */ }
Expand description
Helper struct to unescape a data stream.
Note that one unescaper should be used for a single data stream. Creating a
DataUnescaper
is basically free, and not creating a new one would probably
lead to initial \r\n
being handled incorrectly.
Implementations
sourceimpl DataUnescaper
impl DataUnescaper
sourcepub fn new(is_preceded_by_crlf: bool) -> DataUnescaper
pub fn new(is_preceded_by_crlf: bool) -> DataUnescaper
Creates a DataUnescaper
.
The is_preceded_by_crlf
argument is used to indicate whether, before
the first buffer that is fed into unescape
, the unescaper should
assume that a \r\n
was present.
Usually, one will want to set true
as an argument, as starting a
DataUnescaper
mid-line is a rare use case.
sourcepub fn unescape(&mut self, data: &mut [u8]) -> DataUnescapeRes
pub fn unescape(&mut self, data: &mut [u8]) -> DataUnescapeRes
Unescapes data coming from an EscapedDataReader
.
This takes a data
argument. It will modify the data
argument,
removing the escaping that could happen with it, and then returns a
DataUnescapeRes
.
It is possible that the end of data
does not land on a boundary that
allows yet to know whether data should be output or not. This is the
reason why this returns a DataUnescapeRes
. The
returned value will contain:
.written
, which is the number of unescaped bytes that have been written indata
— that is,data[..res.written]
is the unescaped data, and.unhandled_idx
, which is the number of bytes at the end ofdata
that could not be handled yet for lack of more information — that is,data[res.unhandled_idx..]
is data that should be at the beginning of the next call todata_unescape
.
Note that the unhandled data’s length is never going to be longer than 4 bytes long (“\r\n.\r”, the longest sequence that can’t be interpreted yet), so it should not be an issue to just copy it to the next buffer’s start.
Auto Trait Implementations
impl RefUnwindSafe for DataUnescaper
impl Send for DataUnescaper
impl Sync for DataUnescaper
impl Unpin for DataUnescaper
impl UnwindSafe for DataUnescaper
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more