Make WordPress Core

Opened 6 years ago

Closed 4 months ago

Last modified 7 days ago

#48951 closed feature request (worksforme)

email_too_short is not good email validation candidate

Reported by: dingo_d's profile dingo_d Owned by:
Milestone: Priority: low
Severity: trivial Version: 5.4
Component: Mail Keywords: 2nd-opinion
Focuses: Cc:

Description

Currently, both is_email and sanitize_email will invalidate/sanitize valid emails:

'admin@mailserver1'
'm@m'

Both are valid emails. ICANN just discourages using them.

The problem comes when you work with decoupled WordPress, and the front end is using custom validation that allows such emails, but WordPress doesn't so you don't have consistent behavior. Plus this is just wrong, as the official specification allows such mails.

https://en.wikipedia.org/wiki/Email_address#Valid_email_addresses

Change History (4)

#1 @SergeyBiryukov
6 years ago

  • Component changed from Formatting to Mail

#2 @cbutlerjr
5 years ago

  • Priority changed from normal to low
  • Severity changed from normal to trivial
  • Type changed from defect (bug) to feature request

but WordPress doesn't so you don't have consistent behavior

WP runs filters in both is_email() and sanitize_email(). If necessary, you can run a filter on either of these so that if the $context is 'email_too_short', you return true instead.

#3 @SirLouen
4 months ago

  • Resolution set to worksforme
  • Status changed from new to closed

The problem comes when you work with decoupled WordPress, and the front end is using custom validation that allows such emails, but WordPress doesn't so you don't have consistent behavior. Plus this is just wrong, as the official specification allows such mails.

This is correct, despite ICANN discourages the use of no dot domains, RFC allows it.

But since we are using is_mail as the current mail validator, there is a filter that allows doing this:

https://github.com/SirLouen/wordpress-develop/blob/f152321f2fe5665cb28486de04fa54bdf58fb252/src/wp-includes/formatting.php#L3604-L3608

So you can simply add something like this:

function no_periods_domain( $is_email, $email, $context ) {
    if ( 'domain_no_periods' === $context ) {
        return $email;
    }
    return $is_email;
}
add_filter( 'is_email', 'no_periods_domain', 10, 3 );

And you will be able to use those formats without trouble.

Return-Path: <supertester@example-test-2>
Received: from localhost (unknown [172.20.0.1])
        by 144d19eeeff3 (Mailpit) with SMTP
        for <admin@mailserver1>; Thu, 7 Aug 2025 10:34:17 +0000 (UTC)
Date: Thu, 7 Aug 2025 10:34:17 +0000
To: admin@mailserver1
From: WordPress <supertester@example-test-2>
Subject: Baseline test
Message-ID: <DcDMxyXzLdkJ4D6bdgNGeKaAa5TNkWcdChUNS4S4@localhost>
X-Mailer: PHPMailer 6.9.3 (https://github.com/PHPMailer/PHPMailer)
x-my-things: thing3
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8

See attachments.

#4 @swissspidy
7 days ago

  • Milestone Awaiting Review deleted

Removing milestone from closed ticket.

Note: See TracTickets for help on using tickets.