Version 4.2.0

This commit is contained in:
Neo committed 2025-12-19 05:44:59 -08:00
1 parent 0dc2aee5ed
commit 96997ddd8e
2074 files changed
+125454 -55780

No files matched your search

+59 -27
View File
@@ -1,12 +1,11 @@
<?php
/**
* @brief Outgoing Email Class
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Community Suite
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @since 17 Apr 2013
* @version SVN_VERSION_NUMBER
*/
namespace IPS;
@@ -312,7 +311,7 @@ abstract class _Email
something to read */
if ( $language === NULL )
{
$language = $member ? $member->language() : \IPS\Lang::load( \IPS\Lang::defaultLanguage() );
$language = $member ? $member->language( TRUE ) : \IPS\Lang::load( \IPS\Lang::defaultLanguage() );
}
$this->language = $language;
@@ -347,9 +346,10 @@ abstract class _Email
* @param NULL|string $fromName The name the email should appear from. If NULL, default setting is used
* @param array $additionalHeaders Additional headers to send
* @param string $eol EOL character to use
* @param int|NULL $lineLimit Maximum line length
* @return string
*/
public function compileFullEmail( $to, $cc=array(), $bcc=array(), $fromEmail = NULL, $fromName = NULL, $additionalHeaders = array(), $eol = "\r\n" )
public function compileFullEmail( $to, $cc=array(), $bcc=array(), $fromEmail = NULL, $fromName = NULL, $additionalHeaders = array(), $eol = "\r\n", $lineLimit = 998 )
{
$boundary = "--==_mimepart_" . md5( uniqid() );
@@ -357,13 +357,19 @@ abstract class _Email
foreach ( $this->_compileHeaders( $this->compileSubject( static::_getMemberFromRecipients( $to ) ), $to, $cc, $bcc, $fromEmail, $fromName, $additionalHeaders, $boundary ) as $k => $v )
{
$return .= "{$k}: {$v}{$eol}";
$line = "{$k}: {$v}";
if ( $lineLimit )
{
$line = wordwrap( $line, $lineLimit, $eol );
}
$return .= $line . $eol;
}
$return .= $eol;
$return .= $eol;
$return .= $this->_compileMessage( static::_getMemberFromRecipients( $to ), $boundary, $eol );
$return .= $this->_compileMessage( static::_getMemberFromRecipients( $to ), $boundary, $eol, $lineLimit );
return $return;
}
@@ -440,10 +446,11 @@ abstract class _Email
* @param \IPS\Member $member If the email is going to a member, the member object. Ensures correct language is used.
* @param string $boundary The boundary used in the Content-Type header
* @param string $eol EOL character to use
* @param int|NULL $lineLimit Maximum line length
* @return bool
* @throws \IPS\Email\Outgoing\Exception
*/
protected function _compileMessage( \IPS\Member $member = NULL, $boundary, $eol )
protected function _compileMessage( \IPS\Member $member = NULL, $boundary, $eol, $lineLimit = 998 )
{
$return = '';
@@ -452,8 +459,19 @@ abstract class _Email
$return .= "--{$boundary}{$eol}";
$return .= "Content-Type: {$contentType}; charset=UTF-8{$eol}";
$return .= "{$eol}";
$return .= preg_replace( "/(?<!\r)\n/", "{$eol}", $content );
$return .= "{$eol}";
$content = preg_replace( "/(?<!\r)\n/", "{$eol}", $content );
if ( $lineLimit )
{
foreach ( explode( $eol, $content ) as $line )
{
$return .= wordwrap( $line, $lineLimit, $eol ) . $eol;
}
}
else
{
$return .= $content . $eol;
}
}
$return .= "--{$boundary}--{$eol}";
@@ -1174,24 +1192,38 @@ abstract class _Email
{
$url = \IPS\Http\Url::createFromString( $node->getAttribute('src') );
/* Strip "do" param, but only if it is set to "embed" */
if ( isset( $url->queryString['do'] ) AND $url->queryString['do'] == 'embed' )
/* If this is an external embed link, swap it for whatever is actually embedded */
if ( $url instanceof \IPS\Http\Url\Internal and isset( $url->queryString['app'] ) and $url->queryString['app'] == 'core' and isset( $url->queryString['module'] ) and $url->queryString['module'] == 'system' and isset( $url->queryString['controller'] ) and $url->queryString['controller'] == 'embed' and isset( $url->queryString['url'] ) )
{
$url = $url->stripQueryString( 'do' );
try
{
$url = new \IPS\Http\Url( $url->queryString['url'] );
}
catch ( \Exception $e ) { }
}
/* Convert embedDo and embedComment if present */
if ( isset( $url->queryString['embedDo'] ) )
{
$url = $url->setQueryString( 'do', $url->queryString['embedDo'] )->stripQueryString( 'embedDo' );
}
if ( isset( $url->queryString['embedComment'] ) )
{
$url = $url->setQueryString( 'comment', $url->queryString['embedComment'] )->stripQueryString( 'embedComment' );
}
/* Same for internal embeds */
if ( $url instanceof \IPS\Http\Url\Internal )
{
/* Strip "do" param, but only if it is set to "embed" */
if ( isset( $url->queryString['do'] ) AND $url->queryString['do'] == 'embed' )
{
$url = $url->stripQueryString( 'do' );
}
/* Convert embedDo and embedComment if present */
if ( isset( $url->queryString['embedDo'] ) )
{
$url = $url->setQueryString( 'do', $url->queryString['embedDo'] )->stripQueryString( 'embedDo' );
}
if ( isset( $url->queryString['embedComment'] ) )
{
$url = $url->setQueryString( 'comment', $url->queryString['embedComment'] )->stripQueryString( 'embedComment' );
}
}
/* Swap the iframe for a link */
$a = new \DOMElement( 'a' );
$parent->insertBefore( $a, $node );
$a->setAttribute( 'href', (string) $url );
+5 -6
View File
@@ -1,12 +1,11 @@
<?php
/**
* @brief Incoming email parsing and routing
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Community Suite
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @since 12 June 2013
* @version SVN_VERSION_NUMBER
*/
namespace IPS\Email\Incoming;
@@ -463,7 +462,7 @@ class _Email
protected $imagePlaceholders = array();
/**
* Turn body into sanatised HTML for use within IPS Community Suite
* Turn body into sanatised HTML for use within Invision Community
*
* @param string $body Email body
* @param array $contentType Content-Type data (as returned by _parseStructuredHeader)
+4 -5
View File
@@ -1,12 +1,11 @@
<?php
/**
* @brief POP/IMAP Incoming Email Handler
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Community Suite
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @since 21 December 2015
* @version SVN_VERSION_NUMBER
*/
namespace IPS\Email\Incoming;
+4 -5
View File
@@ -1,12 +1,11 @@
<?php
/**
* @brief POP/IMAP Exception class
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Community Suite
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @since 21 December 2015
* @version SVN_VERSION_NUMBER
*/
namespace IPS\Email\Incoming;
+4 -5
View File
@@ -1,12 +1,11 @@
<?php
/**
* @brief Debug Email Class
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Community Suite
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @since 17 Apr 2013
* @version SVN_VERSION_NUMBER
*/
namespace IPS\Email\Outgoing;
+4 -5
View File
@@ -1,12 +1,11 @@
<?php
/**
* @brief Exception class for email errors
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Community Suite
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @since 26 Aug 2013
* @version SVN_VERSION_NUMBER
*/
namespace IPS\Email\Outgoing;
+24 -18
View File
@@ -1,12 +1,11 @@
<?php
/**
* @brief IPS CiC Email Class
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Community Suite
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @since 13 Dec 2016
* @version SVN_VERSION_NUMBER
*/
namespace IPS\Email\Outgoing;
@@ -80,19 +79,26 @@ class _IpsCic extends \IPS\Email
*/
public function _send( $to, $cc=array(), $bcc=array(), $fromEmail = NULL, $fromName = NULL, $additionalHeaders = array() )
{
\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 ) ),
'fromEmail' => $fromEmail ?: \IPS\Settings::i()->email_out,
'fromName' => $fromName ?: \IPS\Settings::i()->board_name,
'additionalHeaders' => $additionalHeaders,
'subject' => $this->compileSubject( static::_getMemberFromRecipients( $to ) ),
'html' => $this->compileContent( 'html', static::_getMemberFromRecipients( $to ) ),
'plaintext' => $this->compileContent( 'plaintext', static::_getMemberFromRecipients( $to ) ),
'precedence' => ( $this->type === static::TYPE_LIST ) ? 'list' : ( $this->type === static::TYPE_BULK ? 'bulk' : '' )
) );
try
{
\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 ) ),
'fromEmail' => $fromEmail ?: \IPS\Settings::i()->email_out,
'fromName' => $fromName ?: \IPS\Settings::i()->board_name,
'additionalHeaders' => $additionalHeaders,
'subject' => $this->compileSubject( static::_getMemberFromRecipients( $to ) ),
'html' => $this->compileContent( 'html', static::_getMemberFromRecipients( $to ) ),
'plaintext' => $this->compileContent( 'plaintext', static::_getMemberFromRecipients( $to ) ),
'precedence' => ( $this->type === static::TYPE_LIST ) ? 'list' : ( $this->type === static::TYPE_BULK ? 'bulk' : '' )
) );
}
catch( \IPS\Http\Request\Exception $e )
{
throw new \IPS\Email\Outgoing\Exception( $e->getMessage() );
}
}
}
+5 -6
View File
@@ -1,12 +1,11 @@
<?php
/**
* @brief PHP Email Class
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Community Suite
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @since 17 Apr 2013
* @version SVN_VERSION_NUMBER
*/
namespace IPS\Email\Outgoing;
@@ -51,7 +50,7 @@ class _PHP extends \IPS\Email
try
{
if ( !mail( $this->_parseRecipients( $to, TRUE ), static::encodeHeader( $subject ), $this->_compileMessage( static::_getMemberFromRecipients( $to ), $boundary, PHP_EOL ), implode( PHP_EOL, $headers ), \IPS\Settings::i()->php_mail_extra ) )
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();
preg_match( "/^(\d+)/", $error['message'], $matches );
+4 -5
View File
@@ -1,12 +1,11 @@
<?php
/**
* @brief SendGrid Email Class
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Community Suite
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @since 17 Oct 2013
* @version SVN_VERSION_NUMBER
*/
namespace IPS\Email\Outgoing;
+22 -9
View File
@@ -1,12 +1,11 @@
<?php
/**
* @brief SMTP Email Class
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Community Suite
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @since 17 Apr 2013
* @version SVN_VERSION_NUMBER
*/
namespace IPS\Email\Outgoing;
@@ -81,9 +80,10 @@ class _SMTP extends \IPS\Email
/**
* Connect to server
*
* @param bool $checkSsl If set to FALSE, will skip peer certificate verification for TLS connections
* @return void
*/
public function connect()
public function connect( $checkSsl=TRUE )
{
/* Do we already have a connection? */
if( array_key_exists( $this->connectionKey, static::$smtp ) )
@@ -127,11 +127,24 @@ class _SMTP extends \IPS\Email
/* Is TLS being used? */
if( $this->smtpProtocol == 'tls' )
{
if ( $checkSsl )
{
@stream_context_set_option( static::$smtp[ $this->connectionKey ], 'ssl', 'verify_peer', false );
}
$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 ) )
{
throw new \IPS\Email\Outgoing\Exception( \IPS\Member::loggedIn()->language()->addToStack('smtpmail_tls_failed') );
if ( $checkSsl )
{
/* Try again, but ignore SSL checks in case the certificate was self-signed, which will fail when initializing TLS. This will be slightly slower to connect, but will avoid an error in most instances. */
$this->connect( FALSE );
}
else
{
/* If it still failed on the second connection attempt, throw the exception */
throw new \IPS\Email\Outgoing\Exception( \IPS\Member::loggedIn()->language()->addToStack('smtpmail_tls_failed') );
}
}
/* Exchange server (at least) wants EHLO resending for STARTTLS */
@@ -198,7 +211,7 @@ class _SMTP extends \IPS\Email
foreach ( $toEmails as $toEmail )
{
$this->_sendCommand( "RCPT TO:<{$toEmail}>", 250 );
$this->_sendCommand( "RCPT TO:<{$toEmail}>", 250, TRUE );
}
$this->_sendCommand( 'DATA', 354 );
+13 -7
View File
@@ -1,12 +1,11 @@
<?php
/**
* @brief SparkPost Email Class
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Community Suite
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @since 17 Apr 2013
* @version SVN_VERSION_NUMBER
*/
namespace IPS\Email\Outgoing;
@@ -28,7 +27,7 @@ class _SparkPost extends \IPS\Email
/**
* @brief The number of emails that can be sent in one "go"
*/
const MAX_EMAILS_PER_GO = 2000; // SparkPost "recommends" 2000 per cycle
const MAX_EMAILS_PER_GO = 100; // SparkPost "recommends" 2000 per cycle
/**
* @brief If sending a bulk email to more than MAX_EMAILS_PER_GO - does this
@@ -123,7 +122,14 @@ class _SparkPost extends \IPS\Email
$response = $this->_api( 'transmissions', $request );
if ( isset( $response['errors'] ) )
{
throw new \IPS\Email\Outgoing\Exception( $response['errors'][0]['message'], ( isset( $response['errors'][0]['code'] ) ) ? $response['errors'][0]['code'] : NULL );
$error = $response['errors'][0]['message'];
if( isset( $response['errors'][0]['description'] ) )
{
$error .= ': ' . $response['errors'][0]['description'];
}
throw new \IPS\Email\Outgoing\Exception( $error, ( isset( $response['errors'][0]['code'] ) ) ? $response['errors'][0]['code'] : NULL );
}
}