#!/usr/bin/php -q time() ) { $message = $hesk_settings['debug_mode'] ? $hesklang['pfr'] : ''; die($message); } else { // Start the process (force) file_put_contents($job_file, time() ); } } else { // No job in progress, log when this one started file_put_contents($job_file, time() ); } } // Get other required includes require(HESK_PATH . 'inc/pipe_functions.inc.php'); // Get POP3 class require(HESK_PATH . 'inc/mail/pop3.php'); // Uncomment when using SASL authentication mechanisms # require(HESK_PATH . 'inc/mail/sasl/sasl.php'); // If a pop3 wrapper is registered un register it, we need our custom wrapper if ( in_array('pop3', stream_get_wrappers() ) ) { stream_wrapper_unregister('pop3'); } // Register the pop3 stream handler class stream_wrapper_register('pop3', 'pop3_stream'); // Setup required variables $pop3 = new pop3_class; $pop3->hostname = $hesk_settings['pop3_host_name']; $pop3->port = $hesk_settings['pop3_host_port']; $pop3->tls = $hesk_settings['pop3_tls']; $pop3->debug = 0; $pop3->join_continuation_header_lines = 1; // Connect to POP3 if(($error=$pop3->Open())=="") { echo $hesk_settings['debug_mode'] ? "
Connected to the POP3 server "" . $pop3->hostname . "".\n" : ''; // Authenticate if(($error=$pop3->Login($hesk_settings['pop3_user'], hesk_htmlspecialchars_decode($hesk_settings['pop3_password'])))=="") { echo $hesk_settings['debug_mode'] ? "
User "" . $hesk_settings['pop3_user'] . "" logged in.\n" : ''; // Get number of messages and total size if(($error=$pop3->Statistics($messages,$size))=="") { echo $hesk_settings['debug_mode'] ? "
There are $messages messages in the mail box with a total of $size bytes.\n" : ''; // If we have any messages, process them if($messages>0) { // Connect to the database hesk_dbConnect(); for ($message = 1; $message <= $messages; $message++) { echo $hesk_settings['debug_mode'] ? "
Parsing message $message of $messages.\n" : ''; $pop3->GetConnectionName($connection_name); $message_file = 'pop3://'.$connection_name.'/'.$message; // Parse the incoming email $results = parser($message_file); // Convert email into a ticket (or new reply) if ( $id = hesk_email2ticket($results, 1, $set_category, $set_priority) ) { echo $hesk_settings['debug_mode'] ? "
Ticket $id created/updated.\n" : ''; } else { echo $hesk_settings['debug_mode'] ? "
Ticket NOT inserted - may be duplicate, blocked or an error.\n" : ''; } // Queue message to be deleted on connection close if ( ! $hesk_settings['pop3_keep']) { $pop3->DeleteMessage($message); } echo $hesk_settings['debug_mode'] ? "
Disconnected from the POP3 server "" . $pop3->hostname . "".\n" : ''; } } } } // Any error messages? if($error != '') { echo "