def handle_mail(state: State, arguments: str) -> Reply: if arguments[:5].upper() != "FROM:": return handle_wrong_arguments() try: path, rest = parse_reverse_path(arguments[5:]) except ValueError as exc: return handle_wrong_arguments(str(exc)) if not is_valid_smtp_arguments(rest): return handle_wrong_arguments() if not state.greeted: return handle_no_greeting() if not state.mail_allowed: return handle_bad_command_sequence() state.clear() state.reverse_path = path return SMTPStatus.OK, "Sender OK"
def test_invalid_domain(self) -> None: with pytest.raises(ValueError): parse_reverse_path("<foo@*>")
def test_empty_path(self) -> None: path, rest = parse_reverse_path("<>") assert path == "" assert rest == ""
def test_missing_at(self) -> None: with pytest.raises(ValueError): parse_reverse_path("<invalid>")
def test_invalid_local_part(self) -> None: with pytest.raises(ValueError): parse_reverse_path("<@@example.com>")
def test_invalid(self) -> None: with pytest.raises(ValueError): parse_reverse_path("INVALID")
def test_quoted_string(self) -> None: path, rest = parse_reverse_path('<"foo \\" bar"@example.com>') assert path == '"foo \\" bar"@example.com' assert rest == ""
def test_mailbox_with_rest(self) -> None: path, rest = parse_reverse_path("<*****@*****.**>REST") assert path == "*****@*****.**" assert rest == "REST"
def test_mailbox(self) -> None: path, rest = parse_reverse_path("<*****@*****.**>") assert path == "*****@*****.**" assert rest == ""
def test_empty_path_with_rest(self) -> None: path, rest = parse_reverse_path("<>REST") assert path == "" assert rest == "REST"