rfc2047_decoder/lib.rs
1//! # Introduction
2//! This crate provides a [Decoder] and the function [decode], in order to decode
3//! encoded words as described in the [RFC 2047].
4//!
5//! [RFC 2047]: https://datatracker.ietf.org/doc/html/rfc2047
6//!
7//! # Where to start looking
8//! You will likely want to start looking into [Decoder] and/or the [decode]
9//! to use this crate.
10
11mod decoder;
12pub use decoder::{Decoder, Error, RecoverStrategy};
13
14mod evaluator;
15mod lexer;
16mod parser;
17
18pub use evaluator::Error as EvaluatorError;
19pub use lexer::{Error as LexerError, TooLongEncodedWords};
20pub use parser::Error as ParserError;
21
22/// Decodes the given RFC 2047 MIME Message Header encoded string
23/// using a default decoder.
24///
25/// This function equals doing `Decoder::new().decode`.
26///
27/// # Example
28/// ```
29/// use rfc2047_decoder::{decode, Decoder};
30///
31/// let encoded_message = "=?ISO-8859-1?Q?hello_there?=".as_bytes();
32/// let decoded_message = "hello there";
33///
34/// // This ...
35/// assert_eq!(decode(encoded_message).unwrap(), decoded_message);
36///
37/// // ... equals this:
38/// assert_eq!(Decoder::new().decode(encoded_message).unwrap(), decoded_message);
39/// ```
40pub fn decode<T: AsRef<[u8]>>(encoded_str: T) -> Result<String, Error> {
41 Decoder::new().decode(encoded_str)
42}