} $post_category = array(get_option('default_email_category')); $post_data = compact('post_content', 'post_title', 'post_date', 'post_date_gmt', 'post_author', 'post_category', 'post_status'); $post_data = wp_slash($post_data); $post_ID = wp_insert_post($post_data); if (is_wp_error($post_ID)) { echo "\n" . $post_ID->get_error_message(); } // We couldn't post, for whatever reason. Better move forward to the next email. if (empty($post_ID)) { continue; } /** * Fires after a post submitted by email is published. * * @since 1.2.0 * * @param int $post_ID The post ID. */ do_action('publish_phone', $post_ID); echo "\n<p><strong>" . __('Author:') . '</strong> ' . esc_html($post_author) . '</p>'; echo "\n<p><strong>" . __('Posted title:') . '</strong> ' . esc_html($post_title) . '</p>'; if (!$pop3->delete($i)) { echo '<p>' . sprintf(__('Oops: %s'), esc_html($pop3->ERROR)) . '</p>'; $pop3->reset(); exit; } else { echo '<p>' . sprintf(__('Mission complete. Message %s deleted.'), '<strong>' . $i . '</strong>') . '</p>'; } } $pop3->quit();
function wp_mail_receive() { global $xoopsDB, $wpdb, $wp_id, $siteurl, $blog_charset, $wp_pop3; require_once ABSPATH . WPINC . '/class-pop3.php'; timer_start(); $use_cache = 1; $time_difference = get_settings('time_difference'); // Get Server Time Zone // If Server Time Zone is not collect, Please comment out following line; $server_timezone = date("O"); // echo "Server TimeZone is ".date('O')."<br />"; // If Server Time Zone is not collect, Please uncomment following line and set collect timezone value; // $server_timezone = "+0900"; //This is a sample value for JST+0900 $server_timezone = $server_timezone / 100; $weblog_timezone = $server_timezone + $time_difference; error_reporting(2037); $wp_pop3 = new POP3(); if (!$wp_pop3->connect(get_settings('mailserver_url'), get_settings('mailserver_port'))) { echo "Ooops {$wp_pop3->ERROR} <br />\n"; return; } $Count = $wp_pop3->login(get_settings('mailserver_login'), get_settings('mailserver_pass')); if ($Count == false) { if (!$wp_pop3->FP) { echo "Oooops Login Failed: {$wp_pop3->ERROR}<br />\n"; } else { echo "No Message<br />\n"; $wp_pop3->quit(); } return; } // ONLY USE THIS IF YOUR PHP VERSION SUPPORTS IT! register_shutdown_function('wp_mail_quit'); for ($iCount = 1; $iCount <= $Count; $iCount++) { $MsgOne = $wp_pop3->get($iCount); if (!$MsgOne || gettype($MsgOne) != 'array') { echo "oops, {$wp_pop3->ERROR}<br />\n"; $wp_pop3->quit(); return; } $content = ''; $content_type = ''; $boundary = ''; $att_boundary = ''; $hatt_boundary = ''; $bodysignal = 0; $dmonths = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'); while (list($lineNum, $line) = each($MsgOne)) { if (strlen($line) < 3) { $bodysignal = 1; } if ($bodysignal) { $content .= $line; } else { if (preg_match('/^Content-Type:\\s+(.*?)\\;/i', $line, $match)) { $content_type = $match[1]; $content_type = strtolower($match[1]); } if ($content_type == 'multipart/mixed' && preg_match('/boundary=(?:")?([^;"\\s\\n]*?)(?:")?\\s*(?:$|;)/', $line, $match) && $att_boundary == '') { $att_boundary = trim($match[1]); } if ($content_type == 'multipart/alternative' && preg_match('/boundary=(?:")?([^;"\\s\\n]*?)(?:")?\\s*(?:$|;)/', $line, $match) && $boundary == '') { $boundary = trim($match[1]); } if ($content_type == 'multipart/related' && preg_match('/boundary=(?:")?([^;"\\s\\n]*?)(?:")?\\s*(?:$|;)/', $line, $match) && $hatt_boundary == '') { $hatt_boundary = trim($match[1]); } if (preg_match('/Subject: /', $line)) { $subject = trim($line); $subject = substr($subject, 9, strlen($subject) - 9); if (function_exists('mb_decode_mimeheader')) { $subject1 = mb_decode_mimeheader($subject); if ($subject != $subject) { $sub_charset = mb_internal_encoding(); } else { $sub_charset = "auto"; } $subject = $subject1; } if (get_settings('use_phoneemail')) { $subject = explode(get_settings('phoneemail_separator'), $subject); $subject = trim($subject[0]); } } if (preg_match('/Date: /', $line)) { // of the form '20 Mar 2002 20:32:37' $ddate = trim($line); $ddate = str_replace('Date: ', '', $ddate); if (strpos($ddate, ',')) { $ddate = trim(substr($ddate, strpos($ddate, ',') + 1, strlen($ddate))); } $date_arr = explode(' ', $ddate); $date_time = explode(':', $date_arr[3]); $ddate_H = $date_time[0]; $ddate_i = $date_time[1]; $ddate_s = $date_time[2]; $ddate_m = $date_arr[1]; $ddate_d = $date_arr[0]; $ddate_Y = $date_arr[2]; $mail_timezone = trim(ereg_replace("\\([^)]*\\)", "", $date_arr[4])) / 100; // echo "Email TimeZone is {$date_arr[4]}<br />"; $mail_time_difference = $weblog_timezone - $mail_timezone; for ($i = 0; $i < 12; $i++) { if ($ddate_m == $dmonths[$i]) { $ddate_m = $i + 1; } } $ddate_U = mktime($ddate_H, $ddate_i, $ddate_s, $ddate_m, $ddate_d, $ddate_Y); $ddate_U = $ddate_U + $mai_time_difference * 3600; $post_date = date('Y-m-d H:i:s', $ddate_U); } } } if (!ereg(get_settings('subjectprefix'), $subject)) { continue; } $charset = ""; $ncharset = preg_match("/\\s?charset=\"?([A-Za-z0-9\\-]*)\"?/i", $content, $matches); if ($ncharset) { $charset = $matches[1]; } $ddate_today = time() + $time_difference * 3600; $ddate_difference_days = ($ddate_today - $ddate_U) / 86400; if ($ddate_difference_days > 14) { echo "Too old<br />\n"; continue; } if (preg_match('/' . get_settings('subjectprefix') . '/', $subject)) { $userpassstring = ''; echo "<div style=\"border: 1px dashed #999; padding: 10px; margin: 10px;\">\n"; echo "<p><b>{$iCount}</b></p><p><b>Subject: </b>{$subject}</p>\n"; $subject = trim(str_replace(get_settings('subjectprefix'), '', $subject)); $attachment = false; if ($att_boundary) { $contents = explode('--' . $att_boundary, $content); $content = $contents[1]; $ncharset = preg_match("/\\s?charset=\"?([A-Za-z0-9\\-]*)\"?/i", $content, $matches); if ($ncharset) { $charset = $matches[1]; } $content = explode("\r\n\r\n", $content, 2); $content = $content[1]; } if ($hatt_boundary) { $contents = explode('--' . $hatt_boundary, $content); $content = $contents[1]; if (preg_match('/Content-Type: multipart\\/alternative\\;\\s*boundary\\=(?:")?([^";\\s\\n]*?)(?:")?\\s*(?:;|\\n|$)"/i', $content, $matches)) { $boundary = trim($matches[1]); $content = explode('--' . $boundary, $content); $content = $content[2]; } $ncharset = preg_match("/charset=\"?([^\"]*)\"?/i", $content, $matches); if ($ncharset) { $charset = $matches[1]; } $content = explode('Content-Transfer-Encoding: quoted-printable', $content); $content = strip_tags($content[1], '<img><p><br><i><b><u><em><strong><strike><font><span><div><dl><dt><dd><ol><ul><li>,<table><tr><td>'); } else { if ($boundary) { $content = explode('--' . $boundary, $content); $content = $content[2]; if (preg_match('/Content-Type: multipart\\/related\\;\\s*boundary=(?:")?([^";\\s\\n]*?)(?:")?\\s*(?:;|\\n|$)/i', $content, $matches)) { $hatt_boundary = trim($matches[1]); $contents = explode('--' . $hatt_boundary, $content); $content = $contents[1]; } $ncharset = preg_match("/charset=\"?([^\"]*)\"?/i", $content, $matches); if ($ncharset) { $charset = $matches[1]; } $content = explode('Content-Transfer-Encoding: quoted-printable', $content); $content = strip_tags($content[1], '<img><p><br><i><b><u><em><strong><strike><font><span><div><dl><dt><dd><ol><ul><li>,<table><tr><td>'); } } $content = trim($content); echo "<p><b>Content-type:</b> {$content_type}, <b>boundary:</b> {$boundary}</p>\n"; echo "<p><b>att_boundary:</b> {$att_boundary}, <b>hatt_boundary:</b> {$hatt_boundary}</p>\n"; echo "<p><b>charset:</b>{$charset}, <b>BLOG charset:</b>{$blog_charset}</p>\n"; // echo "<p><b>Raw content:</b><br /><pre>".$content.'</pre></p>'; if ($charset == "" || trim(strtoupper($charset)) == "ISO-2022-JP") { $charset = "JIS"; } if (trim(strtoupper($charset)) == "SHIFT_JIS") { $charset = "SJIS"; } $btpos = strpos($content, get_settings('bodyterminator')); if ($btpos) { $content = substr($content, 0, $btpos); } $content = trim($content); $blah = explode("\n", preg_replace("/^[\n\r\\s]*/", "", strip_tags($content))); $firstline = preg_replace("/[\n\r]/", "", $blah[0]); $secondline = $blah[1]; if (get_settings('use_phoneemail')) { echo "<p><b>Use Phone Mail:</b> Yes</p>\n"; $btpos = strpos($firstline, get_settings('phoneemail_separator')); if ($btpos) { $userpassstring = trim(substr($firstline, 0, $btpos)); $content = trim(substr($content, $btpos + strlen(get_settings('phoneemail_separator')), strlen($content))); $btpos = strpos($content, get_settings('phoneemail_separator')); if ($btpos) { $userpassstring = trim(substr($content, 0, $btpos)); $content = trim(substr($content, $btpos + strlen(get_settings('phoneemail_separator')), strlen($content))); } } $contentfirstline = $blah[1]; } else { echo "<p><b>Use Phone Mail:</b> No</p>\n"; $userpassstring = strip_tags($firstline); $contentfirstline = ''; } $flat = 999.0; $flon = 999.0; $secondlineParts = explode(':', strip_tags($secondline)); if (strncmp($secondlineParts[0], "POS", 3) == 0) { echo "Found POS:<br>\n"; // echo "Second parts is:".$secondlineParts[1]; // the second line is the postion listing line $secLineParts = explode(',', $secondlineParts[1]); $flatStr = $secLineParts[0]; $flonStr = $secLineParts[1]; // echo "String are ".$flatStr.$flonStr; $flat = floatval($secLineParts[0]); $flon = floatval($secLineParts[1]); // echo "values are ".$flat." and ".$flon; // ok remove that position... we should not have it in the final output $content = str_replace($secondline, '', $content); } $blah = explode(':', $userpassstring); $user_login = $blah[0]; $user_pass = $blah[1]; if (function_exists('mb_convert_encoding')) { $user_login = mb_convert_encoding(trim($user_login), $blog_charset, $charset); } else { $user_login = trim($user_login); } $content = $contentfirstline . str_replace($firstline, '', $content); $content = trim($content); // Please uncomment following line, only if you want to check user and password. // echo "<p><b>Login:</b> $user_login, <b>Pass:</b> $user_pass</p>"; echo "<p><b>Login:</b> {$user_login}, <b>Pass:</b> *********</p>"; if ($xoopsDB) { $sql = "SELECT ID, user_level FROM {$wpdb->users[$wp_id]} WHERE user_login='******' ORDER BY ID DESC LIMIT 1"; $result = $wpdb->get_row($sql); if (!$result) { echo "<p><b>Wrong Login.</b></p></div>\n"; continue; } else { $sql = "SELECT * FROM " . $xoopsDB->prefix('users') . " WHERE uname='{$user_login}' AND pass='******' ORDER BY uid DESC LIMIT 1"; $result1 = $wpdb->get_row($sql); if (!$result1) { echo "<p><b>Wrong login or password.</b></p></div>\n"; continue; } } } else { $sql = "SELECT ID, user_level FROM {$wpdb->users[$wp_id]} WHERE user_login='******' AND user_pass='******' ORDER BY ID DESC LIMIT 1"; $result = $wpdb->get_row($sql); if (!$result) { echo "<p><b>Wrong login or password.</b></p></div>\n"; continue; } } $user_level = $result->user_level; $post_author = $result->ID; if ($user_level > 0) { $post_title = xmlrpc_getposttitle($content); if ($post_title == '') { $post_title = $subject; } $post_category = get_settings('default_category'); if (preg_match('/<category>(.+?)<\\/category>/is', $content, $matchcat)) { $post_category = xmlrpc_getpostcategory($content); } if ($post_category == '') { $post_category = get_settings('default_post_category'); } if (function_exists('mb_convert_encoding')) { echo "Subject : " . mb_convert_encoding($subject, $blog_charset, $sub_charset) . " <br />\n"; } else { echo "Subject : " . $subject . " <br />\n"; } echo "Category : {$post_category} <br />\n"; if (!get_settings('emailtestonly')) { // Attaching Image Files Save if ($att_boundary != "") { $attachment = wp_getattach($contents[2], trim($user_login), 1); } if ($boundary != "" && $hatt_boundary != "") { for ($i = 2; $i < count($contents); $i++) { $hattachment = wp_getattach($contents[$i], trim($user_login), 0); if ($hattachment) { if (preg_match("/Content-Id: \\<([^\\>]*)>/i", $contents[$i], $matches)) { $content = preg_replace("/(cid:" . preg_quote($matches[1]) . ")/", "{$siteurl}/attach/" . $hattachment, $content); } } } } if ($boundary != "") { $content = preg_replace("/\\=[\r\n]/", "", $content); $content = preg_replace("/[\r\n]/", " ", $content); } $content = preg_replace("|\n([^\n])|", " \$1", $content); $content = preg_replace("/\\=([0-9a-fA-F]{2,2})/e", "pack('c',base_convert('\\1',16,10))", $content); if (function_exists('mb_convert_encoding')) { $content = addslashes(mb_convert_encoding(trim($content), $blog_charset, $charset)); $post_title = addslashes(trim(mb_convert_encoding($post_title, $blog_charset, $sub_charset))); } else { $content = addslashes(trim($content)); $post_title = addslashes(trim($post_title)); } // If we find an attachment, add it to the post if ($attachment) { if (file_exists("attach/thumb-" . $attachment)) { $content = "<a href=\"" . $siteurl . "/attach/" . $attachment . "\"><img style=\"float: left;\" hspace=\"6\" src = \"" . $siteurl . "/attach/thumb-" . $attachment . "\" alt=\"moblog\" ></a>" . $content . "<br clear=left>"; } else { $content = "<a href=\"" . $siteurl . "/attach/" . $attachment . "\"><img style=\"float: left;\" hspace=\"6\" src = \"" . $siteurl . "/attach/" . $attachment . "\" alt=\"moblog\" ></a>" . $content . "<br clear=left>"; } } if ($flat > 500) { $sql = "INSERT INTO {$wpdb->posts[$wp_id]} (post_author, post_date, post_content, post_title, post_category) VALUES ({$post_author}, '{$post_date}', '{$content}', '{$post_title}', {$post_category})"; } else { $sql = "INSERT INTO {$wpdb->posts[$wp_id]} (post_author, post_date, post_content, post_title, post_category, post_lat, post_lon) VALUES ({$post_author}, '{$post_date}', '{$content}', '{$post_title}', {$post_category}, {$flat}, {$flon})"; } $result = $wpdb->query($sql); $post_ID = $wpdb->insert_id; echo "Post ID = {$post_ID}<br />\n"; if (isset($sleep_after_edit) && $sleep_after_edit > 0) { sleep($sleep_after_edit); } $blog_ID = 1; if ($flat < 500) { pingGeoUrl($post_ID); } // Double check it's not there already $exists = $wpdb->get_row("SELECT * FROM {$wpdb->post2cat[$wp_id]} WHERE post_id = {$post_ID} AND category_id = {$post_category}"); if (!$exists && $result) { $wpdb->query("\n\t\t\t\t\t\tINSERT INTO {$wpdb->post2cat[$wp_id]}\n\t\t\t\t\t\t(post_id, category_id)\n\t\t\t\t\t\tVALUES\n\t\t\t\t\t\t({$post_ID}, {$post_category})\n\t\t\t\t\t\t"); } pingWeblogs($blog_ID); pingBlogs($blog_ID); // pingback($content, $post_ID); do_action('publish_post', $post_ID); do_action('publish_phone', $post_ID); } echo "\n<p><b>Posted title:</b> {$post_title}<br />\n"; echo "<b>Posted content:</b><br /><pre>" . $content . "</pre></p>\n"; if (!$wp_pop3->delete($iCount)) { echo "<p>Oops " . $wp_pop3->ERROR . "</p></div>\n"; $wp_pop3->reset(); return; } else { echo "<p>Mission complete, message <strong>{$iCount}</strong> deleted.</p>\n"; } } else { echo "<p><strong>Level 0 users can\\'t post.</strong></p>\n"; } echo "</div>\n"; } } $wp_pop3->quit(); timer_stop($output_debugging_info); return; }
function wp_mail_receive() { global $wpdb, $wp_pop3, $img_target; require_once ABSPATH . WPINC . '/class-pop3.php'; timer_start(); $use_cache = 1; $time_difference = get_settings('time_difference'); $blog_charset = get_settings('blog_charset'); error_reporting(2037); $wp_pop3 = new POP3(); if (!$wp_pop3->connect(get_settings('mailserver_url'), get_settings('mailserver_port'))) { echo "Ooops {$wp_pop3->ERROR} <br />\n"; return; } $mail_count = $wp_pop3->login(get_settings('mailserver_login'), get_settings('mailserver_pass')); if ($mail_count == false) { if (!$wp_pop3->FP) { echo "Oooops Login Failed: {$wp_pop3->ERROR}<br />\n"; } else { echo "No Message<br />\n"; $wp_pop3->quit(); } return; } // ONLY USE THIS IF YOUR PHP VERSION SUPPORTS IT! register_shutdown_function('wp_mail_quit'); for ($mail_num = 1; $mail_num <= $mail_count; $mail_num++) { $MsgOne = $wp_pop3->get($mail_num); if (!$MsgOne || gettype($MsgOne) != 'array') { echo "oops, {$wp_pop3->ERROR}<br />\n"; $wp_pop3->quit(); return; } $content = ''; $content_type = ''; $boundary = ''; $att_boundary = ''; $hatt_boundary = ''; $bodysignal = 0; $dmonths = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'); while (list($lineNum, $line) = each($MsgOne)) { if (strlen($line) < 3) { $bodysignal = 1; } if ($bodysignal) { $content .= $line; } else { if (preg_match('/^Content-Type:\\s+(.*?)\\;/i', $line, $match)) { $content_type = $match[1]; $content_type = strtolower($match[1]); } if ($content_type == 'multipart/mixed' && preg_match('/boundary=(?:")?([^;"\\s\\n]*?)(?:")?\\s*(?:$|;)/', $line, $match) && $att_boundary == '') { $att_boundary = trim($match[1]); } if ($content_type == 'multipart/alternative' && preg_match('/boundary=(?:")?([^;"\\s\\n]*?)(?:")?\\s*(?:$|;)/', $line, $match) && $boundary == '') { $boundary = trim($match[1]); } if ($content_type == 'multipart/related' && preg_match('/boundary=(?:")?([^;"\\s\\n]*?)(?:")?\\s*(?:$|;)/', $line, $match) && $hatt_boundary == '') { $hatt_boundary = trim($match[1]); } if (preg_match('/Subject: /', $line)) { $subject = trim($line); $subject = substr($subject, 9, strlen($subject) - 9); if (function_exists('mb_decode_mimeheader')) { $subject1 = mb_decode_mimeheader($subject); if ($subject != $subject) { $sub_charset = mb_internal_encoding(); } else { $sub_charset = "auto"; } $subject = $subject1; } if (get_settings('use_phoneemail')) { $subject = explode(get_settings('phoneemail_separator'), $subject); $subject = trim($subject[0]); } } if (preg_match('/Date: /', $line)) { // of the form '20 Mar 2002 20:32:37' $ddate = trim($line); $ddate = str_replace('Date: ', '', $ddate); if (strpos($ddate, ',')) { $ddate = trim(substr($ddate, strpos($ddate, ',') + 1, strlen($ddate))); } $ddate_U = strtotime($ddate) + $time_difference * 3600; $post_date = date('Y-m-d H:i:s', $ddate_U); } } } if (!ereg(get_settings('subjectprefix'), $subject)) { continue; } $charset = ""; $ncharset = preg_match("/\\s?charset=\"?([A-Za-z0-9\\-]*)\"?/i", $content, $matches); if ($ncharset) { $charset = $matches[1]; } $ddate_today = time() + $time_difference * 3600; $ddate_difference_days = ($ddate_today - $ddate_U) / 86400; if ($ddate_difference_days > 14) { echo "Too old<br />\n"; continue; } if (preg_match('/' . get_settings('subjectprefix') . '/', $subject)) { $userpassstring = ''; echo "<div style=\"border: 1px dashed #999; padding: 10px; margin: 10px;\">\n"; echo "<p><b>{$mail_num}</b></p><p><b>Subject: </b>{$subject}</p>\n"; $subject = trim(str_replace(get_settings('subjectprefix'), '', $subject)); $attachment = false; if ($att_boundary) { $contents = explode('--' . $att_boundary, $content); $content = $contents[1]; $ncharset = preg_match("/\\s?charset=\"?([A-Za-z0-9\\-]*)\"?/i", $content, $matches); if ($ncharset) { $charset = $matches[1]; } $content = explode("\r\n\r\n", $content, 2); $content = $content[1]; } if ($hatt_boundary) { $contents = explode('--' . $hatt_boundary, $content); $content = $contents[1]; if (preg_match('/Content-Type: multipart\\/alternative\\;\\s*boundary\\=(?:")?([^";\\s\\n]*?)(?:")?\\s*(?:;|\\n|$)"/i', $content, $matches)) { $boundary = trim($matches[1]); $content = explode('--' . $boundary, $content); $content = $content[2]; } $ncharset = preg_match("/charset=\"?([^\"]*)\"?/i", $content, $matches); if ($ncharset) { $charset = $matches[1]; } $content = explode('Content-Transfer-Encoding: quoted-printable', $content); $content = strip_tags($content[1], '<img><p><br><i><b><u><em><strong><strike><font><span><div><dl><dt><dd><ol><ul><li>,<table><tr><td>'); } else { if ($boundary) { $content = explode('--' . $boundary, $content); $content = $content[2]; if (preg_match('/Content-Type: multipart\\/related\\;\\s*boundary=(?:")?([^";\\s\\n]*?)(?:")?\\s*(?:;|\\n|$)/i', $content, $matches)) { $hatt_boundary = trim($matches[1]); $contents = explode('--' . $hatt_boundary, $content); $content = $contents[1]; } $ncharset = preg_match("/charset=\"?([^\"]*)\"?/i", $content, $matches); if ($ncharset) { $charset = $matches[1]; } $content = explode('Content-Transfer-Encoding: quoted-printable', $content); $content = strip_tags($content[1], '<img><p><br><i><b><u><em><strong><strike><font><span><div><dl><dt><dd><ol><ul><li>,<table><tr><td>'); } } $content = trim($content); echo "<p><b>Content-type:</b> {$content_type}, <b>boundary:</b> {$boundary}</p>\n"; echo "<p><b>att_boundary:</b> {$att_boundary}, <b>hatt_boundary:</b> {$hatt_boundary}</p>\n"; echo "<p><b>charset:</b>{$charset}, <b>BLOG charset:</b>{$blog_charset}</p>\n"; // echo "<p><b>Raw content:</b><br /><pre>".$content.'</pre></p>'; if ($charset == "" || trim(strtoupper($charset)) == "ISO-2022-JP") { $charset = "JIS"; } if (trim(strtoupper($charset)) == "SHIFT_JIS") { $charset = "SJIS"; } $btpos = strpos($content, get_settings('bodyterminator')); if ($btpos) { $content = substr($content, 0, $btpos); } $content = trim($content); $blah = explode("\n", preg_replace("/^[\n\r\\s]*/", "", strip_tags($content))); $firstline = preg_replace("/[\n\r]/", "", $blah[0]); $secondline = $blah[1]; if (get_settings('use_phoneemail')) { echo "<p><b>Use Phone Mail:</b> Yes</p>\n"; $btpos = strpos($firstline, get_settings('phoneemail_separator')); if ($btpos) { $userpassstring = trim(substr($firstline, 0, $btpos)); $content = trim(substr($content, $btpos + strlen(get_settings('phoneemail_separator')), strlen($content))); $btpos = strpos($content, get_settings('phoneemail_separator')); if ($btpos) { $userpassstring = trim(substr($content, 0, $btpos)); $content = trim(substr($content, $btpos + strlen(get_settings('phoneemail_separator')), strlen($content))); } } $contentfirstline = $blah[1]; } else { echo "<p><b>Use Phone Mail:</b> No</p>\n"; $userpassstring = strip_tags($firstline); $contentfirstline = ''; } $flat = 999.0; $flon = 999.0; $secondlineParts = explode(':', strip_tags($secondline)); if (strncmp($secondlineParts[0], "POS", 3) == 0) { echo "Found POS:<br />\n"; // echo "Second parts is:".$secondlineParts[1]; // the second line is the postion listing line $secLineParts = explode(',', $secondlineParts[1]); $flatStr = $secLineParts[0]; $flonStr = $secLineParts[1]; // echo "String are ".$flatStr.$flonStr; $flat = floatval($secLineParts[0]); $flon = floatval($secLineParts[1]); // echo "values are ".$flat." and ".$flon; // ok remove that position... we should not have it in the final output $content = str_replace($secondline, '', $content); } $blah = explode(':', $userpassstring); $user_login = $blah[0]; $user_pass = $blah[1]; $user_login = mb_conv(trim($user_login), $blog_charset, $charset); $content = $contentfirstline . str_replace($firstline, '', $content); $content = trim($content); // Please uncomment following line, only if you want to check user and password. // echo "<p><b>Login:</b> $user_login, <b>Pass:</b> $user_pass</p>"; echo "<p><b>Login:</b> {$user_login}, <b>Pass:</b> *********</p>"; if (!user_pass_ok($user_login, $user_pass)) { echo "<p><b>Error: Wrong Login.</b></p></div>\n"; continue; } $userdata = get_userdatabylogin($user_login); $user_level = $userdata->user_level; $post_author = $userdata->ID; if ($user_level > 0) { $post_title = xmlrpc_getposttitle($content); if ($post_title == '') { $post_title = $subject; } echo "Subject : " . mb_conv($post_title, $blog_charset, $sub_charset) . " <br />\n"; $post_category = get_settings('default_category'); if (preg_match('/<category>(.+?)<\\/category>/is', $content, $matchcat)) { $post_category = xmlrpc_getpostcategory($content); } if (empty($post_category)) { $post_category = get_settings('default_post_category'); } echo "Category : {$post_category} <br />\n"; $post_category = explode(',', $post_category); if (!get_settings('emailtestonly')) { // Attaching Image Files Save if ($att_boundary != "") { $attachment = wp_getattach($contents[2], "user-" . trim($post_author), 1); } if ($boundary != "" && $hatt_boundary != "") { for ($i = 2; $i < count($contents); $i++) { $hattachment = wp_getattach($contents[$i], "user-" . trim($post_author), 0); if ($hattachment) { if (preg_match("/Content-Id: \\<([^\\>]*)>/i", $contents[$i], $matches)) { $content = preg_replace("/(cid:" . preg_quote($matches[1]) . ")/", get_settings('fileupload_url') . '/' . $hattachment, $content); } } } } if ($boundary != "") { $content = preg_replace("/\\=[\r\n]/", "", $content); $content = preg_replace("/[\r\n]/", " ", $content); } $content = preg_replace("|\n([^\n])|", " \$1", $content); $content = preg_replace("/\\=([0-9a-fA-F]{2,2})/e", "pack('c',base_convert('\\1',16,10))", $content); $content = mb_conv(trim($content), $blog_charset, $charset); // If we find an attachment, add it to the post if ($attachment) { if (isset($img_target) && $img_target) { $img_target = ' target="' . $img_target . '"'; } else { $img_target = ''; } if (file_exists(get_settings('fileupload_realpath') . "/thumb-" . $attachment)) { $content = "<a href=\"" . get_settings('fileupload_url') . '/' . rawurlencode($attachment) . "\"" . $img_target . "><img style=\"float: left;\" hspace=\"6\" src = \"" . get_settings('fileupload_url') . '/thumb-' . rawurlencode($attachment) . "\" alt=\"" . $attachment . "\" title=\"" . $attachment . "\" /></a>" . $content . "<br clear=\"left\" />"; } else { $content = "<a href=\"" . get_settings('fileupload_url') . '/' . rawurlencode($attachment) . "\"" . $img_target . "><img style=\"float: left;\" hspace=\"6\" src = \"" . get_settings('fileupload_url') . '/' . rawurlencode($attachment) . "\" alt=\"" . $attachment . "\" title=\"" . $attachment . "\" /></a>" . $content . "<br clear=\"left\" />"; } } $postHandler =& wp_handler('Post'); $postObject =& $postHandler->create(); $postObject->setVar('post_content', $content); $postObject->setVar('post_title', trim(mb_conv($post_title, $blog_charset, $sub_charset))); $postObject->setVar('post_date', $post_date); $postObject->setVar('post_author', $post_author); $postObject->setVar('post_category', $post_category[0]); $postObject->setVar('post_name', sanitize_title($post_title)); if ($flat < 500) { $postObject->setVar('post_lat', $flat); $postObject->setVar('post_lon', $flon); } if (!$postHandler->insert($postObject, true)) { echo "<b>Error: Insert New Post</b><br />"; } $post_ID = $postObject->getVar('ID'); echo "Post ID = {$post_ID}<br />\n"; $postObject->assignCategories($post_category); do_action('publish_post', $post_ID); do_action('publish_phone', $post_ID); if ($flat < 500) { pingGeoUrl($post_ID); } $blog_ID = 1; pingWeblogs($blog_ID); pingBlogs($blog_ID); pingback($content, $post_ID); } echo "\n<p><b>Posted title:</b> {$post_title}<br />\n"; echo "<b>Posted content:</b><br /><pre>" . $content . "</pre></p>\n"; if (!$wp_pop3->delete($mail_num)) { echo "<p>Oops " . $wp_pop3->ERROR . "</p></div>\n"; $wp_pop3->reset(); return; } else { echo "<p>Mission complete, message <strong>{$mail_num}</strong> deleted.</p>\n"; } } else { echo "<p><strong>Level 0 users can\\'t post.</strong></p>\n"; } echo "</div>\n"; } } $wp_pop3->quit(); timer_stop($output_debugging_info); return; }
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(); }
/** * Retrieves email via POP3 */ function POP3MessageFetch($server = NULL, $port = NULL, $email = NULL, $password = NULL, $protocol = NULL, $offset = NULL, $test = NULL, $deleteMessages = true, $maxemails = 0) { require_once ABSPATH . WPINC . DIRECTORY_SEPARATOR . 'class-pop3.php'; $emails = array(); $pop3 = new POP3(); if (defined('POSTIE_DEBUG')) { $pop3->DEBUG = POSTIE_DEBUG; } DebugEcho("Connecting to {$server}:{$port} ({$protocol})"); if ($pop3->connect(trim($server), $port)) { $msg_count = $pop3->login($email, $password); if ($msg_count === false) { $msg_count = 0; } } else { if (strpos($pop3->ERROR, "POP3: premature NOOP OK, NOT an RFC 1939 Compliant server") === false) { EchoInfo("Mail Connection Time Out. Common Reasons: Server Down, Network Issue, Port/Protocol MisMatch"); } EchoInfo("The Server said: {$pop3->ERROR}"); $msg_count = 0; } DebugEcho("message count: {$msg_count}"); // loop through messages //$msgs = $pop3->pop_list(); //DebugEcho("POP3MessageFetch: messages"); //DebugDump($msgs); for ($i = 1; $i <= $msg_count; $i++) { $m = $pop3->get($i); if ($m !== false) { if (is_array($m)) { $emails[$i] = implode('', $m); if ($deleteMessages) { if (!$pop3->delete($i)) { EchoInfo('POP3MessageFetch: cannot delete message $i ' . $pop3->ERROR); $pop3->reset(); exit; } } } else { DebugEcho("POP3MessageFetch: message {$i} not an array"); } } else { EchoInfo("POP3MessageFetch: message {$i} {$pop3->ERROR}"); } if ($maxemails != 0 && $i >= $maxemails) { DebugEcho("Max emails ({$maxemails})"); break; } } //clean up $pop3->quit(); return $emails; }