load_funcs('files/model/_file.funcs.php'); } if (!($mbox = dre_connect(true))) { // We couldn't connect to the mail server return 2; // error } // Read messages from server dre_msg(T_('Reading messages from server'), true); $imap_obj = imap_check($mbox); dre_msg(sprintf(T_('Found %d messages'), intval($imap_obj->Nmsgs)), true); if ($imap_obj->Nmsgs == 0) { dre_msg(T_('There are no messages in the mailbox'), true); imap_close($mbox); return 1; // success } // Create posts dre_process_messages($mbox, $imap_obj->Nmsgs, true); if (count($del_cntr) > 0) { // We want to delete processed emails from server imap_expunge($mbox); dre_msg(sprintf(T_('Deleted %d processed message(s) from inbox.'), $del_cntr), true); } imap_close($mbox); // Show reports if ($email_cntr > 0) { dre_msg(sprintf(T_('New emails saved: %d'), $email_cntr), true); } return 1; // success
/** * Process Header information like subject and date of a mail. * * @param array $header header as set by mime_parser_class::Analyze() * @param string message subject by reference * @param string message date by reference * @param boolean TRUE if script is executed by cron * @return bool true if valid subject prefix is detected */ function dre_process_header($header, &$subject, &$post_date, $cron = false) { global $Settings; $subject = $header['Subject']; $ddate = $header['Date']; dre_msg(T_('Subject') . ': ' . $subject, $cron); // Check subject to match in titles to identify return path emails $subject_is_correct = false; $repath_subjects = explode("\n", str_replace(array('\\r\\n', '\\n\\n'), '\\n', $Settings->get('repath_subject'))); foreach ($repath_subjects as $repath_subject) { if (strpos($subject, $repath_subject) !== false) { $subject_is_correct = true; break; } } if (!$subject_is_correct) { // Subject is not match to identify return email dre_msg(sprintf(T_('Subject prefix is not %s, skip this email'), '"' . implode('", "', $repath_subjects) . '"'), $cron); return false; } // Parse Date if (!preg_match('#^(.{3}, )?(\\d{2}) (.{3}) (\\d{4}) (\\d{2}):(\\d{2}):(\\d{2})#', $ddate, $match)) { $ddate_U = @strtotime($ddate); if (empty($ddate_U) || strlen($ddate_U) < 2) { dre_msg(sprintf(T_('Could not parse date header "%s"'), $ddate), $cron); return false; } } if (empty($ddate_U)) { $dmonths = array('Jan' => 1, 'Feb' => 2, 'Mar' => 3, 'Apr' => 4, 'May' => 5, 'Jun' => 6, 'Jul' => 7, 'Aug' => 8, 'Sep' => 9, 'Oct' => 10, 'Nov' => 11, 'Dec' => 12); $ddate_H = $match[5]; $ddate_i = $match[6]; $ddate_s = $match[7]; if (!isset($dmonths[$match[3]])) { dre_msg(T_('Invalid month name in message date string.'), $cron); return false; } $ddate_m = $dmonths[$match[3]]; $ddate_d = $match[2]; $ddate_Y = $match[4]; $ddate_U = mktime($ddate_H, $ddate_i, $ddate_s, $ddate_m, $ddate_d, $ddate_Y); } $post_date = date('Y-m-d H:i:s', $ddate_U); return true; }
if ($mbox = dre_connect()) { // Close opened connection imap_close($mbox); } break; case 'test_2': if ($mbox = dre_connect()) { // Read messages from server dre_msg('Reading messages from server'); $imap_obj = imap_check($mbox); dre_msg('Found ' . $imap_obj->Nmsgs . ' messages'); if ($imap_obj->Nmsgs > 0) { // We will read only 1 message from server in test mode dre_process_messages($mbox, 1); } else { dre_msg(T_('There are no messages in the mailbox')); } imap_close($mbox); } break; case 'test_3': param('test_error_message', 'raw', ''); if (!empty($test_error_message)) { // Simulate a message processing dre_simulate_message($test_error_message); $repath_test_output = implode("<br />\n", $dre_messages); } break; } $Messages->clear(); // Clear all messages
/** * Prepare html message * * @param string Message * @return string Content */ function dre_prepare_html_message($message) { dre_msg('Message body (original): <pre style="font-size:10px">' . htmlspecialchars($message) . '</pre>'); $marker = 0; if (preg_match('~<body[^>]*>(.*?)</body>~is', $message, $result)) { // First see if we can get contents of <body> tag $content = $result[1]; $marker = 1; } elseif (preg_match('~<html[^>]*>(.*?)</html>~is', $message, $result)) { // <body> was not found, use <html> contents and delete <head> section from it $content = preg_replace('~<head[^>]*>(.*?)</head>~is', '', $result[1]); $marker = 1; } if (empty($marker)) { // None of the above methods worked, just use the original message body $content = $message; } // First fix different line-endings (dos, mac, unix), remove double newlines $content = str_replace(array("\r", "\n\n"), "\n", trim($content)); // Decode 'category', 'title' and 'auth' tags $content = preg_replace('~<(/)?(category|title|auth)>~i', '<\\1\\2>', $content); // Balance tags $content = balance_tags($content); // Remove markup that cause validator errors $patterns = array('~ moz-do-not-send="true"~', '~ class="moz-signature" cols="\\d+"~', '~ goomoji="[^"]+"~'); $content = preg_replace($patterns, '', $content); pbm_msg('Message body (processed): <pre style="font-size:10px">' . htmlspecialchars($content) . '</pre>'); return $content; }