Function quoted_string::quote_if_needed
[−]
[src]
pub fn quote_if_needed<'a, FN>(
input: &'a str,
valid_without_quoting: FN,
quoted_string_type: QuotedStringType
) -> Result<(QuotedStringType, Cow<'a, str>)> where
FN: ValidWithoutQuotationCheck,
quotes the input string if needed(RFC 5322/6532/822/2045)
The valid_without_quoting
parameter accepts a function,
which should only return true if the char is valid
without quoting. So this function should never return true
for e.g. \0
. Use this function if some characters are
only valid in a quoted-string context.
If the allowed_mail_type
parameter is set to Ascii
the algorithm will return a error if it stumbles over
a non-ascii character, else it will just indicate the
appearance of one through the returned quoted string type. Note
that if you set quoted_string_type
to Utf8
the function still can returns a QuotedStringType::AsciiOnly
which
means only ascii characters where contained, even through non ascii
character where allowed.
The quoting process can fail if characters are contained,
which can not appear in a quoted string independent of
quoted string type. This are chars which are neither
qtext
,vchar
nor WS (' '
and '\t'
).
Which are basically only 0x7F (DEL) and the
characters < 0x20 (' '
) except 0x09 ('\t'
).
Note that if the valid_without_quoting
function states a CTL
char is valid without quoting then the algorithm will see it
as such even through there shouldn't be any context in which a
CTL char is valid without quoting.