return.php
上传用户:gzy2002
上传日期:2010-02-11
资源大小:1785k
文件大小:5k
- #!/usr/bin/php -q
- <?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: return.php,v $
- // | $Date: 2004/02/11 20:32:13 $
- // | $Revision: 1.24 $
- // +-------------------------------------------------------------+
- // | File Details:
- // | - process() provider for returned (bounced) e-mails.
- // +-------------------------------------------------------------+
- error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);
- //////////////////// PART 1 INCLUDES ////////////////////
- define('RETURNPOP', 1);
- include("mail_config.php");
- include(INCLUDE_PATH . 'functions/admin-tech_functions.php');
- include("mail.php");
- ###################### FUNCTION PROCESS() #######################
- /* Deals with incoming bounce messages.
- $message: the email after it has been decoded (array of elements)
- $source : the source of the email
- $gateway: gateway info (optional)
-
- This is very simple; no errors are logged and such mails will be
- silently ignored.
- */
- function process(&$message, &$source, $gateway = NULL) {
- global $db, $settings, $template_cache, $output, $sourceid;
- // rename a few variables for ease of access
- $email['from'] = trim($message->fromEmail);
- $headers = $message->headers;
- $subject = $headers['subject'];
- //////////////////////////////////////////////////////////////
- /* 1. STANDARD PROCESSING */
- //////////////////////////////////////////////////////////////
- // no valid return email (decoding functions look at various mail headers)
- if (!$email['from']) {
- return true;
- }
- if (!(validate_email($email['from']))) {
- return true;
- }
- // we don't want to autorespond to another DeskPRO
- if (in_string('DeskPRO', $headers['X-Mailer'])) {
- return true;
- }
- // Handle e-mail bans. First, if this sender is banned, reject it.
- if (banned_email(strtolower($email['from']), $banned_emails)) {
- return true;
- }
- // Next, if the sender is ourselves, ignore the message (because that's
- // a common spam trick and we'll never be mailing ourselves anyway)
- if (strtolower($settings[email_from]) == strtolower($email['from'])) {
- return true;
- }
- // check for text
- if ($message->text) {
- $body = $message->text;
- } elseif ($message->html) {
- $body = strip_tags($message->html);
- $strip_tags = 1;
- } else {
- return true;
- }
- if (trim($body) == '') {
- return true;
- }
- /*
- Check to see if the email is a reply (check subject + footer)
- i) subject line AAAA-0000-AAAA
- ii) code at the bottom of the email
- <=== Ticket Ref AAAA-0000-AAAA ===>
- */
- // subject check
- if (ereg("[([0-9]{4}-[A-Za-z]{4}-[0-9]{4})]", $subject, $arr)) {
- $ticketref = $arr[1];
- // footer check
- } elseif (ereg("<=== ([0-9]{4}-[A-Za-z]{4}-[0-9]{4}) ===>", $body, $arr)) {
- $ticketref = $arr[1];
- } else {
- return true;
- }
- // Get ticket information and check if it is valid
- $ticket = $db->query_return("
- SELECT
- ticket.*, ticket_pri.id AS priority_id, ticket_pri.name AS priority_name,
- ticket_cat.id AS category_id, ticket_cat.name AS category_name,
- tech.id AS tech_id, tech.email AS tech_email
- FROM ticket
- LEFT JOIN ticket_pri ON (ticket.priority = ticket_pri.id)
- LEFT JOIN ticket_cat ON (ticket.category = ticket_cat.id)
- LEFT JOIN tech ON (ticket.tech = tech.id)
- WHERE ref = '$ticketref'
- ");
- if (!$db->num_rows()) {
- return true;
- }
- //////////////////////////////////////////////////////////////
- /* 4. PROCESS / ERROR CHECKING */
- //////////////////////////////////////////////////////////////
- /* check someone istn't just spamming the return-path email */
- // 1 hour
- $auto_time = mktime() - (3600 * 1);
- $result = $db->query_return(
- "SELECT COUNT(*) AS total FROM ticket_message
- WHERE ticketid = '$ticket[id]'
- AND date > $auto_time
- AND date > $ticket[date_lastreply_tech]
- ");
- // we have reached the max replies to tickets, generate error and stop processing
- if ($settings['max_reply']) {
- if ($result[total] > $settings['max_reply]']) {
- return true;
- }
- }
- //////////////////////////////////////////////////////////////
- /* 7. ADD REPLY TO TICKET */
- //////////////////////////////////////////////////////////////
- // insert the full email
- $sourceid = store_mail($headers, $source);
- $db->query("
- INSERT into ticket_message SET
- message = 'Mail returned; message follows:n" . mysql_escape_string($body) . "',
- ticketid = '$ticket[id]',
- striptags = '0',
- date = '" . mktime() . "',
- techid = '0',
- userid = '0'
- ");
- return true;
- }
- ?>