///|
/// The SMTP envelope: the sender (MAIL FROM) and the recipients (RCPT TO).
pub struct Envelope {
  from : MailAddress
  recipients : Array[MailAddress]
} derive(Eq, Debug)

///|
pub fn Envelope::new(
  from : MailAddress,
  recipients : Array[MailAddress],
) -> Envelope {
  { from, recipients }
}

///|
pub fn Envelope::from(self : Envelope) -> MailAddress {
  self.from
}

///|
pub fn Envelope::recipients(self : Envelope) -> Array[MailAddress] {
  self.recipients
}

///|
/// The reverse-path as required by MAIL FROM, with an empty sender (`<>`)
/// allowed for null reverse-paths used in bounces.
pub fn Envelope::mail_from(self : Envelope) -> String {
  if self.from.local_part.is_empty() {
    "<>"
  } else {
    "<\{self.from.addr_spec()}>"
  }
}

///|
/// One RCPT TO per recipient.
pub fn Envelope::rcpt_to(self : Envelope) -> Array[String] {
  self.recipients.map(fn(r) { "<\{r.addr_spec()}>" })
}