Skip to main content

encode_words_b

Function encode_words_b 

Source
pub fn encode_words_b(
    text: &str,
    room_first_line: usize,
    out: &mut impl Sink,
) -> Result<(), WriteError>
Expand description

encode_words with the RFC 2047 B encoding: =?UTF-8?B?...?= words of at most 75 bytes, split only between characters, separated by CRLF SP. Text that goes out as it is under encode_words goes out as it is here. B costs four bytes for every three, Q three for every byte it escapes, so B is the shorter for text that is mostly not ASCII: a Japanese or Chinese subject is about 40% shorter. decode_words reads both.

§Errors

WriteError::Forbidden for a control character (C0, DEL, or C1); WriteError::Full (nothing written when the sink reports its room).

§Examples

use parse_net::{mail, Limits, SliceSink};

let mut buf = [0u8; 256];
let mut out = SliceSink::new(&mut buf);
mail::encode_words_b("\u{4f1a}\u{8b70}\u{306e}\u{304a}\u{77e5}\u{3089}\u{305b}", 64, &mut out).expect("room");
assert_eq!(out.written(), b"=?UTF-8?B?5Lya6K2w44Gu44GK55+l44KJ44Gb?=");

let mut text = [0u8; 64];
let s = mail::decode_words(out.written(), &Limits::DEFAULT, &mut text)?;
assert_eq!(s, "\u{4f1a}\u{8b70}\u{306e}\u{304a}\u{77e5}\u{3089}\u{305b}");