InboxMail.parse constructor

InboxMail.parse(
  1. List<int> raw, {
  2. String? sender,
  3. List<String> recipients = const [],
  4. DateTime? received,
})

Decodes the message raw, as it arrived after the SMTP DATA command with its dot-stuffing already undone. sender and recipients are the envelope, which the message itself does not carry.

Decoding never fails: whatever cannot be read is left null, and bytes that are not valid in their charset become replacement characters.

Implementation

factory InboxMail.parse(
  List<int> raw, {
  String? sender,
  List<String> recipients = const [],
  DateTime? received,
}) {
  var message = _Entity.parse(
    raw is Uint8List ? raw : Uint8List.fromList(raw),
  );
  var bodies = _Bodies()..collect(message, 0);
  return InboxMail(
    sender: sender,
    recipients: List.unmodifiable(recipients),
    from: _addresses(message.headers['from']).firstOrNull,
    to: List.unmodifiable(_addresses(message.headers['to'])),
    subject: switch (message.headers['subject']) {
      var subject? => _decodeEncodedWords(subject),
      null => null,
    },
    text: bodies.text,
    html: bodies.html,
    received: received ?? DateTime.now(),
  );
}