Expand description
Thin adapter: mime_tree types → jmap_mail_types types.
All MIME parsing lives in mime-tree. This crate only maps field names.
§Usage
A real MailBackend::parse_email implementation MUST surface
mime_tree::parse and decode_body_value errors as JMAP method
errors per RFC 8620 §3.6.2 — never panic. This example uses ? and
returns Result so the pattern reads correctly when copied.
use jmap_mime::{message_to_jmap_body, body_value_to_jmap};
use jmap_types::Id;
use mime_tree::{parse, decode_body_value};
let raw = b"From: alice@example.com\r\n\
Content-Type: text/plain; charset=utf-8\r\n\
\r\n\
Hello, world!\r\n";
let msg = parse(raw)?;
// Assign blob IDs for each leaf part (storage layer decides how).
let fields = message_to_jmap_body(&msg, |part| {
Id::from(format!("blob-{}", part.part_id))
});
assert_eq!(fields.text_body.len(), 1);
assert_eq!(fields.text_body[0].type_.as_deref(), Some("text/plain"));
// Decode body values on demand and map them into EmailBodyValue.
for part_id in &fields.body_value_part_ids {
if let Some(part) = msg.part_index.find_by_id(part_id) {
let decoded = decode_body_value(raw, part, Some(8192))?;
let _jmap_val = body_value_to_jmap(decoded);
}
}Structs§
- Jmap
Body Fields - The JMAP body fields derived from a parsed MIME message.
Constants§
- MAX_
PART_ DEPTH - Maximum multipart nesting depth this adapter will recurse into.
Functions§
- body_
value_ to_ jmap - Convert a
DecodedBodyValueinto anEmailBodyValue. - message_
to_ jmap_ body - Build the full JMAP body fields from a
ParsedMessage. - part_
to_ jmap - Convert a
ParsedPart(and its children) into anEmailBodyParttree.