SMTP address validation

SMTP address validation — Validate envelope mailbox addresses

Functions

Types and Values

Description

These validators accept a bare mailbox, not a MIME address header. SMTP validates RFC 5321 syntax and ASCII; SMTPUTF8 additionally applies the Unicode, NFC, contextual and script policies of MimeKit's implementation of draft-ietf-mailmaint-smtputf8-syntax-06. Unicode 18.0.0 tables are pinned, independently of the system GLib Unicode/IDNA version.

Functions

g_mime_smtp_address_try_validate ()

gboolean
g_mime_smtp_address_try_validate (const char *address,
                                  gssize length,
                                  GMimeSmtpAddressValidationOptions options,
                                  GMimeSmtpAddressError *error);

Checks the complete address without trimming, parsing display names, or changing it. Invalid UTF-8 and embedded NUL bytes are syntax errors. Syntax errors precede non-ASCII errors, which precede optional length errors. Quotes and escape sequences count toward the length limits. Domain literals are exempt from label/domain limits, but not the overall address limit.

Parameters

address

a bare mailbox address in UTF-8

 

length

byte length, or -1 for a NUL-terminated string

 

options

validation options

 

error

the validation result.

[out][optional]

Returns

TRUE if valid; otherwise FALSE with the reason in error .

Since: 4.0


g_mime_smtp_address_try_validate_mailbox ()

gboolean
g_mime_smtp_address_try_validate_mailbox
                               (GMimeMailboxAddress *mailbox,
                                GMimeSmtpAddressValidationOptions options,
                                GMimeSmtpAddressError *error);

Validates the mailbox's address as stored, ignoring the display name and route. Does not convert its domain to an IDN-encoded form.

Parameters

mailbox

a mailbox

 

options

validation options

 

error

the validation result.

[out][optional]

Returns

TRUE if valid for SMTP.

Since: 4.0


g_mime_smtp_utf8_address_try_validate ()

gboolean
g_mime_smtp_utf8_address_try_validate (const char *address,
                                       gssize length,
                                       GMimeSmtpUtf8AddressValidationOptions options,
                                       GMimeSmtpUtf8AddressError *error);

Validates syntax, optional lengths, A-label policy, PRECIS code points, NFC, context rules, and script mixtures, in that order. Invalid UTF-8 and embedded NUL bytes are syntax errors. Unicode 18.0.0 data is used on every platform.

Local-part and whole-address limits use the original UTF-8 bytes; domain lengths use raw Punycode A-label sizes. Lengths are checked before IDN decoding. Decoded A-labels must be canonical, at most 63 octets, and satisfy the same Unicode rules as U-labels. Local-part A-label atoms are never decoded.

The input is not normalized, mapped, case-folded, or modified. Passing a NULL error provides a simple validity check. This policy is stricter than the SMTPUTF8 transport grammar and is not a guarantee against all spoofing.

Parameters

address

a bare mailbox address in UTF-8

 

length

byte length, or -1 for a NUL-terminated string

 

options

validation options

 

error

the validation result.

[out][optional]

Returns

TRUE if valid; otherwise FALSE with the reason in error .

Since: 4.0


g_mime_smtp_utf8_address_try_validate_mailbox ()

gboolean
g_mime_smtp_utf8_address_try_validate_mailbox
                               (GMimeMailboxAddress *mailbox,
                                GMimeSmtpUtf8AddressValidationOptions options,
                                GMimeSmtpUtf8AddressError *error);

Validates the mailbox's address as stored using g_mime_smtp_utf8_address_try_validate(), ignoring the display name and route.

Parameters

mailbox

a mailbox

 

options

validation options

 

error

the validation result.

[out][optional]

Returns

TRUE if valid under the SMTPUTF8 validation policy.

Since: 4.0

Types and Values

enum GMimeSmtpAddressValidationOptions

Optional SMTP validation policies.

Members

GMIME_SMTP_ADDRESS_VALIDATION_NONE

Validate syntax without length limits.

 

GMIME_SMTP_ADDRESS_VALIDATION_ALLOW_ISO2022JP_LOCAL_PART

Permit ISO-2022-JP escape sequences in a quoted local-part, ending in ASCII mode.

 

GMIME_SMTP_ADDRESS_VALIDATION_ENFORCE_LENGTH_LIMITS

Enforce SMTP/DNS lengths.

 

enum GMimeSmtpUtf8AddressValidationOptions

Optional SMTPUTF8 validation policies.

Members

GMIME_SMTP_UTF8_ADDRESS_VALIDATION_NONE

Validate the address as written.

 

GMIME_SMTP_UTF8_ADDRESS_VALIDATION_DECODE_IDN

Decode canonical domain A-labels.

 

GMIME_SMTP_UTF8_ADDRESS_VALIDATION_ASCII_IS_LATIN

Count ASCII letters as Latin within the local-part and separately within each domain label.

 

GMIME_SMTP_UTF8_ADDRESS_VALIDATION_ENFORCE_LENGTH_LIMITS

Enforce SMTP/DNS lengths.

 

enum GMimeSmtpAddressError

Validation results, in precedence order. Length errors require the length option. These are results, not a GError domain.

Members

GMIME_SMTP_ADDRESS_ERROR_NONE

Valid address.

 

GMIME_SMTP_ADDRESS_ERROR_SYNTAX

Invalid mailbox syntax or invalid UTF-8.

 

GMIME_SMTP_ADDRESS_ERROR_NON_ASCII

Syntactically valid but requires SMTPUTF8.

 

GMIME_SMTP_ADDRESS_ERROR_LOCAL_PART_TOO_LONG

Local-part exceeds 64 octets.

 

GMIME_SMTP_ADDRESS_ERROR_LABEL_TOO_LONG

Domain label exceeds 63 octets.

 

GMIME_SMTP_ADDRESS_ERROR_DOMAIN_TOO_LONG

Domain exceeds 253 octets.

 

GMIME_SMTP_ADDRESS_ERROR_ADDRESS_TOO_LONG

Address exceeds 254 octets.

 

enum GMimeSmtpUtf8AddressError

Validation results, in precedence order. Length errors require the length option. These are results, not a GError domain.

Members

GMIME_SMTP_UTF8_ADDRESS_ERROR_NONE

Valid address.

 

GMIME_SMTP_UTF8_ADDRESS_ERROR_SYNTAX

Invalid mailbox syntax or invalid UTF-8.

 

GMIME_SMTP_UTF8_ADDRESS_ERROR_LOCAL_PART_TOO_LONG

Local-part exceeds 64 UTF-8 octets.

 

GMIME_SMTP_UTF8_ADDRESS_ERROR_LABEL_TOO_LONG

Domain label exceeds 63 A-label octets.

 

GMIME_SMTP_UTF8_ADDRESS_ERROR_DOMAIN_TOO_LONG

Domain exceeds 253 A-label octets.

 

GMIME_SMTP_UTF8_ADDRESS_ERROR_ADDRESS_TOO_LONG

Address exceeds 254 UTF-8 octets.

 

GMIME_SMTP_UTF8_ADDRESS_ERROR_A_LABEL

Forbidden or invalid A-label.

 

GMIME_SMTP_UTF8_ADDRESS_ERROR_DISALLOWED_CODE_POINT

Code point is not permitted.

 

GMIME_SMTP_UTF8_ADDRESS_ERROR_NOT_NORMALIZED

Address is not NFC.

 

GMIME_SMTP_UTF8_ADDRESS_ERROR_CONTEXT_RULE

A contextual rule is unsatisfied.

 

GMIME_SMTP_UTF8_ADDRESS_ERROR_MIXED_SCRIPTS

Disallowed script mixture.