cannon7 Posted September 6, 2003 Posted September 6, 2003 allows people who don't have access to their mail alias config files or the ability to excute functions from their mail aliases to still be able to use it? I am thinking something like this: 1) Script logs into pop3/imap server 2) Checks and parses e-mail messages 3) Inserts messages into database 4) Deletes e-mail messages 5) Closes pop3/imap connection Then one could run this script on a cron job every 10 minutes or so. I don't think this would be too difficult, but alas, my programming skills are not up to par (I've tried, without success). Here's the original osc_mail2db.php file, designed to be executed by procmail or qmail via an alias file. And just in case you don't know, this is from the "Help Desk" contribution: <?php /* $Id: $ osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright (c) 2002 osCommerce Released under the GNU General Public License */ function osc_create_random_string() { $ascii_from = 50; // 2 $ascii_to = 90; // Z // exclude some characters $exclude = array(58, 59, 60, 61, 62, 63, 64, 73, 79); mt_srand((double)microtime() * 1000000); $string = ''; $i = 0; while ($i < 7) { // random ASCII decimal within limits $randnum = mt_rand($ascii_from, $ascii_to); if (!in_array($randnum, $exclude)) { $string .= chr($randnum); $i++; } } return $string; } function osc_parse_mime_decode_output(&$obj, &$parts){ if (!empty($obj->parts)) { for ($i=0; $i<count($obj->parts); $i++) { osc_parse_mime_decode_output($obj->parts[$i], $parts); } } else { $ctype = $obj->ctype_primary.'/'.$obj->ctype_secondary; switch ($ctype) { case 'text/plain': if (!empty($obj->disposition) AND $obj->disposition == 'attachment') { $parts['attachments'][] = $obj->body; } else { $parts['text'][] = $obj->body; } break; case 'text/html': if (!empty($obj->disposition) AND $obj->disposition == 'attachment') { $parts['attachments'][] = $obj->body; } else { $parts['html'][] = $obj->body; } break; default: $parts['attachments'][] = $obj->body; } } } $config_file = false; // read arguments for ($i=0; $i<sizeof($argv); $i++) { if (substr($argv[$i], 0, 7) == 'config=') { $config_file_parameter = explode('=', $argv[$i]); if (strlen(trim($config_file_parameter[1])) > 0) { $config_file = trim($config_file_parameter[1]); } } } if ($config_file == false) { echo "n" . 'osCommerce 2.2 Mail2Database Script' . "n" . 'Copyright (c) 2002 osCommerce' . "nn" . 'Release under the GNU General Public License' . "nn" . 'Usage: osc_mail2db.php config=<path to config file>' . "nn" . 'The config file parameter is used to retrieve the database' . "n" . 'connection parameters.' . "nn" . 'Example /etc/mail/aliases entry:' . "nn" . 'helpdesk: "| /usr/bin/php -q /home/site/scripts/osc_mail2db.php config=/home/site/osCommerce/includes/configure.php"' . "nn"; exit; } include($config_file); include(DIR_FS_ADMIN . 'includes/classes/mime_decode.php'); $link = mysql_connect(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD) or die('Could not connect to server.'); mysql_select_db(DB_DATABASE) or die('Count not select database.'); $store_query = mysql_query("select configuration_key, configuration_value from configuration where configuration_key in ('STORE_OWNER', 'STORE_OWNER_EMAIL_ADDRESS', 'DEFAULT_HELPDESK_STATUS_ID', 'DEFAULT_HELPDESK_PRIORITY_ID', 'DEFAULT_HELPDESK_DEPARTMENT_ID')", $link); while ($store = mysql_fetch_array($store_query)) { define($store['configuration_key'], $store['configuration_value']); } if (phpversion() > 4) { $contents = file('php://stdin'); } else { $contents = file('/dev/stdin'); } if (sizeof($contents) < 1) { $error = "n" . 'An error has occured with osc_mail2db.' . "nn" . 'The command used was:' . "nn" . implode(' ', $argv) . "nn"; mail(STORE_OWNER_EMAIL_ADDRESS, "[osC Mail2Database] Error", $error, 'From: ' . STORE_OWNER_EMAIL_ADDRESS); exit; } reset($contents); $contents = implode ('', $contents); $params = array('input' => $contents, 'crlf' => "rn", 'include_bodies' => TRUE, 'decode_headers' => TRUE, 'decode_bodies' => TRUE); $output = Mail_mimeDecode::decode($params); $parts = array(); osc_parse_mime_decode_output($output, $parts); $field_body = ''; if (isset($parts['text'][0])) { $field_body = trim($parts['text'][0]); } elseif (isset($parts['html'][0])) { $field_body = trim(strip_tags($parts['html'][0])); } $output->headers['date'] = trim($output->headers['date']); if (empty($output->headers['date'])) { $field_date = date("Y-m-d H:i:s"); } else { $field_date = date("Y-m-d H:i:s", strtotime($output->headers['date'], time())); } $output->headers['received'] = trim($output->headers['received']); if (ereg('([0-9]+.[0-9]+.[0-9]+.[0-9]+)', $output->headers['received'], $regs)) { $field_ip = $regs[1]; } else { $field_ip = ''; } $field_host = @gethostbyaddr($field_ip); $output->headers['from'] = trim($output->headers['from']); if (empty($output->headers['from'])) { $field_from = ''; $field_from_email_address = ''; } else { if (ereg('"([^"]+)" <([^>]+)>', $output->headers['from'], $regs)) { $field_from = trim($regs[1]); $field_from_email_address = trim($regs[2]); } elseif (ereg('([^<]+)<([^>]+)>', $output->headers['from'], $regs)) { $field_from = trim($regs[1]); $field_from_email_address = trim($regs[2]); } elseif (substr($output->headers['from'], 0, 1) == '<') { $field_from = substr($output->headers['from'], 1, -1); $field_from_email_address = $field_from; } else { $field_from = $output->headers['from']; $field_from_email_address = $field_from; } } $output->headers['to'] = trim($output->headers['to']); if (empty($output->headers['to'])) { $field_to = ''; $field_to_email_address = ''; } else { if (ereg('"([^"]+)" <([^>]+)>', $output->headers['to'], $regs)) { $field_to = trim($regs[1]); $field_to_email_address = trim($regs[2]); } elseif (ereg('([^<]+)<([^>]+)>', $output->headers['to'], $regs)) { $field_to = trim($regs[1]); $field_to_email_address = trim($regs[2]); } elseif (substr($output->headers['to'], 0, 1) == '<') { $field_to = substr($output->headers['to'], 1, -1); $field_to_email_address = $field_to; } else { $field_to = $output->headers['to']; $field_to_email_address = $field_to; } } $field_message_id = trim($output->headers['message-id']); $ticket = false; $parent_id = '0'; $status_id = DEFAULT_HELPDESK_STATUS_ID; $priority_id = DEFAULT_HELPDESK_PRIORITY_ID; $department_id = DEFAULT_HELPDESK_DEPARTMENT_ID; $departments_query = mysql_query("select department_id from helpdesk_departments where email_address = '" . addslashes($field_to_email_address) . "'", $link); if (mysql_num_rows($departments_query)) { $departments = mysql_fetch_array($departments_query); $department_id = $departments['department_id']; } $field_subject = trim($output->headers['subject']); if (ereg('^.*[osC:([A-Z0-9]{7})].*$', $field_subject, $regs)) { $ticket = $regs[1]; $ticket_info_query = mysql_query("select he.parent_id, ht.department_id, ht.status_id, ht.priority_id from helpdesk_entries he left join helpdesk_tickets ht on (he.ticket = ht.ticket) where he.ticket = '" . $ticket . "' order by he.parent_id desc limit 1", $link); if (mysql_num_rows($ticket_info_query)) { $ticket_info = mysql_fetch_array($ticket_info_query); $parent_id = $ticket_info['parent_id']; $status_id = $ticket_info['status_id']; $priority_id = $ticket_info['priority_id']; $department_id = $ticket_info['department_id']; } } else { while (true) { $ticket = osc_create_random_string(); $check_query = mysql_query("select count(*) as count from helpdesk_tickets where ticket = '" . $ticket . "'", $link); $check = mysql_fetch_array($check_query); if ($check['count'] < 1) break; } } $check_query = mysql_query("select count(*) as count from helpdesk_tickets where ticket = '" . $ticket . "'", $link); $check = mysql_fetch_array($check_query); if ($check['count'] < 1) { mysql_query("insert into helpdesk_tickets (ticket, department_id, priority_id, status_id, datestamp_last_entry) values ('" . $ticket . "', '" . $department_id . "', '" . DEFAULT_HELPDESK_PRIORITY_ID . "', '" . DEFAULT_HELPDESK_STATUS_ID . "', now())", $link); } mysql_query("insert into helpdesk_entries (helpdesk_entries_id, ticket, parent_id, message_id, ip_address, host, datestamp_local, datestamp, receiver, receiver_email_address, sender, email_address, subject, body, entry_read) values ('', '" . $ticket . "', '" . $parent_id . "', '" . addslashes($field_message_id) . "', '" . addslashes($field_ip) . "', '" . addslashes($field_host) . "', now(), '" . addslashes($field_date) . "', '" . addslashes($field_to) . "', '" . addslashes($field_to_email_address) . "', '" . addslashes($field_from) . "', '" . addslashes($field_from_email_address) . "', '" . addslashes($field_subject) . "', '" . addslashes($field_body) . "', '0')", $link); mysql_close($link); ?> Hope someone can help me out! Thanks. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.