techmail.php
上传用户:gzy2002
上传日期:2010-02-11
资源大小:1785k
文件大小:4k
- #!/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: techmail.php,v $
- // | $Date: 2004/02/10 01:34:25 $
- // | $Revision: 1.6 $
- // +-------------------------------------------------------------+
- // | File Details:
- // | - process() dp1 style management of emails
- // +-------------------------------------------------------------+
- error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);
- //////////////////// PART 1 INCLUDES ////////////////////
- define('USERZONE', 1);
- define('TECHMAILPOP', 1);
- include("mail_config.php");
- include("mail.php");
- ###################### FUNCTION PROCESS() #######################
- /*
- Deals with incoming user email for new ticket and reply creation
- $message: the email after it has been decoded (array of elements)
- $source : the source of the email
- $gateway: array containing gateway information (for POP3); if not
- provided, we try to figure it out ourselves here.
- */
- function process($message, $source, $gateway = NULL) {
-
- global $db, $settings, $template_cache, $output, $sourceid, $user;
- // rename a few variables for ease of access
- $email['from'] = trim(strtolower($message->fromEmail));
- $headers = $message->headers;
- $subject = $headers['subject'];
- //////////////////////////////////////////////////////////////
- /* 1. STANDARD PROCESSING INDEPENDANT OF REPLY / NEW TICKET */
- //////////////////////////////////////////////////////////////
- // insert the full email
- $sourceid = store_mail($headers, $source);
- if (in_string('DeskPRO', $headers['X-Mailer'])) {
- return true;
- }
- // no valid return email (decoding functions look at various mail headers)
- if (!$email['from']) {
- return true;
- }
- // the from email is invalid
- if (!(validate_email($email['from']))) {
- return true;
- }
- // Handle e-mail bans. First, if this sender is banned, reject it.
- if (banned_email($email['from'])) {
- 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]) == $email['from']) {
- return true;
- }
- //////////////////// PART 4 EMAIL PARSEING ////////////////////
- // get subject bits
- if (ereg("[([0-9]{1,})--(.{1,})]", $subject, $arr)) {
- $email_id = $arr[1];
- $email_code = $arr[2];
- }
- $parent_email = $db->query_return("
- SELECT *
- FROM tech_sendmail
- WHERE id = '$email_id'
- AND parent = '0'
- AND pass = '$email_code'
- ");
- if ($db->num_rows() < 1) {
- $stop = 1;
- $error_match = 1;
- }
- // get from email
- if (eregi("([-.a-z0-9_]+@[-.a-z0-9_)]*)", $email['from'], $arr)) {
- $from_email = $arr[1];
- } else {
- $no = 1;
- }
- // use text version of body if we have it, otherwise use html version.
- if (trim($message->text) != '') {
- $body = $message->text;
- } elseif (trim($message->html != '')) {
- $body = strip_tags($message->html);
- }
- // select part of body we want
- $end = strpos($body, "=== ENTER RESPONSE");
- if (($end === false) OR (is_string($post && !$post))) {
- $post = $body;
- } else {
- $post = substr($body, 0, ($end - 3));
- }
- //////////////////// PART 6 ADD REPLY TO DATABASE ////////////////////
- // add the new email to database
- $db->query("
- INSERT into tech_sendmail SET
- date_sent = '" . mktime() . "',
- message = '" . addslashes($body) . "',
- subject = '" . addslashes($subject) . "',
- parent = '" . addslashes($parent_email[id]) . "',
- from_email = '" . addslashes($from_email) . "'
- ");
- //////////////////// PART 7 UPDATE EMAIL ////////////////////
- $db->query("
- UPDATE tech_sendmail SET
- awaiting_reply = '1'
- WHERE id = '$parent_email[id]'
- ");
- }
- ?>