Version 2.3.6

This commit is contained in:
Neo committed 2025-12-19 00:26:08 -08:00
1 parent a3bb603c96
commit 19b38c7c74
764 files changed
+143731 -118164

No files matched your search

+274 -113
View File
@@ -1,24 +1,16 @@
<?php
/*
/*
+--------------------------------------------------------------------------
| Invision Power Services Kernel [Email Functions]
| Invision Power Board 2.2.2
| Invision Power Board
| =============================================
| by Matthew Mecham
| (c) 2001 - 2006 Invision Power Services, Inc.
| http://www.invisionpower.com
| =============================================
| Web: http://www.invisionboard.com
| http://www.ibresource.ru/products/invisionpowerboard/
| Time: Monday 05th of March 2007 10:10:55 PM
| Release: e3790216629e5a2aaf37070b32237f06
| Licence Info: http://www.invisionboard.com/?license
| http://www.ibresource.ru/license
+---------------------------------------------------------------------------
| INVISION POWER BOARD ÍÅ ßÂËßÅÒÑß ÁÅÑÏËÀÒÍÛÌ ÏÐÎÃÐÀÌÌÍÛÌ ÎÁÅÑÏÅ×ÅÍÈÅÌ!
| Ïðàâà íà ÏÎ ïðèíàäëåæàò Invision Power Services
| Ïðàâà íà ïåðåâîä IBResource (http://www.ibresource.ru)
| THIS IS NOT FREE / OPEN SOURCE SOFTWARE
+---------------------------------------------------------------------------
|
| > Core Module
@@ -74,147 +66,169 @@ class class_email
*
* @var string
*/
var $from = "";
var $from = "";
/**
* From email address
*
* @var string
*/
var $from_display = "";
/**
* To email address
*
* @var string
*/
var $to = "";
var $to = "";
/**
* Email subject
*
* @var string
*/
var $subject = "";
var $subject = "";
/**
* Email message contents
*
* @var string
*/
var $message = "";
var $message = "";
/**
* Plain text message contents
*
* @var string
*/
var $pt_message = "";
/**
* Attachments: Parts
*
* @var array
*/
var $parts = array();
var $parts = array();
/**
* BCC Email addresses
*
* @var array
*/
var $bcc = array();
var $bcc = array();
/**
* Email headers (sep. \r\n)
* Email headers
*
* @var string
*/
var $mail_headers = "";
var $mail_headers = array();
/**
* Header EOL
* RFC specs state \r\n
* However most servers support \n
* @var string
*/
var $header_eol = "\n";
/**
* Attachments: Multi-part
*
* @var string
*/
var $multipart = "";
var $multipart = "";
/**
* Attachments: Boundry
*
* @var string
*/
var $boundry = "----=_NextPart_000_0022_01C1BD6C.D0C0F9F0";
var $boundry = "----=_NextPart_000_0022_01C1BD6C.D0C0F9F0";
/**
* HTML email flag
*
* @var integer
*/
var $html_email = 0;
var $html_email = 0;
/**
* Email character set
*
* @var string
*/
var $char_set = 'iso-8859-1';
var $char_set = 'utf-8';
/**
* SMTP:
*
* @var boolean
*/
var $smtp_fp = FALSE;
var $smtp_fp = null;
/**
* SMTP: Message
*
* @var string
*/
var $smtp_msg = "";
var $smtp_msg = "";
/**
* SMTP: Port
*
* @var integer
*/
var $smtp_port = 25;
var $smtp_port = 25;
/**
* SMTP: Host
*
* @var string
*/
var $smtp_host = "localhost";
var $smtp_host = "localhost";
/**
* SMTP: Username
*
* @var string
*/
var $smtp_user = "";
var $smtp_user = "";
/**
* SMTP: Password
*
* @var string
*/
var $smtp_pass = "";
var $smtp_pass = "";
/**
* SMTP: Return code
*
* @var string
*/
var $smtp_code = "";
var $smtp_code = "";
/**
* SMTP: Wrap email addresses in brackets flag
*
* @var integer boolean
*/
var $wrap_brackets = 0;
var $wrap_brackets = 0;
/**
* Default email method (mail or smtp)
*
* @var string
*/
var $mail_method = 'mail';
var $mail_method = 'mail';
/**
* Dump email to flat file for testing
*
* @var integer
*/
var $temp_dump = 0;
var $temp_dump = 0;
/**
* Error message
@@ -280,6 +294,9 @@ class class_email
function build_headers()
{
$extra_headers = array();
$extra_header_rfc = "";
//-----------------------------------------
// HTML (hitmuhl)
// If we're sending HTML messages, then
@@ -288,39 +305,56 @@ class class_email
//-----------------------------------------
$this->pt_message = $this->message;
$this->pt_message = str_replace( "<br />", "\n", $this->pt_message );
$this->pt_message = str_replace( "<br>" , "\n", $this->pt_message );
$this->pt_message = strip_tags( $this->pt_message );
$this->pt_message = html_entity_decode( $this->pt_message, ENT_QUOTES );
$this->pt_message = str_replace( '&#092;', '\\', $this->pt_message );
$this->pt_message = str_replace( '&#036;', '$', $this->pt_message );
// Now put & back...
//-----------------------------------------
// Start mail headers
//-----------------------------------------
$this->mail_headers .= "Return-Path: ".$this->from."\n";
$this->mail_headers .= "X-Priority: 3\n";
$this->mail_headers .= "X-Mailer: IPB PHP Mailer\n";
$this->mail_headers['MIME-Version'] = "1.0";
//-----------------------------------------
// From and to...
//-----------------------------------------
$this->mail_headers .= "From: ".$this->from."\n";
if( $this->from_display )
{
$this->mail_headers['From'] = '"' . $this->from_display . '" <' . $this->from . '>';
}
else
{
$this->mail_headers['From'] = '<' . $this->from . '>';
}
if ( $this->mail_method != 'smtp' )
{
if ( count( $this->bcc ) > 1 )
{
$this->mail_headers .= "Bcc: ".implode( "," , $this->bcc ) . "\n";
$this->mail_headers['Bcc'] = implode( "," , $this->bcc );
}
}
else
{
if ( $this->to )
{
$this->mail_headers .= "To: ".$this->to."\n";
$this->mail_headers['To'] = $this->to;
}
$this->mail_headers .= "Subject: ".$this->subject."\n";
$this->mail_headers['Subject'] = $this->subject;
}
# Start MIME headers
$this->mail_headers .= "MIME-Version: 1.0\n";
$this->mail_headers['Return-Path'] = $this->from;
$this->mail_headers['X-Priority'] = "3";
$this->mail_headers['X-Mailer'] = "IPS PHP Mailer";
//-----------------------------------------
// Attachments?
@@ -328,66 +362,116 @@ class class_email
if ( count ($this->parts) > 0 )
{
# Format PT message
if ( $this->html_email )
if ( ! $this->html_email )
{
$this->pt_message = str_replace( "<br />", "\n", $this->pt_message );
$this->pt_message = str_replace( "<br>" , "\n", $this->pt_message );
$this->pt_message = strip_tags( $this->pt_message );
$extra_headers[0]['Content-Type'] = "multipart/mixed;\n\tboundary=\"".$this->boundry."\"";
$extra_headers[0]['notencode'] = "\n\nThis is a MIME encoded message.\n\n--".$this->boundry."\n";
$extra_headers[1]['Content-Type'] = "text/plain;\n\tcharset=\"".$this->char_set."\"";
#$extra_headers[1]['Content-Transfer-Encoding'] = "quoted-printable";
$extra_headers[1]['notencode'] = "\n\n".$this->message."\n\n--".$this->boundry;
}
else
{
$extra_headers[0]['Content-Type'] = "multipart/mixed;\n\tboundary=\"".$this->boundry."\"";
$extra_headers[0]['notencode'] = "\n\nThis is a MIME encoded message.\n\n--".$this->boundry."\n";
$extra_headers[1]['Content-Type'] = "text/html;\n\tcharset=\"".$this->char_set."\"";
#$extra_headers[1]['Content-Transfer-Encoding'] = "quoted-printable";
$extra_headers[1]['notencode'] = "\n\n".$this->message."\n\n--".$this->boundry;
}
# Force plain text emails only
$this->html_email = 0;
$extra_headers[2]['notencode'] = $this->build_multipart();
reset($extra_headers);
foreach( $extra_headers as $subset => $the_header )
{
foreach( $the_header as $k => $v )
{
if( $k == 'notencode' )
{
$extra_headers_rfc .= $v;
}
else
{
$v = $this->encode_headers( array( 'v' => $v ) );
$extra_headers_rfc .= $k.': '.$v['v'].$this->header_eol;
}
}
}
# Do headers
$this->mail_headers .= "Content-type: multipart/mixed;boundary=\"".$this->boundry."\"\n\nThis is a MIME encoded message.\n\n--".$this->boundry;
}
//-----------------------------------------
// Sort out HTML / PT emails
//-----------------------------------------
if ( $this->html_email )
{
# Format PT message
$this->pt_message = str_replace( "<br />", "\n", $this->pt_message );
$this->pt_message = str_replace( "<br>" , "\n", $this->pt_message );
$this->pt_message = strip_tags( $this->pt_message );
# Do headers
$this->mail_headers .= "Content-type: multipart/alternative;boundary=\"".$this->boundry."\"\n\nThis is a MIME encoded message.\n\n--".$this->boundry;
}
//-----------------------------------------
// HTML headers...
//-----------------------------------------
# Plain text version...
$this->mail_headers .= "\nContent-Type: text/plain;\n\tcharset=\"".$this->char_set."\"\n\n".$this->pt_message."\n\n--".$this->boundry;
# HTML version
if ( $this->html_email )
{
$this->mail_headers .= "\nContent-Type: text/html;\n\tcharset=\"".$this->char_set."\"\n\n".$this->message."\n\n";
}
//-----------------------------------------
// Do the attachments last
//-----------------------------------------
if ( count ($this->parts) > 0 )
{
$this->mail_headers .= $this->build_multipart();
}
//-----------------------------------------
// Stop double printing message
//-----------------------------------------
if ( $this->html_email OR count ($this->parts) > 0 )
{
$this->message = "";
}
else
{
//-----------------------------------------
// HTML (hitmuhl) ?
//-----------------------------------------
if ( $this->html_email )
{
$extra_headers[0]['Content-Type'] = "multipart/alternative;\n\tboundary=\"".$this->boundry."\"";
$extra_headers[0]['notencode'] = "\n\nThis is a MIME encoded message.\n\n--".$this->boundry."\n";
$extra_headers[1]['Content-Type'] = "text/html;\n\tcharset=\"".$this->char_set."\"";
#$extra_headers[1]['Content-Transfer-Encoding'] = "quoted-printable";
$extra_headers[1]['notencode'] = "\n\n".$this->message."\n\n--".$this->boundry."\n";
$extra_headers[2]['Content-Type'] = "text/plain;\n\tcharset=\"".$this->char_set."\"";
#$extra_headers[2]['Content-Transfer-Encoding'] = "quoted-printable";
$extra_headers[2]['notencode'] = "\n\n".$this->pt_message."\n\n";
reset($extra_headers);
foreach( $extra_headers as $subset => $the_header )
{
foreach( $the_header as $k => $v )
{
if( $k == 'notencode' )
{
$extra_headers_rfc .= $v;
}
else
{
$v = $this->encode_headers( array( 'v' => $v ) );
$extra_headers_rfc .= $k.': '.$v['v'].$this->header_eol;
}
}
}
$this->message = "";
}
else
{
$this->mail_headers['Content-type'] = 'text/plain; charset="'.$this->char_set.'"';
}
}
$this->encode_headers();
foreach( $this->mail_headers as $k => $v )
{
$this->rfc_headers .= $k.": ".$v.$this->header_eol;
}
//-----------------------------------------
// Attachments extra?
//-----------------------------------------
if( $extra_headers_rfc )
{
$this->rfc_headers .= $extra_headers_rfc;
}
}
/*-------------------------------------------------------------------------*/
@@ -404,12 +488,12 @@ class class_email
{
$multipart = "";
for ( $i = sizeof($this->parts) - 1 ; $i >= 0 ; $i-- )
for ($i = sizeof($this->parts) - 1 ; $i >= 0 ; $i--)
{
$multipart .= "\n--" . $this->boundry . "\n" . $this->_encode_attachment($this->parts[$i]);
$multipart .= $this->header_eol . $this->encode_attachment($this->parts[$i]) . "--" . $this->boundry;
}
return $multipart;
return $multipart . "--\n";
}
@@ -445,6 +529,13 @@ class class_email
$this->build_headers();
if( $this->mail_method != 'smtp' )
{
$subject = $this->encode_headers( array( 'Subject' => $this->subject ) );
$this->subject = $subject['Subject'];
}
//-----------------------------------------
// Lets go..
//-----------------------------------------
@@ -457,12 +548,18 @@ class class_email
if ($this->temp_dump == 1)
{
$blah = $this->subject."\n------------\n".$this->mail_headers."\n\n".$this->message;
$blah = $this->subject."\n------------\n".$this->rfc_headers."\n\n".$this->message;
$pathy = str_replace( '//', '/', $this->root_path.'/_mail/'.date("M-j-Y,hi-A").str_replace( '@', '+', $this->to ).".php" );
$fh = fopen ($pathy, 'w');
fputs ($fh, $blah, strlen($blah) );
fclose($fh);
if( !is_dir( $this->root_path . '/_mail' ) )
{
@mkdir( $this->root_path . '/_mail' );
@chmod( $this->root_path . '/_mail', 0777 );
}
$pathy = str_replace( '//', '/', $this->root_path . '/_mail/' . date("M-j-Y,hi-A") . str_replace( '@', '+', $this->to ) . '.php' );
$fh = @fopen( $pathy, 'w' );
@fputs( $fh, $blah, strlen($blah) );
@fclose( $fh );
}
else
{
@@ -472,10 +569,10 @@ class class_email
if ($this->mail_method != 'smtp')
{
if ( ! @mail( $this->to, $this->subject, $this->message, $this->mail_headers, $this->extra_opts ) )
if ( ! @mail( $this->to, $this->subject, $this->message, $this->rfc_headers, $this->extra_opts ) )
{
# Try without args for safe mode peeps
if ( ! @mail( $this->to, $this->subject, $this->message, $this->mail_headers ) )
if ( ! @mail( $this->to, $this->subject, $this->message, $this->rfc_headers ) )
{
$this->fatal_error("Could not send the email", "Failed at 'mail' command");
}
@@ -498,9 +595,11 @@ class class_email
$this->to = "";
$this->from = "";
$this->from_display = "";
$this->message = "";
$this->pt_message = "";
$this->subject = "";
$this->mail_headers = "";
$this->mail_headers = array();
}
/*-------------------------------------------------------------------------*/
@@ -627,8 +726,13 @@ class class_email
if ( $this->smtp_code != 250 )
{
$this->smtp_error("HELO");
return;
$this->smtp_send_cmd("EHLO ".$this->smtp_host);
if ( $this->smtp_code != 250 )
{
$this->smtp_error("HELO,EHLO");
return;
}
}
//-----------------------------------------
@@ -705,7 +809,7 @@ class class_email
{
if ( $this->wrap_brackets )
{
$this->smtp_send_cmd("RCPT TO:<".$to_email.">");
$this->smtp_send_cmd("RCPT TO:<".$to_email.">");
}
else
{
@@ -783,6 +887,7 @@ class class_email
function fatal_error($msg, $help="")
{
$this->error_msg = $msg;
$this->error_help = $help;
@@ -800,14 +905,70 @@ class class_email
* @return string Processed data
*/
function _encode_attachment($part)
function encode_attachment($part)
{
$msg = chunk_split(base64_encode($part['data']));
return "Content-Type: ".$part['ctype']. ($part['name'] ? ";\n\tname =\"".$part['name']."\"" : "").
"\nContent-Transfer-Encoding: ".$part['encode']."\nContent-Disposition: attachment;\n\tfilename=\"".$part['name']."\"\n\n".$msg."\n";
$headers = array();
$header_str = "";
$headers['Content-Type'] = $part['ctype']. ($part['name'] ? "; name =\"".$part['name']."\"" : "");
$headers['Content-Transfer-Encoding'] = $part['encode'];
$headers['Content-Disposition'] = "attachment; filename=\"".$part['name']."\"";
$headers = $this->encode_headers( $headers );
foreach( $headers as $k => $v )
{
$header_str .= $k.': '.$v.$this->header_eol;
}
$header_str .= "\n\n".$msg."\n";
return $header_str;
}
/*-------------------------------------------------------------------------*/
// ENCODE HEADERS - RFC2047
/*-------------------------------------------------------------------------*/
function encode_headers( $headers = array() )
{
$enc_headers = count($headers) ? $headers : $this->mail_headers;
foreach( $enc_headers as $header => $value)
{
preg_match_all( '/(\w*[\x80-\xFF]+\w*)/', $value, $matches );
foreach ($matches[1] as $value)
{
if( $header == 'From' )
{
// Either sendmail or the email servers don't like 'From' encoded...let's remove the board name
// and just move along, as email address cannot contain nasty characters themselves
$this->mail_headers['From'] = $this->from;
continue 2;
}
$replacement = preg_replace_callback( '/([\x80-\xFF])/', create_function( '$match', 'return "=" . strtoupper( dechex( ord( "$match[1]" ) ) );' ), $value );
$value = str_replace( $value, '=?' . $this->char_set . '?Q?' . $replacement . '?=', $value );
}
if( !count($headers) )
{
$this->mail_headers[ $header ] = $value;
}
else
{
$enc_headers[ $header ] = $value;
}
}
return $enc_headers;
}
}