mime_tree/message.rs
1use serde::{Deserialize, Serialize};
2
3use crate::part::{ParsedHeader, ParsedPart};
4
5/// The result of `parse()`.
6///
7/// All fields are owned. No lifetime parameters.
8#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
9#[non_exhaustive]
10pub struct ParsedMessage {
11 /// The MIME part tree rooted at the message.
12 pub part_index: ParsedPart,
13 /// Part IDs of text/plain body parts, per RFC 8621 §4.1.4.
14 pub text_body: Vec<String>,
15 /// Part IDs of text/html body parts, per RFC 8621 §4.1.4.
16 pub html_body: Vec<String>,
17 /// Part IDs of attachment parts, per RFC 8621 §4.1.4.
18 pub attachments: Vec<String>,
19 /// Top-level message headers.
20 pub headers: Vec<ParsedHeader>,
21 /// Short preview of the message body (first ~256 chars of text content).
22 ///
23 /// `None` when there is no text body part, when the first text part is
24 /// empty, or when decoding the first text part fails (e.g. unsupported
25 /// charset or transfer-encoding error).
26 pub preview: Option<String>,
27 /// Non-fatal parse warnings (e.g. unknown CTE, out-of-range part
28 /// indices, encoding problems).
29 ///
30 /// # Stability
31 ///
32 /// Warning strings are human-readable diagnostic messages. Their
33 /// exact wording, count, and order are **not** stable across minor
34 /// versions — do not match on them programmatically. Use
35 /// `warnings.is_empty()` to check for a clean parse; log the
36 /// contents for debugging.
37 pub warnings: Vec<String>,
38}
39
40/// Result of `decode_body_value()`.
41#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
42#[non_exhaustive]
43pub struct DecodedBodyValue {
44 /// Decoded, charset-converted text.
45 pub value: String,
46 /// True if `max_bytes` was reached before the full body was decoded.
47 pub is_truncated: bool,
48 /// True if the charset conversion encountered unmappable or replacement
49 /// characters. Note: also set when `max_bytes` truncates a multi-byte
50 /// character sequence mid-codepoint; in that case the flag reflects the
51 /// truncation artifact, not underlying data corruption.
52 pub is_encoding_problem: bool,
53}