Clean up
This commit is contained in:
parent
5fc635571b
commit
90cdf758c2
23
src/SMTP.php
23
src/SMTP.php
|
|
@ -633,31 +633,28 @@ class SMTP
|
|||
return false;
|
||||
}
|
||||
$oauth = $OAuth->getOauth64();
|
||||
|
||||
/*
|
||||
* 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
|
||||
* An SMTP command line can have a maximum length of 512 bytes, including the command name,
|
||||
* so the base64-encoded OAUTH token has a maximum length of 512 - 13 (AUTH XOAUTH2) - 2 (CRLF) = 497 bytes
|
||||
* If the token is longer than that, the command and the token must be sent separately as described in
|
||||
* https://www.rfc-editor.org/rfc/rfc4954#section-4
|
||||
*/
|
||||
if (strlen($oauth) <= 497) {
|
||||
//Start authentication
|
||||
//Authenticate using a token in the initial-response part
|
||||
if (!$this->sendCommand('AUTH', 'AUTH XOAUTH2 ' . $oauth, 235)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// Send the command and expect a code 334
|
||||
//The token is too long, so we need to send it in two parts.
|
||||
//Send the auth command without a token and expect a 334
|
||||
if (!$this->sendCommand('AUTH', 'AUTH XOAUTH2', 334)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Send the token
|
||||
if (!$this->sendCommand('Oauth TOKEN', $oauth, [235, 334])) {
|
||||
//Send the token
|
||||
if (!$this->sendCommand('OAuth TOKEN', $oauth, [235, 334])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the server answer with a code 334, send an empty line and wait for a code 235
|
||||
//If the server answers with 334, send an empty line and wait for a 235
|
||||
if (
|
||||
substr($this->last_reply, 0, 3) === '334'
|
||||
&& $this->sendCommand('AUTH End', '', 235)
|
||||
|
|
|
|||
Loading…
Reference in New Issue