Added support for maximum command size during XOAUTH2 authentication
This commit is contained in:
parent
912f278a48
commit
8ca031797f
33
src/SMTP.php
33
src/SMTP.php
|
|
@ -634,9 +634,36 @@ class SMTP
|
|||
}
|
||||
$oauth = $OAuth->getOauth64();
|
||||
|
||||
//Start authentication
|
||||
if (!$this->sendCommand('AUTH', 'AUTH XOAUTH2 ' . $oauth, 235)) {
|
||||
return false;
|
||||
/*
|
||||
* The maximum length for an SMTP commands is 512 bytes, according to RFC 4954 (https://datatracker.ietf.org/doc/html/rfc4954).
|
||||
* (In truth this seems more complex than that, but 512 bytes seems to be the stricter limit)
|
||||
*
|
||||
* Therefor, the base64-encoded OAUTH token has a maximum length of 497 : 512 - 13 (AUTH XOAUTH2) - 2 (CRLF)
|
||||
* If the token is longer than that, the command and the token must be sent separately
|
||||
*/
|
||||
if (strlen($oauth) <= 497) {
|
||||
//Start authentication
|
||||
if (!$this->sendCommand('AUTH', 'AUTH XOAUTH2 ' . $oauth, 235)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// Send the command and expect a code 334
|
||||
if (!$this->sendCommand('AUTH', 'AUTH XOAUTH2', 334)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Send the token
|
||||
if (!$this->sendCommand('Oauth TOKEN', $oauth, [235, 334])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the server answer with a code 334, send and empty line an wait for a code 235
|
||||
if (
|
||||
substr($this->last_reply, 0, 3) == 334
|
||||
&& $this->sendCommand('AUTH End', '', 235)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
|
|
|||
Loading…
Reference in New Issue