Skip to content

calternal_imap::mime

Bounded MIME descriptions and exact body sections (#897/#486, DESIGN §53) with Apple Note validation kept at the Notes boundary (#428 D9). Accepted wrapper spelling and MIME bytes remain inert raw data for per-User internal state. Parts have CID identities, never client filenames or filesystem paths. The Markdown writer decides where a new attachment belongs; this module performs no filesystem access.

Source: crates/calternal-imap/src/mime.rs

pub struct Attachment

A CID part has no client-controlled filesystem path or replayed active HTML.

Fields

  • pub cid: String
  • pub media_type: String
  • pub bytes: Vec<u8>

Implements: Clone, Debug, PartialEq, Eq

Source: crates/calternal-imap/src/mime.rs:35

pub struct MimeLimits

MIME resource limits applied independently of IMAP framing. Input bytes are bounded before parsing; decoded bytes and part count are checked before copy.

Fields

  • pub max_message_bytes: usize
  • pub max_parts: usize
  • pub max_decoded_bytes: usize
  • pub max_header_bytes: usize

Implements: Clone, Copy, Default

Source: crates/calternal-imap/src/mime.rs:16

pub struct NoteMessage

Raw MIME is retained for D9 replay separately from authoritative Markdown.

Fields

  • pub identity: String
  • pub html: String
  • pub raw: Vec<u8>
  • pub attachments: Vec<Attachment>

Implements: Clone, Debug

pub fn parse(raw: &[u8], limits: MimeLimits) -> Result<Self, &'static str>

Parse only an identified Apple Note with one HTML body. Reject duplicate identities, corrupt transfer encodings, active HTML and ambiguous CIDs.

pub fn render(
identity_value: &str,
html: &str,
attachments: &[Attachment],
limits: MimeLimits,
) -> Result<Vec<u8>, &'static str>

Make a safe related message with base64 bodies. Boundary text cannot occur in base64 data. Only static image types and PDF are projected. This form has no Subject or Date; the Notes bridge uses NoteMessage::render_note, which Apple Notes needs to show a Note.

pub fn render_note(
identity_value: &str,
date: i64,
html: &str,
attachments: &[Attachment],
limits: MimeLimits,
) -> Result<Vec<u8>, &'static str>

Render a Note the way Apple Notes writes its own messages (#428 live Mac run): a Subject equal to the first visible line, a Date, and a complete <html><body> document. Without these the Mac lists the Note with no title and an empty body. date is Unix seconds (UTC).

Source: crates/calternal-imap/src/mime.rs:43

pub enum BodySection

Which exact encoded slice a BODY section requests (#486, DESIGN §53).

Variants

  • Body
  • Header
  • Mime
  • Text

Implements: Clone, Copy

Source: crates/calternal-imap/src/mime.rs:416

pub fn apple_created_date(raw: &[u8]) -> Option<i64>

Read Apple’s X-Mail-Created-Date as Unix seconds. macOS 27 Notes 4.13 can retain its initial Date over several local saves (#644 live Mac). The provider must resolve it to immutable served evidence, never assume that it is the current revision. Absent or malformed values prove nothing.

Source: crates/calternal-imap/src/mime.rs:681

pub fn body_section(
raw: &[u8],
path: &[u32],
section: BodySection,
) -> Result<Option<Vec<u8>>, &'static str>

Read bounded MIME part coordinates without decoding leaf wire bytes. Missing parts return NIL. Embedded-message header and text requests use the nested message, while MIME requests use the enclosing part header.

Source: crates/calternal-imap/src/mime.rs:426

pub fn bodystructure(raw: &[u8]) -> Result<String, &'static str>

Describe ordinary Mail and generated Notes without Note-only validation (#897, DESIGN §53). Bound bytes before parsing, then bound parts and headers. Parameters and encodings describe the wire bytes, not decoded content.

Source: crates/calternal-imap/src/mime.rs:506

pub fn envelope(headers: &[u8]) -> Result<String, &'static str>

Build client envelope metadata from exact outer headers without body bytes (#684/#486, DESIGN §53). The shared sync header limit bounds parsing.

Source: crates/calternal-imap/src/mime.rs:404