SmtpResponseLine.parse constructor

SmtpResponseLine.parse(
  1. String text
)

Parses the given response text.

A reply line is Reply-code [ SP textstring ] or Reply-code "-" [ textstring ] (RFC 5321, section 4.2), so both the separator and the text are optional: a bare 250 is a valid line.

Implementation

factory SmtpResponseLine.parse(String text) {
  final code = text.length < 3 ? null : int.tryParse(text.substring(0, 3));
  if (code == null) {
    return SmtpResponseLine(500, text);
  }
  final message = text.length > 4 ? text.substring(4) : '';

  return SmtpResponseLine(code, message);
}