if (!defined('WP_MAIL_INTERVAL')) { define('WP_MAIL_INTERVAL', 300); } // 5 minutes $last_checked = get_transient('mailserver_last_checked'); if ($last_checked) { wp_die(__('Slow down cowboy, no need to check for new mails so often!')); } set_transient('mailserver_last_checked', true, WP_MAIL_INTERVAL); $time_difference = get_option('gmt_offset') * HOUR_IN_SECONDS; $phone_delim = '::'; $pop3 = new POP3(); if (!$pop3->connect(get_option('mailserver_url'), get_option('mailserver_port')) || !$pop3->user(get_option('mailserver_login'))) { wp_die(esc_html($pop3->ERROR)); } $count = $pop3->pass(get_option('mailserver_pass')); if (false === $count) { wp_die(esc_html($pop3->ERROR)); } if (0 === $count) { $pop3->quit(); wp_die(__('There doesn’t seem to be any new mail.')); } for ($i = 1; $i <= $count; $i++) { $message = $pop3->get($i); $bodysignal = false; $boundary = ''; $charset = ''; $content = ''; $content_type = ''; $content_transfer_encoding = '';
require_once ABSPATH . WPINC . '/class-pop3.php'; /** Only check at this interval for new messages. */ if (!defined('WP_MAIL_INTERVAL')) { define('WP_MAIL_INTERVAL', 300); } // 5 minutes $last_checked = get_transient('mailserver_last_checked'); if ($last_checked) { wp_die(__('Slow down cowboy, no need to check for new mails so often!')); } set_transient('mailserver_last_checked', true, WP_MAIL_INTERVAL); $time_difference = get_option('gmt_offset') * 3600; $phone_delim = '::'; $pop3 = new POP3(); $count = 0; if (!$pop3->connect(get_option('mailserver_url'), get_option('mailserver_port')) || !$pop3->user(get_option('mailserver_login')) || !($count = $pop3->pass(get_option('mailserver_pass')))) { $pop3->quit(); wp_die(0 === $count ? __('There doesn’t seem to be any new mail.') : esc_html($pop3->ERROR)); } for ($i = 1; $i <= $count; $i++) { $message = $pop3->get($i); $bodysignal = false; $boundary = ''; $charset = ''; $content = ''; $content_type = ''; $content_transfer_encoding = ''; $post_author = 1; $author_found = false; $dmonths = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'); foreach ($message as $line) {
public function checkBounced() { if ($this->config->get('ne_bounce') && $this->config->get('ne_bounce_email') && $this->config->get('ne_bounce_pop3_server') && $this->config->get('ne_bounce_pop3_user') && $this->config->get('ne_bounce_pop3_password')) { require_once DIR_SYSTEM . 'library/pop3_ne.php'; $pop3 = new POP3(); if (!@$pop3->connect($this->config->get('ne_bounce_pop3_server'), $this->config->get('ne_bounce_pop3_port') ? $this->config->get('ne_bounce_pop3_port') : 110) || !$pop3->user($this->config->get('ne_bounce_pop3_user'))) { return false; } $count = @$pop3->pass($this->config->get('ne_bounce_pop3_password')); if (false === $count) { return false; } if (0 === $count) { $pop3->quit(); return false; } for ($i = 1; $i <= $count; $i++) { $message = $pop3->get($i); foreach ($message as $line) { if (preg_match('/X-NEMail: /i', $line)) { $hash = trim(str_replace('X-NEMail: ', '', $line)); } } if (isset($hash) && $hash) { $hash = base64_decode(urldecode($hash)); $test = explode('|', $hash); if (count($test) == 2) { $data = array('uid' => $test[1], 'email' => $test[0]); $query = $this->db->query("UPDATE `" . DB_PREFIX . "ne_stats_personal` SET bounced = '1' WHERE stats_personal_id = '" . (int) $data['uid'] . "' AND email = '" . $this->db->escape($data['email']) . "'"); if ($query) { $pop3->delete($i); } else { $pop3->reset(); } } } else { if ($this->config->get('ne_bounce_delete')) { $pop3->delete($i); } } } $pop3->quit(); } }
public function ajax_bounce_test_check() { $return['success'] = false; $return['msg'] = ''; $passes = intval($_POST['passes']); $identifier = $_POST['identifier']; if (!mymail_option('bounce_active')) { $return['complete'] = true; echo json_encode($return); exit; } $server = mymail_option('bounce_server'); $user = mymail_option('bounce_user'); $pwd = mymail_option('bounce_pwd'); if (!$server || !$user || !$pwd) { $return['complete'] = true; echo json_encode($return); exit; } if (mymail_option('bounce_ssl')) { $server = 'ssl://' . $server; } require_once ABSPATH . WPINC . '/class-pop3.php'; $pop3 = new POP3(); if (!$pop3->connect($server, mymail_option('bounce_port', 110)) || !$pop3->user($user)) { $return['complete'] = true; $return['msg'] = __('Unable to connect to bounce server! Please check your settings.', 'mymail'); echo json_encode($return); exit; } $return['success'] = true; $count = $pop3->pass($pwd); $return['msg'] = __('checking for new messages', 'mymail') . str_repeat('.', $passes); if ($passes > 20) { $return['complete'] = true; $return['msg'] = __('Unable to get test message! Please check your settings.', 'mymail'); } if (false === $count || 0 === $count) { if (0 === $count) { $pop3->quit(); } echo json_encode($return); exit; } for ($i = 1; $i <= $count; $i++) { $message = $pop3->get($i); if (!$message) { continue; } $message = implode($message); if (strpos($message, $identifier)) { $pop3->delete($i); $pop3->quit(); $return['complete'] = true; $return['msg'] = __('Your bounce server is good!', 'mymail'); echo json_encode($return); exit; } else { $pop3->reset(); } } $pop3->quit(); echo json_encode($return); exit; }
private function check_bounces() { if (!mymail_option('bounce_active')) { return false; } do_action('mymail_check_bounces'); $server = mymail_option('bounce_server'); $user = mymail_option('bounce_user'); $pwd = mymail_option('bounce_pwd'); if (!$server || !$user || !$pwd) { return false; } if (get_transient('mymail_check_bounces_lock')) { return false; } //check bounces only every five minutes set_transient('mymail_check_bounces_lock', true, 360); if (mymail_option('bounce_ssl')) { $server = 'ssl://' . $server; } require_once ABSPATH . WPINC . '/class-pop3.php'; $pop3 = new POP3(); if (!$pop3->connect($server, mymail_option('bounce_port', 110)) || !$pop3->user($user)) { return false; } $count = $pop3->pass($pwd); if (false === $count) { return false; } if (0 === $count) { $pop3->quit(); return false; } $delete_bounces = mymail_option('bounce_delete'); //only max 1000 at once $count = min($count, 1000); for ($i = 1; $i <= $count; $i++) { $message = $pop3->get($i); if (!$message) { continue; } $message = implode($message); preg_match('#X-MyMail: ([a-f0-9]{32})#i', $message, $hash); preg_match('#X-MyMail-Campaign: (\\d+)#i', $message, $camp); if (!empty($hash) && !empty($camp)) { if ($this->reset_mail($hash[1], $camp[1])) { $pop3->delete($i); } else { $pop3->reset(); } } else { if ($delete_bounces) { $pop3->delete($i); } } } $pop3->quit(); //do third party stuff $this->thirdpartystuff(); }
function getlist($mail_server, $mail_port, $mail_user, $mail_pass, $max = 10) { $maillists = array(); $phone_delim = '::'; $pop3 = new POP3(); if (!$pop3->connect($mail_server, $mail_port) || !$pop3->user($mail_user) || !($count = $pop3->pass($mail_pass))) { $pop3->quit(); $this->error = 0 === $count ? 'There doesn’t seem to be any new mail.' : $pop3->ERROR; return false; } $this->count = $count; var_dump($count); //if($count > $max )$count = $max; for ($i = $count; $i > $count - 1; $i--) { $message = $pop3->get($i); /*foreach($message as $m=>$n){ //$n=iconv_mime_decode($n, 2, "gbk"); $n=base64_decode($n); $n=mb_convert_encoding($n, 'gbk', 'gbk'); var_dump($n); if(strpos($n,'http://bbs.scol.com.cn/member.php')!==FALSE){ var_dump($n); } if(strpos($n,'(如果上面不')!==FALSE){ var_dump($n); } //$n=mb_convert_encoding($n, 'gbk', 'gbk'); }*/ /*for($j=0;$j<=sizeof($message);$j++){ $message[$j]=base64_decode($message[$j]); }*/ var_dump(base64_decode($message[42])); var_dump(substr(base64_decode($message[41]), 12)); var_dump(substr(base64_decode($message[42]), 0, -12)); $bf = substr(base64_decode($message[41]), 17); $af = trim(substr(base64_decode($message[42]), 0, -20)); //$url=substr(base64_decode($message[43]),12)+substr(base64_decode($message[44]),0,-12); var_dump($bf . $af); $all = str_replace("\n", '', $bf . $af); $all = str_replace(">", "", $all); $all = str_replace("&", "&", $all); //$snoopy->fetch($bf.$af); //$re =mb_convert_encoding($snoopy->results,"utf-8","gbk"); //print_r($re); //sleep(10); //echo "。"; //echo "<br/>"; $bodysignal = false; $boundary = ''; $charset = ''; $content = ''; $content_type = ''; $content_transfer_encoding = ''; $post_author = 1; foreach ((array) $message as $line) { //var_dump($line); // body signal if (strlen($line) < 3) { $bodysignal = true; } if ($bodysignal) { $content .= $line; } else { if (preg_match('/Content-Type: /i', $line)) { $content_type = trim($line); $content_type = substr($content_type, 14, strlen($content_type) - 14); $content_type = explode(';', $content_type); if (!empty($content_type[1])) { $charset = explode('=', $content_type[1]); $charset = !empty($charset[1]) ? trim($charset[1]) : ''; } $content_type = $content_type[0]; } if (preg_match('/Content-Transfer-Encoding: /i', $line)) { $content_transfer_encoding = trim($line); $content_transfer_encoding = substr($content_transfer_encoding, 27, strlen($content_transfer_encoding) - 27); $content_transfer_encoding = explode(';', $content_transfer_encoding); $content_transfer_encoding = $content_transfer_encoding[0]; } if ($content_type == 'multipart/alternative' && false !== strpos($line, 'boundary="') && '' == $boundary) { $boundary = trim($line); $boundary = explode('"', $boundary); $boundary = $boundary[1]; } if (preg_match('/Subject: /i', $line)) { $subject = trim($line); $subject = substr($subject, 9, strlen($subject) - 9); // Captures any text in the subject before $phone_delim as the subject if (function_exists('iconv_mime_decode')) { $subject = iconv_mime_decode($subject, 2, "UTF-8"); } else { $subject = wp_iso_descrambler($subject); } $subject = explode($phone_delim, $subject); $subject = $subject[0]; } // Set the author using the email address (From or Reply-To, the last used) // otherwise use the site admin if (preg_match('/(From|Reply-To): /', $line)) { if (preg_match('|[a-z0-9_.-]+@[a-z0-9_.-]+(?!.*<)|i', $line, $matches)) { $author = $matches[0]; } else { $author = trim($line); } } if (preg_match('/Date: /i', $line)) { // of the form '20 Mar 2002 20:32:37' $ddate = trim($line); } if (preg_match('/member.php?mod=activate/i', $line)) { // of the form '20 Mar 2002 20:32:37' $lj = trim($line); } } } //$subject = trim($subject); $post_data = compact('ddate', 'author', 'subject', 'lj', 'all'); $maillists[] = $post_data; /* if(!$pop3->delete($i)) { echo '<p>' . sprintf(__('Oops: %s'), esc_html($pop3->ERROR)) . '</p>'; $pop3->reset(); exit; } else { echo '<p>' . sprintf(__('Mission complete. Message <strong>%s</strong> deleted.'), $i) . '</p>'; } */ } $pop3->quit(); $this->result = $maillists; return $maillists; }