Skip to main content

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)]
9pub struct ParsedMessage {
10    /// The MIME part tree rooted at the message.
11    pub part_index: ParsedPart,
12    /// Part IDs of text/plain body parts, per RFC 8621 §4.1.4.
13    pub text_body: Vec<String>,
14    /// Part IDs of text/html body parts, per RFC 8621 §4.1.4.
15    pub html_body: Vec<String>,
16    /// Part IDs of attachment parts, per RFC 8621 §4.1.4.
17    pub attachments: Vec<String>,
18    /// Top-level message headers.
19    pub headers: Vec<ParsedHeader>,
20    /// Short preview of the message body (first ~256 chars of text content).
21    ///
22    /// `None` when there is no text body part, when the first text part is
23    /// empty, or when decoding the first text part fails (e.g. unsupported
24    /// charset or transfer-encoding error).
25    pub preview: Option<String>,
26    /// Non-fatal parse warnings.
27    pub warnings: Vec<String>,
28}
29
30/// Result of `decode_body_value()`.
31#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
32pub struct DecodedBodyValue {
33    /// Decoded, charset-converted text.
34    pub value: String,
35    /// True if `max_bytes` was reached before the full body was decoded.
36    pub is_truncated: bool,
37    /// True if the charset conversion encountered unmappable or replacement
38    /// characters. Note: also set when `max_bytes` truncates a multi-byte
39    /// character sequence mid-codepoint; in that case the flag reflects the
40    /// truncation artifact, not underlying data corruption.
41    pub is_encoding_problem: bool,
42}