The address text. It must be exactly one mailbox.
The parsed mailbox, normalized for use in a header or as an SMTP envelope path. The result is plain immutable data owned by the caller.
Accepted grammar: the mailbox productions addr-spec and
[display-name] angle-addr, with comments and folding whitespace anywhere the
grammar allows them, including the obsolete forms that permit CFWS around the
dots of a local part or domain. Group syntax is not a mailbox; use
parseAddressList for a header that may contain groups.
Normalization:
user@例え.jp becomes user@xn--r8jz45g.jp;user@a_b.example is
rejected;"john.doe"@example.com is therefore
the same mailbox as john.doe@example.com (RFC 5321 section 4.1.2);=?UTF-8?B?...?=
yields readable text.Validation is strict where the address could become an envelope recipient: the
RFC 5321 length limits apply (64-octet local part, 255-octet domain, 254-octet
address), a domain literal must be a real IPv4, IPv6, or general address
literal, and control characters are rejected, including in a decoded display
name. A comment is CFWS rather than a display name, so user@example.com (Bob)
has no display name.
AddressError When the input is not a single valid mailbox. AddressError.kind identifies the reason.
import { AddressError, addressErrorKind, parseAddress } from "@mxraven/mail";
const mailbox = parseAddress("Acme <Noreply@例え.jp>");
mailbox.localPart; // "Noreply"
mailbox.domain; // "xn--r8jz45g.jp"
mailbox.displayName; // "Acme"
try {
parseAddress("user@例え-.jp");
} catch (error) {
if (error instanceof AddressError && error.kind === addressErrorKind.invalidDomain) {
// The domain is not a valid DNS name.
}
}
Parses one RFC 5322 mailbox address and normalizes it.
This is the parser the SDK itself uses for envelope senders and recipients and for the address headers it builds, so a value that parses here can be put on the wire unchanged. Use it to validate input before handing it to Message or Client, or to inspect how an address will be normalized.