📄 functions.php
字号:
<?php
// +-------------------------------------------------------------+
// | DeskPRO v [2.0.1 Production]
// | Copyright (C) 2001 - 2004 Headstart Solutions Limited
// | Supplied by WTN-WDYL
// | Nullified by WTN-WDYL
// | Distribution via WebForum, ForumRU and associated file dumps
// +-------------------------------------------------------------+
// | DESKPRO IS NOT FREE SOFTWARE
// +-------------------------------------------------------------+
// | License ID : Full Enterprise License =) ...
// | License Owner : WTN-WDYL Team
// +-------------------------------------------------------------+
// | $RCSfile: functions.php,v $
// | $Date: 2004/02/11 01:28:14 $
// | $Revision: 1.25 $
// +-------------------------------------------------------------+
// | File Details:
// | - process() provider for user-mailed e-mails.
// +-------------------------------------------------------------+
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);
/*****************************************************
function spam_check
-----DESCRIPTION: -----------------------------------
- Lets check for spam
*****************************************************/
function spam_check($subject, $themessage) {
global $db;
$db->query("SELECT * FROM gateway_spam");
while ($result = $db->row_array()) {
// relevant info to check
if (!$result[type]) {
$text = $subject;
} elseif ($result[type] == 1) {
$text = $themessage;
}
// regex check
if ($result['regex'] AND $result['textmatch']) {
if (preg_match($result[textmatch], $text)) {
if ($result['is_delete']) {
return 'delete';
} else {
return 'markspam';
}
}
}
// normal check
if (!$result[regex] AND $result['textmatch']) {
if (in_string($result[textmatch], $text)) {
if ($result['is_delete']) {
return 'delete';
} else {
return 'markspam';
}
}
}
}
return null;
}
/*****************************************************
function extra_email
-----DESCRIPTION: -----------------------------------
- Sends a warning email to the user
*****************************************************/
function extra_email($type, $user_details) {
global $ticket;
$user_details = update_user_details($user_details);
if ($type == 'license_expiry') {
eval(makeemaileval('message', 'TECHBODY_license_expired', $subject, $ticket));
$toemail = $settings['email_offemail'];
dp_mail($settings['email_offemail'], $subject, $message);
} else {
eval(makeemaileval('message', 'BODY_email_warning', $subject, $ticket));
dp_mail($user_details['email'], $subject, $message);
}
}
/*****************************************************
function get_pipe
-----DESCRIPTION: -----------------------------------
- Get data the is piped to script
*****************************************************/
function get_pipe() {
global $settings;
$fp = fopen('php://stdin', 'r');
while(!feof($fp) ){
$data .= fgets($fp, 4096);
$size += 4096;
if ($settings['max_message_size_pipe']) {
if ($size > $settings['max_message_size_pipe']) {
fclose($fp);
log_error('message_too_big');
exit;
}
}
}
fclose($fp);
return $data;
}
/*****************************************************
function log_pop_error
-----DESCRIPTION: -----------------------------------
- Logs any POP3 errors
*****************************************************/
function log_pop_error($error) {
global $pop, $db;
$error = $pop->serverinfo['server'] . ' (' . $pop->serverinfo['username'] . ') error: ' . $error;
$db->query("
INSERT INTO gateway_pop_failures SET
messageid = '" . addslashes($messageid) . "',
reason = '". addslashes($error) . "',
stamp = '" . mktime() . "'
");
$pop->close();
}
/*****************************************************
function store_mail
-----DESCRIPTION: -----------------------------------
- Store mail in gateway_source table
*****************************************************/
function store_mail($headers, $source) {
global $db, $settings;
$db->query("
INSERT INTO gateway_source SET
source = '" . mysql_escape_string($source) . "',
headers = '" . mysql_escape_string(serialize($headers)) . "'
");
return $db->last_id();
}
/*****************************************************
function process_attachments
-----DESCRIPTION: -----------------------------------
- Deal with attachments
*****************************************************/
function process_attachments($attachments, $embedded, $ticketid='', $userid='') {
global $user_fields, $ticket, $db;
$attachments = array_merge($attachments, $embedded);
if (is_array($attachments)) {
foreach ($attachments AS $key => $attach) {
$db->query("INSERT INTO blobs SET
blobdata = '" . mysql_escape_string($attach[data]) . "'
");
$blobid = $db->last_id();
$db->query("INSERT INTO ticket_attachments SET
filename = '" . mysql_escape_string($attach[filename]) . "',
filesize = '" . strlen($attach[data]) . "',
extension = '" . mysql_escape_string($attach[extension]) . "',
userid = '$userid',
timestamp = '" . mktime() . "',
ticketid = '$ticketid',
blobid = '$blobid'
");
$id = $db->last_id();
// build array to send to techs
$attachment_array[] = array(
'name' => $attach[filename],
'id' => $id,
'filesize' => strlen($attach[data]),
'extension' => $attach[extension],
'data' => $attach[data]
);
}
}
return $attachment_array;
}
###################### FUNCTION find_email) #######################
/*
Finds the from email, email is passed by reference for performance reasons
*/
function find_email(&$email) {
$lines = explode("\n", $email);
for ($i=0; $i<count($lines); $i++) {
if (preg_match("/^From: (.*)/", $lines[$i], $matches)) {
return $matches[1];
}
}
}
###################### FUNCTION log_error() #######################
function log_error($error, &$message) {
global $user, $ticketid, $sourceid, $db, $gateway, $settings, $new, $for_error;
$email = trim(strtolower($message->fromEmail));
$user_details = $user;
$user_details['email'] = $email;
/*
- Logs errors
- Reports certain errors to tech/admin to follow up
- Sends email to user in some situations to inform them of the error
- Sends the email from the email address they used (sales v support) if relevant (admin option)
- Sends emails to techs to explain error
- Sends emails to admin if there is a problem they need to fix straight away
*/
$db->query("INSERT INTO gateway_error SET
error = '" . mysql_escape_string($error) . "',
timestamp = '" . mktime() . "',
sourceid = '$sourceid'
");
// By default, we assume we're *not* sending mail. The cases below can change
// this. We also assume if we *are* sending mail, the amount of error mail we send
// is also limited per hour
$send_email = false;
$max_emails = $settings['max_error_emails'];
if ($error == 'no_gateway') {
dp_mail(
$settings[technical_email],
'IMPORTANT: DeskPRO Error',
'This is an automated DeskPRO error.
You currently have no gateway accounts setup but you have email being processed by DeskPRO. This email will not be processed until you have created a gateway account. Instructions on doing this can be found in the admin manual found inside the docs folder in your distribution'
);
}
switch ($error) {
case 'no_email':
case 'self_email':
case 'invalid_email':
case 'banned_email':
case 'no_gateway':
case 'gateway_email':
case 'duplicate_subject':
case 'no_ticketref':
case 'duplicate_message':
case 'no_tech':
case 'spam':
case 'no_user':
case 'x-loop':
// In these cases, we don't send any mail at all; either the mail is
// spam, a forgery, or the administrator hasn't configured the mail
// gateway yet. We don't have to actually do anything here except
// to catch these cases so we don't send mail.
$send_email = false;
break;
case 'no_message':
// The message was empty.
$email_template = 'BODY_error_new';
$error_empty = 1;
$send_email = true;
break;
case 'ticket_closed':
// The ticket is closed.
$email_template = 'BODY_error_reply';
$error_closed = 1;
$send_email = true;
break;
case 'bad_auth':
// The ticket is closed.
$email_template = 'BODY_error_reply';
$error_auth = 1;
$send_email = true;
break;
case 'user_expired':
// The ticket is closed.
$email_template = 'BODY_error_new';
$error_expired = 1;
$send_email = true;
break;
case 'new_user_limit':
// Don't create any more tickes for this user. Probably autoresponding
$send_email = false;
break;
case 'unregistered':
// The sender's address isn't recognized and the admin has configured
// DeskPro to require registration before submitting new tickets.
$email_template = 'BODY_error_new';
$error_unregistered = 1;
$send_email = true;
break;
case 'autoresponds_reply':
case 'autoresponder_reply':
// The user has an autoresponder; if we keep sending mail, it'll just
// keep getting bounced back to us.
$db->query("UPDATE user SET autoresponds = 1 WHERE id = '$user[id]'");
$send_email = false;
break;
case 'message_too_big':
// message is too big (probably large attachments)
$email_template = 'BODY_error_new';
$send_email = true;
$error_message_too_big = 1;
break;
case 'attachment_too_big':
// One or more attachments were too long.
if ($new == true) {
$email_template = 'BODY_error_new';
} else {
$email_template = 'BODY_error_reply';
}
$send_email = true;
$error_attachment_too_big = 1;
break;
case 'license_no_new_tickets':
// The license prohibits more tickets
$send_email = false;
extra_email('license_expiry', $user);
break;
}
if (defined('RETURNPOP')) {
// We *NEVER* respond to bounces.
$send_email = 0;
}
if ($send_email) {
if (!defined('USERZONE')) {
$email_template = 'TECHBODY_error_reply';
}
// Just a sanity check
if (!$max_emails) {
$max_emails = 5;
}
// First we check whether we've already sent as many mails this hour to this
// user as we're allowed.
$day_time = time() - (60 * 60);
$result = $db->query_return("
SELECT COUNT(*) AS total
FROM gateway_auto
WHERE email = '" . mysql_escape_string($email) . "'
AND type = '$error'
AND timestamp > $day_time
");
// send email if necessary
if ($result['total'] < $max_emails) {
$db->query("
INSERT INTO gateway_auto SET
email = '" . mysql_escape_string($email) . "',
type = '$type',
timestamp = " . mktime() . "
");
$user_details = update_user_details($user_details);
eval(makeemaileval('body', $email_template, $subject));
dp_mail($email, $subject, $body);
}
}
return false;
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -