laminas / laminas-mail

Provides generalized functionality to compose and send both text and MIME-compliant multipart e-mail messages
https://docs.laminas.dev/laminas-mail/
BSD 3-Clause "New" or "Revised" License
94 stars 64 forks source link

Mail recepients with German umlaut are not accepted #67

Open michalbundyra opened 4 years ago

michalbundyra commented 4 years ago

Cloned this from zf2 issue repository for correct assignment to zend-mail:

https://github.com/zendframework/zf2/issues/7654

Hi,

since ZF v2.4.x, I cannot send any mails to recepients containing German umlauts in their mail address. For exmaple: testäöü@gmail.com Encoding is set to UTF-8 on Zend\Mail\Message object. The following expection is thrown:

Invalid header value detected #0 foobar\vendor\zendframework\zend-mail\src\Header\AbstractAddressList.php(114): Zend\Mail\Header\HeaderValue::assertValid('test\xC3\xA4\xC3\xB6\xC3\xBC@gmai...') #1 foobar\vendor\zendframework\zend-mail\src\Header\AbstractAddressList.php(158): Zend\Mail\Header\AbstractAddressList->getFieldValue(true) #2 foobar\vendor\zendframework\zend-mail\src\Headers.php(422): Zend\Mail\Header\AbstractAddressList->toString() #3 foobar\vendor\zendframework\zend-mail\src\Transport\Smtp.php(332): Zend\Mail\Headers->toString() #4 foobar\vendor\zendframework\zend-mail\src\Transport\Smtp.php(238): Zend\Mail\Transport\Smtp->prepareHeaders(Object(Zend\Mail\Message)) #5 foobar\vendor\Solar\library\Solar\Mail\Mail.php(144): Zend\Mail\Transport\Smtp->send(Object(Zend\Mail\Message)) #6 foobar\vendor\Solar\library\Solar\Client\AbstractClient.php(249): Solar\Mail\Mail->sendSmtp('processrevenuec...', Array, true, '') #7 foobar\modules\eonde\Processrevenuecheck.php(73): Solar\Client\AbstractClient->sendMail('test\xC3\xA4\xC3\xB6\xC3\xBC@gmai...', '', Array) #8 foobar\vendor\Solar\library\Solar\Bootstrap\Bootstrap.php(248): modules\eonde\Processrevenuecheck->run() #9 foobar\index.php(80): Solar\Bootstrap\Bootstrap->getResponse() #10 {main}

Umlauts work fine with the subject and body. Also, the value passes the \Zend\Validate\EmailAddress validator. It might be related to this issue although I cannot gain any workaround from it: https://github.com/zendframework/zf2/issues/7501

Update: Seems like RFC6531 was implemented in zend-validate but not yet zend-mail.


Originally posted by @renecatharsis at https://github.com/zendframework/zend-mail/issues/49

michalbundyra commented 4 years ago

AFAIK umlauts are not allowed in an email address (yet). The current accepted standard is RFC 2822 and non ASCII characters are not allowed in the local-part there. Non ASCII characters are proposed in RFC 6531. But this is still markes as PROPOSED STANDARD and was not implemented in Zend\Validator\EmailAddress::validateLocalPart() (see: https://github.com/zendframework/zend-validator/blob/master/src/EmailAddress.php#L334). Which version of zend-validator do you use? isValid() returns false for me (2.5.3/latest stable).


Originally posted by @BreyndotEchse at https://github.com/zendframework/zend-mail/issues/49#issuecomment-169629428

michalbundyra commented 4 years ago

I'm using v2.5.3 as well. Installed by composer as part of zendframework/zendframework": "2.* For me the validator returns true. intl extension is loaded, the function idnToAscii actually calls PHP's idn_to_ascii function.

Running on a Win7 x64 with PHP7.0.0 wampstack, if that helps.


Originally posted by @renecatharsis at https://github.com/zendframework/zend-mail/issues/49#issuecomment-169638140

michalbundyra commented 4 years ago

Oh. You're right. Intl was not loaded in my test environment. I have looked up RFC 6531, 6530, 5336, 5891 and 5890 and could not find any reference that the local-part could be converted to IDN ASCII. Actually there are some hints that the local-part SHOULD NOT be converted.

RFC 5891:

IDNA does not update the existing email standards, which allow only ASCII characters in local parts. Even though work is in progress to define internationalization for email addresses [RFC4952], changes to the email address part of the SOA RDATA would require action in, or updates to, other standards, specifically those that specify the format of the SOA RR.

(https://tools.ietf.org/html/rfc5891#section-3.2.2)

RFC 6530:

In order to use internationalized email addresses, it is necessary to internationalize both the domain part and the local part of email addresses. The domain part of email addresses is already internationalized [RFC5890], while the local part is not.

(https://tools.ietf.org/html/rfc6530#section-1)

IMO the behavior in zend-validator is wrong.

However google gave me some results of people claiming that some email providers actually support IDN converted local-parts. Let's ask @svyatoslav-kubakh who implemented IDN (zendframework/zf2#7281). Maybe he can give us more information on this.


Originally posted by @BreyndotEchse at https://github.com/zendframework/zend-mail/issues/49#issuecomment-169947340

arcaste commented 4 years ago

For German umlaut you need to set UTF-8 with setEncoding method in \Laminas\Mail\Message()

lklapa commented 4 years ago

I also came across this issue. While I am aware of the rules of the RFC, the current behaviour is not consistent. An e-mail address with accents returns true for Laminas\Validator\EmailAddress validator, but the same e-mail is rejected by the Laminas\Mail\Header\HeaderValue's isValid().

The Laminas\Validator\EmailAddress has the option strict, but even though it defaults to true it doesn't take into account RFC 2822.

Is now only manual/additional validation the way to go? There is a mention of this in the validator: https://github.com/laminas/laminas-validator/issues/7 and it looks like this issue is with the Laminas\Validator\EmailAddress.