Version 5.0.0 beta 9

This commit is contained in:
Neo committed 2025-12-19 17:47:00 -08:00
1 parent 214f649f1d
commit 56979f8ee8
202 files changed
+4403 -1123

No files matched your search

+31 -11
View File
@@ -10,9 +10,9 @@
namespace IPS\Email\Outgoing;
/* To prevent PHP errors (extending class does not exist) revealing path */
use IPS\Email;
use IPS\Login;
use IPS\Http\Url;
use IPS\Request;
use IPS\Settings;
use function defined;
@@ -21,6 +21,8 @@ use function stream_socket_enable_crypto;
use const IPS\DEFAULT_REQUEST_TIMEOUT;
use const IPS\VERY_LONG_REQUEST_TIMEOUT;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
@@ -128,15 +130,16 @@ class Smtp extends Email
}
/* HELO/EHLO */
$ehloFqdn = \IPS\Http\Url::internal('')->data['host'];
try
{
$helo = 'EHLO';
$responseCode = $this->_sendCommand('EHLO ' . $this->smtpHost, 250);
$responseCode = $this->_sendCommand( 'EHLO ' . $ehloFqdn, 250 );
}
catch (Exception $e )
{
$helo = 'HELO';
$responseCode = $this->_sendCommand('HELO ' . $this->smtpHost, 250);
$responseCode = $this->_sendCommand( 'HELO ' . $ehloFqdn, 250 );
}
/* Is TLS being used? */
@@ -163,7 +166,7 @@ class Smtp extends Email
}
/* Exchange server (at least) wants EHLO resending for STARTTLS */
$this->_sendCommand($helo . ' ' . $this->smtpHost, 250);
$this->_sendCommand( $helo . ' ' . $ehloFqdn, 250 );
}
/* Authenticate */
@@ -193,19 +196,24 @@ class Smtp extends Email
$fromEmail = $fromEmail ?: Settings::i()->email_out;
/* SMTP requires you to do CC/BCC by sending a RCPT TO command for each recipient. We'll hide BCC by not actually setting that header */
$recipieintsForSmtp = explode( ',', static::_parseRecipients( $to, TRUE ) );
$recipientsForSmtp = explode( ',', static::_parseRecipients( $to, TRUE ) );
if ( $cc )
{
$recipieintsForSmtp = array_merge( $recipieintsForSmtp, explode( ',', static::_parseRecipients( $cc, TRUE ) ) );
$recipientsForSmtp = array_merge( $recipientsForSmtp, explode( ',', static::_parseRecipients( $cc, TRUE ) ) );
}
if ( $bcc )
{
$recipieintsForSmtp = array_merge( $recipieintsForSmtp, explode( ',', static::_parseRecipients( $bcc, TRUE ) ) );
$recipientsForSmtp = array_merge( $recipientsForSmtp, explode( ',', static::_parseRecipients( $bcc, TRUE ) ) );
}
$recipieintsForSmtp = array_unique( array_map( 'trim', $recipieintsForSmtp ) );
$recipientsForSmtp = array_unique( array_map( 'trim', $recipientsForSmtp ) );
if( empty( $additonalHeaders['Message-ID'] ) )
{
$additionalHeaders['Message-ID'] = $this->generateMessageId();
}
/* Send */
$this->_sendCompiled( $fromEmail, $recipieintsForSmtp, $this->compileFullEmail( $to, $cc, array(), $fromEmail, $fromName, $additionalHeaders ) );
$this->_sendCompiled( $fromEmail, $recipientsForSmtp, $this->compileFullEmail( $to, $cc, array(), $fromEmail, $fromName, $additionalHeaders ) );
}
/**
@@ -292,6 +300,18 @@ class Smtp extends Email
/* Return */
return $response;
}
/**
* Generate random message-id
*
* @return string
*/
public function generateMessageId(): string
{
$randomString = base_convert( microtime() . '.' . Login::generateRandomString(), 10, 36 );
return '<' . $randomString . '@' . Url::internal('')->data[ Url::COMPONENT_HOST ] . '>';
}
/**
* Return the SMTP log