mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-22 14:23:57 -07:00
r545
Упрощение emailer (удаление неиспользуемых функций прикрепления файлов к письму) с некоторыми заделами на будущее. git-svn-id: https://torrentpier2.googlecode.com/svn/trunk@545 a8ac35ab-4ca4-ca47-4c2d-a49a94f06293
This commit is contained in:
parent
1baf7460d0
commit
b0eadd11b0
2 changed files with 53 additions and 144 deletions
|
@ -56,7 +56,7 @@ $domain_name = (!empty($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : $do
|
|||
// Increase number of revision after update
|
||||
$bb_cfg['tp_version'] = '2.5 (unstable)';
|
||||
$bb_cfg['tp_release_date'] = '10-08-2013';
|
||||
$bb_cfg['tp_release_state'] = 'R544';
|
||||
$bb_cfg['tp_release_state'] = 'R545';
|
||||
|
||||
// Database
|
||||
$charset = 'utf8';
|
||||
|
@ -306,9 +306,19 @@ $bb_cfg['new_user_reg_restricted'] = false;
|
|||
|
||||
// Email
|
||||
$bb_cfg['emailer_disabled'] = false;
|
||||
|
||||
$bb_cfg['smtp_host'] = '';
|
||||
$bb_cfg['smtp_password'] = '';
|
||||
$bb_cfg['smtp_username'] = '';
|
||||
|
||||
$bb_cfg['board_email'] = 'admin@' . $domain_name;
|
||||
$bb_cfg['board_email_sig'] = '';
|
||||
$bb_cfg['sitename'] = $domain_name;
|
||||
|
||||
$bb_cfg['topic_notify_enabled'] = true;
|
||||
$bb_cfg['pm_notify_enabled'] = true;
|
||||
$bb_cfg['groupcp_send_email'] = true;
|
||||
$bb_cfg['email_change_disabled'] = false; // disable changing email by user
|
||||
|
||||
$bb_cfg['tech_admin_email'] = 'admin@' . $domain_name; // email for sending error reports
|
||||
$bb_cfg['abuse_email'] = 'abuse@' . $domain_name;
|
||||
|
|
|
@ -9,60 +9,80 @@ class emailer
|
|||
var $use_smtp;
|
||||
|
||||
var $tpl_msg = array();
|
||||
var $vars = array();
|
||||
|
||||
function emailer($use_smtp)
|
||||
function emailer ($use_smtp/*$tpl_name, $sbj, $to_address*/)
|
||||
{
|
||||
global $bb_cfg;
|
||||
|
||||
$this->reset();
|
||||
$this->use_smtp = $use_smtp;
|
||||
$this->reply_to = $this->from = '';
|
||||
$this->from = $bb_cfg['board_email'];
|
||||
$this->reply_to = $bb_cfg['board_email'];
|
||||
$this->use_smtp = $use_smtp; /*!empty($bb_cfg['smtp_host']);
|
||||
|
||||
$this->use_template($tpl_name);
|
||||
$this->set_subject($sbj);
|
||||
$this->email_address($to_address);*/
|
||||
}
|
||||
|
||||
function set_default_vars ()
|
||||
{
|
||||
global $bb_cfg;
|
||||
|
||||
$this->vars = array(
|
||||
'SITENAME' => $bb_cfg['sitename'],
|
||||
'BOARD_EMAIL' => $bb_cfg['board_email'],
|
||||
'EMAIL_SIG' => !empty($bb_cfg['board_email_sig']) ? "-- \n{$bb_cfg['board_email_sig']}" : '',
|
||||
);
|
||||
}
|
||||
|
||||
// Resets all the data (address, template file, etc etc to default
|
||||
function reset()
|
||||
function reset ()
|
||||
{
|
||||
$this->addresses = array();
|
||||
$this->vars = $this->msg = $this->extra_headers = '';
|
||||
$this->msg = $this->extra_headers = '';
|
||||
$this->set_default_vars();
|
||||
}
|
||||
|
||||
// Sets an email address to send to
|
||||
function email_address($address)
|
||||
function email_address ($address)
|
||||
{
|
||||
$this->addresses['to'] = trim($address);
|
||||
}
|
||||
|
||||
function cc($address)
|
||||
function cc ($address)
|
||||
{
|
||||
$this->addresses['cc'][] = trim($address);
|
||||
}
|
||||
|
||||
function bcc($address)
|
||||
function bcc ($address)
|
||||
{
|
||||
$this->addresses['bcc'][] = trim($address);
|
||||
}
|
||||
|
||||
function replyto($address)
|
||||
function replyto ($address)
|
||||
{
|
||||
$this->reply_to = trim($address);
|
||||
}
|
||||
|
||||
function from($address)
|
||||
function from ($address)
|
||||
{
|
||||
$this->from = trim($address);
|
||||
}
|
||||
|
||||
// set up subject for mail
|
||||
function set_subject($subject = '')
|
||||
function set_subject ($subject = '')
|
||||
{
|
||||
$this->subject = trim(preg_replace('#[\n\r]+#s', '', $subject));
|
||||
}
|
||||
|
||||
// set up extra mail headers
|
||||
function extra_headers($headers)
|
||||
function extra_headers ($headers)
|
||||
{
|
||||
$this->extra_headers .= trim($headers) . "\n";
|
||||
}
|
||||
|
||||
function use_template($template_file, $template_lang = '')
|
||||
function use_template ($template_file, $template_lang = '')
|
||||
{
|
||||
global $bb_cfg;
|
||||
|
||||
|
@ -105,13 +125,13 @@ class emailer
|
|||
}
|
||||
|
||||
// assign variables
|
||||
function assign_vars($vars)
|
||||
function assign_vars ($vars)
|
||||
{
|
||||
$this->vars = (empty($this->vars)) ? $vars : $this->vars . $vars;
|
||||
$this->vars = array_merge($this->vars, $vars);
|
||||
}
|
||||
|
||||
// Send the mail out to the recipients set previously in var $this->address
|
||||
function send()
|
||||
function send ()
|
||||
{
|
||||
global $bb_cfg, $lang;
|
||||
|
||||
|
@ -120,7 +140,7 @@ class emailer
|
|||
return;
|
||||
}
|
||||
|
||||
// Escape all quotes, else the eval will fail.
|
||||
// Escape all quotes
|
||||
$this->msg = str_replace ("'", "\'", $this->msg);
|
||||
$this->msg = preg_replace('#\{([a-z0-9\-_]*?)\}#is', "' . $\\1 . '", $this->msg);
|
||||
|
||||
|
@ -178,10 +198,10 @@ class emailer
|
|||
// Build header
|
||||
$this->extra_headers = (($this->reply_to != '') ? "Reply-to: $this->reply_to\n" : '') . (($this->from != '') ? "From: $this->from\n" : "From: " . $bb_cfg['board_email'] . "\n") . "Return-Path: " . $bb_cfg['board_email'] . "\nMessage-ID: <" . md5(uniqid(TIMENOW)) . "@" . $bb_cfg['server_name'] . ">\nMIME-Version: 1.0\nContent-type: text/plain; charset=" . $this->encoding . "\nContent-transfer-encoding: 8bit\nDate: " . date('r', TIMENOW) . "\nX-Priority: 0\nX-MSMail-Priority: Normal\nX-Mailer: Microsoft Office Outlook, Build 11.0.5510\nX-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441\nX-Sender: " . $bb_cfg['board_email'] . "\n" . $this->extra_headers . (($cc != '') ? "Cc: $cc\n" : '') . (($bcc != '') ? "Bcc: $bcc\n" : '');
|
||||
|
||||
// Send message ... removed $this->encode() from subject for time being
|
||||
if ( $this->use_smtp )
|
||||
// Send message
|
||||
if ($this->use_smtp)
|
||||
{
|
||||
if ( !defined('SMTP_INCLUDED') )
|
||||
if (!defined('SMTP_INCLUDED'))
|
||||
{
|
||||
include(INC_DIR .'smtp.php');
|
||||
}
|
||||
|
@ -190,20 +210,9 @@ class emailer
|
|||
}
|
||||
else
|
||||
{
|
||||
$empty_to_header = ($to == '') ? TRUE : FALSE;
|
||||
$to = ($to == '') ? (($bb_cfg['sendmail_fix']) ? ' ' : 'Undisclosed-recipients:;') : $to;
|
||||
$to = ($to == '') ? ' ' : $to;
|
||||
|
||||
$result = @mail($to, $this->subject, preg_replace("#(?<!\r)\n#s", "\n", $this->msg), $this->extra_headers);
|
||||
|
||||
if (!$result && !$bb_cfg['sendmail_fix'] && $empty_to_header)
|
||||
{
|
||||
$to = ' ';
|
||||
|
||||
bb_update_config(array('sendmail_fix' => 1));
|
||||
|
||||
$bb_cfg['sendmail_fix'] = 1;
|
||||
$result = @mail($to, $this->subject, preg_replace("#(?<!\r)\n#s", "\n", $this->msg), $this->extra_headers);
|
||||
}
|
||||
}
|
||||
|
||||
// Did it work?
|
||||
|
@ -215,11 +224,7 @@ class emailer
|
|||
return true;
|
||||
}
|
||||
|
||||
// Encodes the given string for proper display for this encoding ... nabbed
|
||||
// from php.net and modified. There is an alternative encoding method which
|
||||
// may produce lesd output but it's questionable as to its worth in this
|
||||
// scenario IMO
|
||||
function encode($str)
|
||||
function encode ($str)
|
||||
{
|
||||
if ($this->encoding == '')
|
||||
{
|
||||
|
@ -235,110 +240,4 @@ class emailer
|
|||
|
||||
return $start . $str . $end;
|
||||
}
|
||||
|
||||
//
|
||||
// Attach files via MIME.
|
||||
//
|
||||
function attachFile($filename, $mimetype = "application/octet-stream", $szFromAddress, $szFilenameToDisplay)
|
||||
{
|
||||
global $lang;
|
||||
$mime_boundary = "--==================_846811060==_";
|
||||
|
||||
$this->msg = '--' . $mime_boundary . "\nContent-Type: text/plain;\n\tcharset=\"" . $lang['CONTENT_ENCODING'] . "\"\n\n" . $this->msg;
|
||||
|
||||
if ($mime_filename)
|
||||
{
|
||||
$filename = $mime_filename;
|
||||
$encoded = $this->encode_file($filename);
|
||||
}
|
||||
|
||||
$fd = fopen($filename, "r");
|
||||
$contents = fread($fd, filesize($filename));
|
||||
|
||||
$this->mimeOut = "--" . $mime_boundary . "\n";
|
||||
$this->mimeOut .= "Content-Type: " . $mimetype . ";\n\tname=\"$szFilenameToDisplay\"\n";
|
||||
$this->mimeOut .= "Content-Transfer-Encoding: quoted-printable\n";
|
||||
$this->mimeOut .= "Content-Disposition: attachment;\n\tfilename=\"$szFilenameToDisplay\"\n\n";
|
||||
|
||||
if ( $mimetype == "message/rfc822" )
|
||||
{
|
||||
$this->mimeOut .= "From: ".$szFromAddress."\n";
|
||||
$this->mimeOut .= "To: ".$this->emailAddress."\n";
|
||||
$this->mimeOut .= "Date: ".date("D, d M Y H:i:s") . " UT\n";
|
||||
$this->mimeOut .= "Reply-To:".$szFromAddress."\n";
|
||||
$this->mimeOut .= "Subject: ".$this->mailSubject."\n";
|
||||
// $this->mimeOut .= "X-Mailer: PHP/".phpversion()."\n";
|
||||
$this->mimeOut .= "X-Priority: 0\n";
|
||||
$this->mimeOut .= "X-Mailer: Microsoft Office Outlook, Build 11.0.5510\n";
|
||||
$this->mimeOut .= "X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441\n";
|
||||
$this->mimeOut .= "X-Sender: " . $bb_cfg['board_email'] . " \n";
|
||||
$this->mimeOut .= "MIME-Version: 1.0\n";
|
||||
}
|
||||
|
||||
$this->mimeOut .= $contents."\n";
|
||||
$this->mimeOut .= "--" . $mime_boundary . "--" . "\n";
|
||||
|
||||
return $out;
|
||||
// added -- to notify email client attachment is done
|
||||
}
|
||||
|
||||
function getMimeHeaders($filename, $mime_filename="")
|
||||
{
|
||||
$mime_boundary = "--==================_846811060==_";
|
||||
|
||||
if ($mime_filename)
|
||||
{
|
||||
$filename = $mime_filename;
|
||||
}
|
||||
|
||||
$out = "MIME-Version: 1.0\n";
|
||||
$out .= "Content-Type: multipart/mixed;\n\tboundary=\"$mime_boundary\"\n\n";
|
||||
$out .= "This message is in MIME format. Since your mail reader does not understand\n";
|
||||
$out .= "this format, some or all of this message may not be legible.";
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
//
|
||||
// Split string by RFC 2045 semantics (76 chars per line, end with \r\n).
|
||||
//
|
||||
function myChunkSplit($str)
|
||||
{
|
||||
$stmp = $str;
|
||||
$len = strlen($stmp);
|
||||
$out = "";
|
||||
|
||||
while ($len > 0)
|
||||
{
|
||||
if ($len >= 76)
|
||||
{
|
||||
$out .= substr($stmp, 0, 76) . "\r\n";
|
||||
$stmp = substr($stmp, 76);
|
||||
$len = $len - 76;
|
||||
}
|
||||
else
|
||||
{
|
||||
$out .= $stmp . "\r\n";
|
||||
$stmp = "";
|
||||
$len = 0;
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
//
|
||||
// Split the specified file up into a string and return it
|
||||
//
|
||||
function encode_file($sourcefile)
|
||||
{
|
||||
if (is_readable(phpbb_realpath($sourcefile)))
|
||||
{
|
||||
$fd = fopen($sourcefile, "r");
|
||||
$contents = fread($fd, filesize($sourcefile));
|
||||
$encoded = $this->myChunkSplit(base64_encode($contents));
|
||||
fclose($fd);
|
||||
}
|
||||
|
||||
return $encoded;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue