Table of Contents

Method TrySplit

Namespace
MailFathom.Domain.Emails
Assembly
MailFathom.Domain.dll

TrySplit(ReadOnlySpan<char>, out ReadOnlySpan<char>, out ReadOnlySpan<char>)

Splits an addr-spec into its two halves at the at-sign every split in this system is made at.

public static bool TrySplit(ReadOnlySpan<char> address, out ReadOnlySpan<char> localPartText, out ReadOnlySpan<char> domainText)

Parameters

address ReadOnlySpan<char>

The addr-spec text to read, which may be anything a header carried.

localPartText ReadOnlySpan<char>

What precedes the last at-sign, when the text names a mailbox.

domainText ReadOnlySpan<char>

What follows it.

Returns

bool

true when the text has both halves; otherwise false.

Remarks

The last at-sign, because a quoted local part is allowed to contain one. Both halves must be non-empty for the text to name a mailbox at all, so text that is only a domain, only a local part, or a bare at-sign is refused rather than handed back with an empty half every caller would have to check for. Neither half is validated here: what a usable local part and a usable domain are belongs to the types that own those questions.

TrySplit(out string, out ReadOnlySpan<char>)

Splits this address into the comparison form of its local part and the text of its domain.

public bool TrySplit(out string normalizedLocalPart, out ReadOnlySpan<char> domainText)

Parameters

normalizedLocalPart string

The local part in the form NormalizedAddress is written in.

domainText ReadOnlySpan<char>

The domain exactly as the message wrote it, which is the form a domain type normalizes from.

Returns

bool

true when the address has both halves; otherwise false.

Remarks

The two halves are handed back in different forms because they normalize differently: the local part is compared as text and takes this type's comparison form, while the domain has an encoding to settle and is left to the type that settles it. Reading the domain from Address rather than from the comparison form is what keeps a domain type's own record of what its source wrote intact.

Each form is cut at its own at-sign rather than at an offset carried from the other. A case mapping is not obliged to produce one character per character, so an offset taken from the written address would cut the comparison form of a local part that expanded — handing back a truncated prefix that a shorter, unrelated mailbox could also produce, in a value sender trust and recipient governance then compare on.