Skip to main content

Crate postacert

Crate postacert 

Source
Expand description

§postacert

CI codecov crates.io docs.rs License: MIT

Parsing PEC messages, Italian certified email, and reading and writing their daticert.xml certification data, in Rust.

  • every receipt, notice and envelope a PEC provider generates, told apart by kind and checked against its subject
  • the certification data of daticert.xml, read and written
  • the original message out of a transport envelope or a delivery receipt, and the arrived message out of an anomaly envelope
  • short-receipt hashes identified and checked against the sent message, including named roots, nested attachments and carried user files, with ambiguous assignments rejected

The crate works on bytes already fetched, so any SMTP or IMAP client can feed it. It follows the AgID technical rules annexed to DM 2 November 2005.

use postacert::{Kind, Message, MessageKind};

let raw = std::fs::read("tests/fixtures/messages/delivery-full.eml")?;
let receipt = Message::parse(&raw)?;
assert_eq!(receipt.kind(), MessageKind::Certified(Kind::Delivery));
assert_eq!(receipt.subject(), "Invio fattura 00012");

let data = receipt.certification_data().expect("every receipt has one");
assert_eq!(data.data.delivered_to.as_deref(), Some("ufficio.fatture@pec.example.it"));
assert_eq!(data.data.at.timestamp().to_string(), "2026-11-08T09:15:00Z");
assert!(receipt.original_message().is_some());

Re-exports§

pub use certification::CertificationData;
pub use certification::CertifiedAt;
pub use certification::Data;
pub use certification::ErrorCode;
pub use certification::Header;
pub use certification::ReceiptKind;
pub use certification::Recipient;
pub use certification::RecipientKind;
pub use message::Message;

Modules§

certification
The certification data a provider attaches as daticert.xml, per the DTD of §7.4.
message
Reading a message a PEC provider generated: its kind, its certification data and the message it carries.

Structs§

AttachmentHash
An attachment of the original message that a short delivery receipt replaced with its SHA-1 (§6.5.2.2).
MessageId
A message identifier, the msg-id of RFC 5322 §3.6.4, held without its angle brackets.

Enums§

AttachmentCheck
How one attachment of the sent message, or one thing the receipt carries in its place, compares (§6.5.2.2).
Error
Why PEC data could not be read or a receipt’s attachments could not be checked.
Kind
The kind of a certified message, the tipo of daticert.xml (§7.4).
MessageKind
What a message is, read from X-Ricevuta or X-Trasporto.
TextLineEnds
The line ends a provider may have hashed a text attachment or an attached message with (§6.5.2.2).