/** * For batch sending (every tot mins) */ function alo_em_more_reccurences($schedules) { $schedules['alo_em_interval'] = array('interval' => 59 * ALO_EM_INTERVAL_MIN, 'display' => 'EasyMail every ' . ALO_EM_INTERVAL_MIN . ' minutes'); // Set bounce schedule only if some bounce options are set $bounce_settings = alo_em_bounce_settings(); $bounce_interval = (int) $bounce_settings['bounce_interval']; if ($bounce_interval > 0 && is_email($bounce_settings['bounce_email']) && !empty($bounce_settings['bounce_host'])) { $schedules['alo_em_bounce'] = array('interval' => 59 * 60 * $bounce_interval, 'display' => 'EasyMail every ' . $bounce_interval . ' hours'); } return $schedules; }
/* only admin can */ ?> <div id="bounces"> <form action="#bounces" method="post"> <h2><?php _e("Bounces", "alo-easymail"); ?> </h2> <table class="form-table"><tbody> <?php // Get array of saved settings $bounce_settings = alo_em_bounce_settings(); // IMAP not installed if (!$imap_installed) { echo '<tr valign="top">'; echo '<td colspan="2">'; echo '<div class="text-alert"><p><img src="' . ALO_EM_PLUGIN_URL . '/images/12-exclamation.png" /> '; echo '<strong>' . sprintf(__('PHP %s extension was not detected', 'alo-easymail'), 'IMAP') . '.</strong><br />'; echo __('This plugin feature can not work now.', 'alo-easymail') . ' '; echo sprintf(__('Ask your hosting provider to enable %s for PHP', 'alo-easymail'), '<code>IMAP</code>') . '.'; echo '</p></div>'; echo '</td></tr>'; } else { if (isset($_POST['test_bounce_connection'])) { $bounce_connection = alo_em_bounce_connect(); echo '<tr valign="top">'; echo '<td colspan="2">';
function alo_em_handle_bounces($report = false) { global $wpdb; $output = ''; $bounce_settings = alo_em_bounce_settings(); $conn = alo_em_bounce_connect(); if (!$conn) { return FALSE; } $num_msgs = imap_num_msg($conn); // start bounce class require_once 'inc/bouncehandler/bounce_driver.class.php'; $bouncehandler = new Bouncehandler(); // get the failures $email_addresses = array(); $delete_addresses = array(); $max_msgs = min($num_msgs, $bounce_settings['bounce_maxmsg']); if ($report) { $output .= 'Bounces handled in: ' . $bounce_settings['bounce_email']; } for ($n = 1; $n <= $max_msgs; $n++) { $msg_headers = imap_fetchheader($conn, $n); $msg_body = imap_body($conn, $n); $bounce = $msg_headers . $msg_body; //entire message $multiArray = $bouncehandler->get_the_facts($bounce); if (!empty($multiArray[0]['action']) && !empty($multiArray[0]['status']) && !empty($multiArray[0]['recipient'])) { if ($report) { $output .= '<br /> - MSG #' . $n . ' - Bounce response: ' . $multiArray[0]['action']; } // If delivery permanently failed, unsubscribe if ($multiArray[0]['action'] == 'failed') { $email = trim($multiArray[0]['recipient']); // Unsubscribe email address if ($s_id = alo_em_is_subscriber($email)) { alo_em_delete_subscriber_by_id($s_id); do_action('alo_easymail_bounce_email_unsubscribed', $email); // Hook if ($report) { $output .= ' - ' . $email . ' UNSUBSCRIBED'; } } } // If delivery temporary or permanently failed, mark recipient as bounced if ($multiArray[0]['action'] == 'failed' || $multiArray[0]['action'] == 'transient' || $multiArray[0]['action'] == 'autoreply') { // TODO maybe use: $bouncehandler->x_header_search_1 = 'ALO-EM-Newsletter'; // Look fo EasyMail custom headers: Newsletter and Recipient // NOTE: searching in body because IDs are inside original message included in body $newsletter_id = 0; $recipient_id = 0; if (preg_match('/X-ALO-EM-Newsletter: (\\d+)/i', $bounce, $matches)) { if (!empty($matches[1]) && is_numeric($matches[1])) { $newsletter_id = (int) $matches[1]; } } if (preg_match('/X-ALO-EM-Recipient: (\\d+)/i', $bounce, $matches)) { if (!empty($matches[1]) && is_numeric($matches[1])) { $recipient_id = (int) $matches[1]; } } // Mark recipient as bounced only if not a debug to author if ($newsletter_id > 0 && $recipient_id > 0 && strpos($msg_headers, "( DEBUG - TO: ") === false) { $wpdb->update("{$wpdb->prefix}easymail_recipients", array('result' => -3), array('ID' => $recipient_id, 'newsletter' => $newsletter_id, 'email' => $email)); } if ($report) { $output .= ' - Recipient ID #' . $recipient_id . ' marked as not delivered'; } // mark msg for deletion imap_delete($conn, $n); } } else { if ($report) { $output .= '<br /><span class="description"> - MSG #' . $n . ' - Not a bounce</span>'; } } } //for loop // delete messages imap_expunge($conn); // close imap_close($conn); if ($report) { return $output; } }