function fetch_mails() { global $wpdb; /* checks mail from various mailboxes and posts those e-mails */ //Load up some usefull libraries //Retreive emails $fetch_query = 'SELECT * FROM ' . $wpdb->prefix . 'postie_addresses'; $mailboxes = $wpdb->get_results($fetch_query); print_r($mailboxes); $config = get_config(); foreach ($mailboxes as $mailbox) { $emails = FetchMail($mailbox->server, $mailbox->port, $mailbox->email, $mailbox->passwd, $mailbox->protocol); //loop through messages foreach ($emails as $email) { //sanity check to see if there is any info in the message if ($email == NULL) { print 'Dang, message is empty!'; continue; } $mimeDecodedEmail = DecodeMimeMail($email); $from = RemoveExtraCharactersInEmailAddress(trim($mimeDecodedEmail->headers["from"])); //Check poster to see if a valid person $poster = ValidatePoster($mimeDecodedEmail, $config); if (!empty($poster)) { if ($config['TEST_EMAIL']) { DebugEmailOutput($email, $mimeDecodedEmail); } if ($mailbox->category) { $config['DEFAULT_POST_CATEGORY'] = $mailbox->category; } PostEmail($poster, $mimeDecodedEmail, $config); } else { print "<p>Ignoring email - not authorized.\n"; } } // end looping over messages } }
function postie_get_mail() { require_once plugin_dir_path(__FILE__) . 'mimedecode.php'; if (!function_exists('file_get_html')) { require_once plugin_dir_path(__FILE__) . 'simple_html_dom.php'; } EchoInfo("Starting mail fetch"); postie_environment(); $wp_content_path = dirname(dirname(dirname(__FILE__))); DebugEcho("wp_content_path: {$wp_content_path}"); if (file_exists($wp_content_path . DIRECTORY_SEPARATOR . "filterPostie.php")) { DebugEcho("found filterPostie.php in {$wp_content_path}"); include_once $wp_content_path . DIRECTORY_SEPARATOR . "filterPostie.php"; } if (has_filter('postie_post')) { echo "Postie: filter 'postie_post' is depricated in favor of 'postie_post_before'"; } $test_email = null; $config = config_Read(); //extract($config); if (!array_key_exists('maxemails', $config)) { $config['maxemails'] = 0; } $emails = FetchMail($config['mail_server'], $config['mail_server_port'], $config['mail_userid'], $config['mail_password'], $config['input_protocol'], $config['time_offset'], $test_email, $config['delete_mail_after_processing'], $config['maxemails'], $config['email_tls']); $message = 'Done.'; EchoInfo(sprintf(__("There are %d messages to process", "postie"), count($emails))); if (function_exists('memory_get_usage')) { DebugEcho(__("memory at start of email processing:") . memory_get_usage()); } DebugDump($config); //loop through messages $message_number = 0; foreach ($emails as $email) { $message_number++; DebugEcho("{$message_number}: ------------------------------------"); //sanity check to see if there is any info in the message if ($email == NULL) { $message = __('Dang, message is empty!', 'postie'); EchoInfo("{$message_number}: {$message}"); continue; } else { if ($email == 'already read') { $message = __("Message is already marked 'read'.", 'postie'); EchoInfo("{$message_number}: {$message}"); continue; } } $mimeDecodedEmail = DecodeMIMEMail($email); DebugEmailOutput($email, $mimeDecodedEmail); //Check poster to see if a valid person $poster = ValidatePoster($mimeDecodedEmail, $config); if (!empty($poster)) { PostEmail($poster, $mimeDecodedEmail, $config); } else { EchoInfo("Ignoring email - not authorized."); } flush(); } EchoInfo("Mail fetch complete, {$message_number} emails"); if (function_exists('memory_get_usage')) { DebugEcho("memory at end of email processing:" . memory_get_usage()); } }
} $message = ''; $mimeDecodedEmail = DecodeMimeMail($email, true); $from = RemoveExtraCharactersInEmailAddress(trim($mimeDecodedEmail->headers["from"])); /* if ($from != "") { continue; } */ //Check poster to see if a valid person $poster = ValidatePoster($mimeDecodedEmail, $config); if (!empty($poster)) { if ($config['TEST_EMAIL']) { DebugEmailOutput($email, $mimeDecodedEmail); } PostEmail($poster, $mimeDecodedEmail, $config); } else { print "<p>Ignoring email - not authorized.\n"; } if (function_exists('memory_get_usage')) { echo "memory at end of e-mail processing:" . memory_get_usage() . "\n"; } } // end looping over messages } else { $message = "\n" . __("There does not seem to be any new mail.", 'postie'); } print $message; print "</pre>\n"; /* END PROGRAM */ // end of script
TestWPMailInstallation(); //Retreive emails print "<pre>\n"; $emails = FetchMail(); //loop through messages foreach ($emails as $email) { //sanity check to see if there is any info in the message if ($email == NULL) { print 'Dang, message is empty!'; continue; } $mimeDecodedEmail = DecodeMimeMail($email); $from = RemoveExtraCharactersInEmailAddress(trim($mimeDecodedEmail->headers["from"])); /* if ($from != "") { continue; } */ //Check poster to see if a valid person $poster = ValidatePoster($mimeDecodedEmail); if (!empty($poster)) { DebugEmailOutput($email, $mimeDecodedEmail); PostEmail($poster, $mimeDecodedEmail); } else { print "<p>Ignoring email - not authorized.\n"; } } // end looping over messages print "</pre>\n"; /* END PROGRAM */ // end of script