imsg_formats/bmessage/mod.rs
1//! bMessage encoder and parser (MAP spec appendix B).
2//!
3//! Parse with [`crate::bmessage::BMessage::parse`]; encode with
4//! [`crate::bmessage::BMessage::encode`].
5
6mod encode;
7mod parser;
8mod types;
9
10pub use types::{BBody, BEnvelope, BMessage, BMessageError, BVCard, MessageStatus, MessageType};
11
12// LENGTH covers the CRLF `BEGIN:MSG…END:MSG` block; encode and parse must agree on its overhead.
13const BEGIN_MSG_LEN: usize = "BEGIN:MSG\r\n".len();
14const END_MSG_LEN: usize = "END:MSG\r\n".len();
15
16impl BMessage {
17 /// Parses a bMessage from UTF-8 text, accepting CRLF and LF line endings.
18 ///
19 /// # Errors
20 ///
21 /// Returns [`BMessageError`] when a required field is absent, a section is
22 /// unterminated, or STATUS/TYPE hold unrecognised values.
23 pub fn parse(input: &str) -> Result<Self, BMessageError> {
24 parser::parse_bmessage(input)
25 }
26}