Skip to main content

decode_words

Function decode_words 

Source
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 are read strictly (D-080): whole groups of four, = padding only at the end with zero bits under it, no whitespace inside, and at most 75 bytes to a word. CRLF WSP folds count as whitespace, so the output of encode_words and encode_words_b reads back as written.

§Errors

ErrorKind::UnsupportedCharset; ErrorKind::InvalidEncodedWord (a bad encoding letter, a broken =XX, a byte not allowed in a Q word, base64 that is not canonical, a B word longer than 75 bytes); 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");