Version 4.5.0

This commit is contained in:
Neo committed 2025-12-19 05:51:58 -08:00
1 parent 1a0c7fd3c2
commit f79dcf067a
3791 files changed
+248032 -76372

No files matched your search

+1 -9
View File
@@ -11,7 +11,7 @@
namespace IPS\Email\Outgoing;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -27,14 +27,6 @@ class _Debug extends \IPS\Email
*/
protected $debugPath = '';
/**
* @brief If sending a bulk email to more than MAX_EMAILS_PER_GO - does this
* class require waiting between cycles? For "standard" classes like
* PHP and SMTP, this will be TRUE - and will cause bulk mails to go
* to a class. For APIs like SparkPost, this can be FALSE
*/
const REQUIRES_TIME_BREAK = TRUE;
/**
* Constructor
*
+1 -1
View File
@@ -11,7 +11,7 @@
namespace IPS\Email\Outgoing;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
+9 -6
View File
@@ -11,7 +11,7 @@
namespace IPS\Email\Outgoing;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -42,12 +42,15 @@ class _IpsCic extends \IPS\Email
/**
* Constructor
*
* @param string $apiKey API Key
* @return void
*/
public function __construct()
{
if ( \IPS\CIC and preg_match( '/^\/var\/www\/html\/(.+?)(?:\/|$)/i', \IPS\ROOT_PATH, $matches ) )
if ( \IPS\CIC2 AND isset( $_SERVER['IPS_CLOUD2_ID'] ) )
{
$this->community = $_SERVER['IPS_CLOUD2_ID'];
}
elseif ( \IPS\CIC and preg_match( '/^\/var\/www\/html\/(.+?)(?:\/|$)/i', \IPS\ROOT_PATH, $matches ) )
{
$this->community = $matches[1];
}
@@ -75,9 +78,9 @@ class _IpsCic extends \IPS\Email
{
\IPS\Http\Url::external( static::ENDPOINT )->request()->post( array(
'siteId' => $this->community,
'to' => explode( ',', static::_parseRecipients( $to, TRUE ) ),
'cc' => explode( ',', static::_parseRecipients( $cc, TRUE ) ),
'bcc' => explode( ',', static::_parseRecipients( $bcc, TRUE ) ),
'to' => array_map( 'trim', explode( ',', static::_parseRecipients( $to, TRUE ) ) ),
'cc' => array_map( 'trim', explode( ',', static::_parseRecipients( $cc, TRUE ) ) ),
'bcc' => array_map( 'trim', explode( ',', static::_parseRecipients( $bcc, TRUE ) ) ),
'fromEmail' => $fromEmail ?: \IPS\Settings::i()->email_out,
'fromName' => $fromName ?: \IPS\Settings::i()->board_name,
'additionalHeaders' => $additionalHeaders,
+4 -6
View File
@@ -11,7 +11,7 @@
namespace IPS\Email\Outgoing;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -42,7 +42,7 @@ class _PHP extends \IPS\Email
$headers = array();
foreach( $this->_compileHeaders( $subject, $to, $cc, $bcc, $fromEmail, $fromName, $additionalHeaders, $boundary ) as $k => $v )
{
if ( !in_array( $k, array( 'To', 'Subject' ) ) )
if ( !\in_array( $k, array( 'To', 'Subject' ) ) )
{
$headers[] = "{$k}: {$v}";
}
@@ -52,11 +52,9 @@ class _PHP extends \IPS\Email
{
if ( !mail( $this->_parseRecipients( $to, TRUE ), static::encodeHeader( $subject ), $this->_compileMessage( static::_getMemberFromRecipients( $to ), $boundary, PHP_EOL, 68 ), implode( PHP_EOL, $headers ), \IPS\Settings::i()->php_mail_extra ) )
{
$error = error_get_last();
if ( $error )
if ( $error = \IPS\IPS::$lastError )
{
preg_match( "/^(\d+)/", $error['message'], $matches );
throw new \IPS\Email\Outgoing\Exception( $error['message'], isset( $matches[1] ) ? $matches[1] : NULL );
throw new \IPS\Email\Outgoing\Exception( $error->getMessage(), $error->getCode() );
}
else
{
+19 -21
View File
@@ -11,7 +11,7 @@
namespace IPS\Email\Outgoing;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -29,14 +29,6 @@ class _SendGrid extends \IPS\Email
*/
const MAX_EMAILS_PER_GO = 1000; // SendGrid has a hard 1000 recipients per request limit
/**
* @brief If sending a bulk email to more than MAX_EMAILS_PER_GO - does this
* class require waiting between cycles? For "standard" classes like
* PHP and SMTP, this will be TRUE - and will cause bulk mails to go
* to a class. For APIs like SparkPost, this can be FALSE
*/
const REQUIRES_TIME_BREAK = FALSE;
/**
* @brief API Key
*/
@@ -86,7 +78,7 @@ class _SendGrid extends \IPS\Email
/* Add the recipients */
foreach ( array( 'to', 'cc', 'bcc' ) as $type )
{
if ( is_array( $$type ) )
if ( \is_array( $$type ) )
{
foreach ( $$type as $recipient )
{
@@ -143,8 +135,8 @@ class _SendGrid extends \IPS\Email
/* Add the subject and content */
$subject = $this->compileSubject( NULL, $language );
$htmlContent = $this->compileContent( 'html', FALSE, $language );
$plaintextContent = $this->compileContent( 'plaintext', FALSE, $language );
$request['subject'] = $subject;
$plaintextContent = preg_replace( '/\*\|(.+?)\|\*/', '*|$1_plain|*', $this->compileContent( 'plaintext', FALSE, $language ) );
$request['subject'] = preg_replace( '/\*\|(.+?)\|\*/', '*|$1_plain|*', $subject );
$request['content'] = array(
array(
'type' => 'text/plain',
@@ -166,7 +158,8 @@ class _SendGrid extends \IPS\Email
foreach ( $substitutions as $k => $v )
{
$language->parseEmail( $v );
$finalSubstitutions["*|{$k}|*"] = $v;
$finalSubstitutions["*|{$k}_plain|*"] = $v;
$finalSubstitutions["*|{$k}|*"] = htmlspecialchars( $v, ENT_QUOTES | ENT_DISALLOWED, 'UTF-8', TRUE );
}
$request['personalizations'][] = array(
@@ -177,6 +170,9 @@ class _SendGrid extends \IPS\Email
/* Add additional headers */
$request = $this->_modifyRequestDataWithHeaders( $request, $additionalHeaders );
/* Log emails sent */
$this->_trackStatistics( \count( $addresses ) );
/* Send */
try
@@ -202,7 +198,7 @@ class _SendGrid extends \IPS\Email
$errorcount = 0;
if ( isset( $response['errors'] ) )
{
$errorcount = count( $response['errors'] );
$errorcount = \count( $response['errors'] );
\IPS\Db::i()->insert( 'core_mail_error_logs', array(
'mlog_date' => time(),
'mlog_to' => json_encode( $addresses ),
@@ -214,17 +210,20 @@ class _SendGrid extends \IPS\Email
'mlog_smtp_log' => NULL
) );
}
return ( count( $recipients ) - $errorcount );
$successCount = ( \count( $recipients ) - $errorcount );
/* Update ad impression count */
\IPS\core\Advertisement::updateEmailImpressions( $successCount );
return $successCount;
}
/**
* Create a request
*
* @param array $recipients Array where the keys are the email addresses to send to and the values are an array of variables to replace
* @param mixed $fromEmail The email address to send from. If NULL, default setting is used. NOTE: This should always be a site-controlled domin. Some services like Sparkpost require the domain to be validated.
* @param mixed $fromName The name the email should appear from. If NULL, default setting is used
* @param array $additionalHeaders Additional headers to send. Merge tags can be used like in content.
* @param \IPS|Lang $language The language the email content should be in
* @return array
*/
protected function _initRequest( $fromEmail = NULL, $fromName = NULL )
@@ -248,7 +247,7 @@ class _SendGrid extends \IPS\Email
if ( \IPS\Settings::i()->sendgrid_ip_pool )
{
$request['ip_pool_name'] = (bool) \IPS\Settings::i()->sendgrid_ip_pool;
$request['ip_pool_name'] = \IPS\Settings::i()->sendgrid_ip_pool;
}
return $request;
@@ -297,7 +296,7 @@ class _SendGrid extends \IPS\Email
unset( $additionalHeaders['To'] );
unset( $additionalHeaders['CC'] );
unset( $additionalHeaders['BCC'] );
if ( count( $additionalHeaders ) )
if ( \count( $additionalHeaders ) )
{
$request['headers'] = $additionalHeaders;
}
@@ -310,7 +309,6 @@ class _SendGrid extends \IPS\Email
* Make API call
*
* @param string $method Method
* @param string $apiKey API Key
* @param array $args Arguments
* @throws \IPS\Email\Outgoing\Exception Indicates an invalid JSON response or HTTP error
* @return array|null
+9 -5
View File
@@ -11,7 +11,7 @@
namespace IPS\Email\Outgoing;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -65,6 +65,11 @@ class _SMTP extends \IPS\Email
/**
* Constructor
*
* @param string $smtpProtocol Protocol to use
* @param string $smtpHost Hostname to connect to
* @param int $smtpPort Port to connect to
* @param string $smtpUser Username
* @param string $smtpPass Password
* @return void
*/
public function __construct( $smtpProtocol, $smtpHost, $smtpPort, $smtpUser, $smtpPass )
@@ -133,7 +138,7 @@ class _SMTP extends \IPS\Email
}
$this->_sendCommand( 'STARTTLS', 220 );
if ( !@\stream_socket_enable_crypto( static::$smtp[ $this->connectionKey ], TRUE, version_compare( PHP_VERSION, '5.6.7' ) >= 0 ? STREAM_CRYPTO_METHOD_SSLv23_CLIENT : STREAM_CRYPTO_METHOD_TLS_CLIENT ) )
if ( !@\stream_socket_enable_crypto( static::$smtp[ $this->connectionKey ], TRUE, STREAM_CRYPTO_METHOD_SSLv23_CLIENT ) )
{
if ( $checkSsl )
{
@@ -199,7 +204,6 @@ class _SMTP extends \IPS\Email
* @param string $fromEmail The email address to send from
* @param array $toEmails Array of email addresses to send to
* @param string $email The full email (with headers, etc.) except the Bcc header
* @param array $additionalHeaders Additional headers to send
* @return void
* @throws \IPS\Email\Outgoing\Exception
*/
@@ -239,7 +243,7 @@ class _SMTP extends \IPS\Email
$response = $this->_getResponse();
/* Get response code */
$code = intval( mb_substr( $response, 0, 3 ) );
$code = \intval( mb_substr( $response, 0, 3 ) );
if ( $expectedResponse !== NULL and $code !== $expectedResponse )
{
if( $resetOnFailure === TRUE )
@@ -273,7 +277,7 @@ class _SMTP extends \IPS\Email
}
/* Log */
$this->log .= $response;
$this->log .= mb_convert_encoding( $response, 'UTF-8', 'ASCII' );
/* Return */
return $response;