pub fn decode_words<'b>(
value: &[u8],
limits: &Limits,
out: &'b mut [u8],
) -> Result<&'b str, ParseError>Expand description
Decodes the RFC 2047 encoded words in unstructured header text into
out and returns the text. Text outside encoded words is copied;
whitespace between two adjacent encoded words is dropped (section 6.2);
_ is a space in Q; an encoded word must stand alone between whitespace,
and words inside a quoted string are not decoded (section 5). Charsets:
UTF-8, US-ASCII, ISO-8859-1 (transcoded), with an optional RFC 2231
*language. B words need the encode-lib feature, which is not yet
available (D-002). CRLF WSP folds count as whitespace, so the output of
encode_words reads back as written.
§Errors
ErrorKind::UnsupportedCharset; ErrorKind::InvalidEncodedWord (a
bad encoding letter, a broken =XX, a byte not allowed in a Q word, a
B word); ErrorKind::ControlInDecoded for a decoded control
character (C0 including CR, LF, NUL, and HTAB; DEL; C1), as in ext-values;
a control kind for a control byte outside the words, other than HTAB and
the CRLF of a fold; ErrorKind::InvalidUtf8 (a UTF-8 word that is not
whole characters, or text outside the words that is not UTF-8);
ErrorKind::TooManyMembers
beyond max_encoded_words; ErrorKind::BufferTooSmall. Nothing is
written on error.
§Examples
use parse_net::{mail, Limits};
let mut buf = [0u8; 64];
let s = mail::decode_words(b"=?utf-8?q?Caf=C3=A9?= =?ISO-8859-1?Q?_cr=E8me?= now", &Limits::DEFAULT, &mut buf)?;
assert_eq!(s, "Caf\u{e9} cr\u{e8}me now");