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; }
$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 = ''; $post_author = 1; $author_found = false; $dmonths = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'); foreach ($message as $line) { // Body signal. if (strlen($line) < 3) { $bodysignal = true; } if ($bodysignal) {
error_reporting(2037); $pop3 = new POP3(); if (!$pop3->connect($mailserver_url, $mailserver_port)) { echo "Ooops {$pop3->ERROR} <br />\n"; exit; } $Count = $pop3->login($mailserver_login, $mailserver_pass); if (!$Count || $Count == -1) { echo "<h1>Login Failed: {$pop3->ERROR}</h1>\n"; $pop3->quit(); exit; } // ONLY USE THIS IF YOUR PHP VERSION SUPPORTS IT! //register_shutdown_function($pop3->quit()); for ($iCount = 1; $iCount <= $Count; $iCount++) { $MsgOne = $pop3->get($iCount); if (!$MsgOne || gettype($MsgOne) != 'array') { echo "oops, {$pop3->ERROR}<br />\n"; $pop3->quit(); exit; } $content = ''; $content_type = ''; $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) {
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; }
function mail_fetch_login() { require_once SM_PATH . 'include/validate.php'; include_once SM_PATH . 'functions/imap.php'; require_once SM_PATH . 'plugins/mail_fetch/class.POP3.php'; require_once SM_PATH . 'plugins/mail_fetch/functions.php'; global $data_dir, $imapServerAddress, $imapPort; sqgetGlobalVar('username', $username, SQ_SESSION); sqgetGlobalVar('key', $key, SQ_COOKIE); $mailfetch_newlog = getPref($data_dir, $username, 'mailfetch_newlog'); $outMsg = ''; $mailfetch_server_number = getPref($data_dir, $username, 'mailfetch_server_number'); if (!isset($mailfetch_server_number)) { $mailfetch_server_number = 0; } $mailfetch_cypher = getPref($data_dir, $username, 'mailfetch_cypher'); if ($mailfetch_server_number < 1) { $mailfetch_server_number = 0; } for ($i_loop = 0; $i_loop < $mailfetch_server_number; $i_loop++) { $mailfetch_login_[$i_loop] = getPref($data_dir, $username, "mailfetch_login_{$i_loop}"); $mailfetch_fref_[$i_loop] = getPref($data_dir, $username, "mailfetch_fref_{$i_loop}"); $mailfetch_pass_[$i_loop] = getPref($data_dir, $username, "mailfetch_pass_{$i_loop}"); if ($mailfetch_cypher == 'on') { $mailfetch_pass_[$i_loop] = decrypt($mailfetch_pass_[$i_loop]); } if ($mailfetch_pass_[$i_loop] != '' && ($mailfetch_login_[$i_loop] == 'on' && $mailfetch_newlog == 'on' || $mailfetch_fref_[$i_loop] == 'on')) { $mailfetch_server_[$i_loop] = getPref($data_dir, $username, "mailfetch_server_{$i_loop}"); $mailfetch_port_[$i_loop] = getPref($data_dir, $username, "mailfetch_port_{$i_loop}"); $mailfetch_alias_[$i_loop] = getPref($data_dir, $username, "mailfetch_alias_{$i_loop}"); $mailfetch_user_[$i_loop] = getPref($data_dir, $username, "mailfetch_user_{$i_loop}"); $mailfetch_lmos_[$i_loop] = getPref($data_dir, $username, "mailfetch_lmos_{$i_loop}"); $mailfetch_uidl_[$i_loop] = getPref($data_dir, $username, "mailfetch_uidl_{$i_loop}"); $mailfetch_subfolder_[$i_loop] = getPref($data_dir, $username, "mailfetch_subfolder_{$i_loop}"); $mailfetch_server = $mailfetch_server_[$i_loop]; $mailfetch_port = $mailfetch_port_[$i_loop]; $mailfetch_user = $mailfetch_user_[$i_loop]; $mailfetch_alias = $mailfetch_alias_[$i_loop]; $mailfetch_pass = $mailfetch_pass_[$i_loop]; $mailfetch_lmos = $mailfetch_lmos_[$i_loop]; $mailfetch_login = $mailfetch_login_[$i_loop]; $mailfetch_uidl = $mailfetch_uidl_[$i_loop]; $mailfetch_subfolder = $mailfetch_subfolder_[$i_loop]; // $outMsg .= "$mailfetch_alias checked<br>"; // $outMsg .= "$mailfetch_alias_[$i_loop]<br>"; $pop3 = new POP3($mailfetch_server, 60); if (!$pop3->connect($mailfetch_server, $mailfetch_port)) { $outMsg .= _("Warning, ") . $pop3->ERROR; continue; } $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10); $Count = $pop3->login($mailfetch_user, $mailfetch_pass); if (($Count == false || $Count == -1) && $pop3->ERROR != '') { $outMsg .= _("Login Failed:") . $pop3->ERROR; continue; } // register_shutdown_function($pop3->quit()); $msglist = $pop3->uidl(); $i = 1; for ($j = 1; $j < sizeof($msglist); $j++) { if ($msglist["{$j}"] == $mailfetch_uidl) { $i = $j + 1; break; } } if ($Count < $i) { $pop3->quit(); continue; } if ($Count == 0) { $pop3->quit(); continue; } else { $newmsgcount = $Count - $i + 1; } // Faster to get them all at once $mailfetch_uidl = $pop3->uidl(); if (!is_array($mailfetch_uidl) && $mailfetch_lmos == 'on') { $outMsg .= _("Server does not support UIDL."); } for (; $i <= $Count; $i++) { if (!ini_get('safe_mode')) { set_time_limit(20); } // 20 seconds per message max $Message = ""; $MessArray = $pop3->get($i); if (!$MessArray or gettype($MessArray) != "array") { $outMsg .= _("Warning, ") . $pop3->ERROR; continue 2; } while (list($lineNum, $line) = each($MessArray)) { $Message .= $line; } /** * check if mail folder is not null and subscribed * Function can check if mail folder is only unsubscribed * and use unsubscribed mail folder. */ if ($mailfetch_subfolder == '' || !mail_fetch_check_folder($imap_stream, $mailfetch_subfolder)) { fputs($imap_stream, "A3{$i} APPEND INBOX {" . strlen($Message) . "}\r\n"); } else { fputs($imap_stream, "A3{$i} APPEND {$mailfetch_subfolder} {" . strlen($Message) . "}\r\n"); } $Line = fgets($imap_stream, 1024); if (substr($Line, 0, 1) == '+') { fputs($imap_stream, $Message); fputs($imap_stream, "\r\n"); sqimap_read_data($imap_stream, "A3{$i}", false, $response, $message); if ($mailfetch_lmos != 'on') { $pop3->delete($i); } } else { echo "{$Line}"; $outMsg .= _("Error Appending Message!"); } } $pop3->quit(); sqimap_logout($imap_stream); if (is_array($mailfetch_uidl)) { setPref($data_dir, $username, "mailfetch_uidl_{$i_loop}", array_pop($mailfetch_uidl)); } } } if (trim($outMsg) != '') { echo '<br><font size="1">' . _("Mail Fetch Result:") . "<br>{$outMsg}</font>"; } if ($mailfetch_newlog == 'on') { setPref($data_dir, $username, 'mailfetch_newlog', 'off'); } }
if (!is_array($mailfetch_uidl) && $mailfetch_lmos == 'on') { Mail_Fetch_Status(_("Server does not support UIDL.")); } if ($mailfetch_lmos == 'on') { Mail_Fetch_Status(_("Leaving mail on server...")); } else { Mail_Fetch_Status(_("Deleting messages from server...")); } for (; $i <= $Count; $i++) { Mail_Fetch_Status(_("Fetching message ") . "{$i}"); if (!ini_get('safe_mode')) { set_time_limit(20); } // 20 seconds per message max $Message = ""; $MessArray = $pop3->get($i); while (!$MessArray or gettype($MessArray) != "array") { Mail_Fetch_Status(_("Oops, ") . $pop3->ERROR); // re-connect pop3 Mail_Fetch_Status(_("Server error. Disconnect")); $pop3->quit(); Mail_Fetch_Status(_("Reconnect from dead connection")); if (!$pop3->connect($mailfetch_server)) { Mail_Fetch_Status(_("Oops, ") . $pop3->ERROR); Mail_Fetch_Status(_("Saving UIDL")); setPref($data_dir, $username, "mailfetch_uidl_{$i_loop}", $mailfetch_uidl[$i - 1]); continue; } $Count = $pop3->login($mailfetch_user, $mailfetch_pass); if (($Count == false || $Count == -1) && $pop3->ERROR != '') { Mail_Fetch_Status(_("Login Failed:") . ' ' . htmlspecialchars($pop3->ERROR));
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; }
function workPopfetcher(&$eventData) { global $serendipity; static $debug = null; if ($debug === null) { $debug = $this->debug = serendipity_db_bool($this->get_config('debug')); } // updertEntry() will not function unless this is set: $serendipity['POST']['properties']['fake'] = 'fake'; $_SESSION['serendipityRightPublish'] = true; $this->out('<h3>' . PLUGIN_MF_NAME . ' v' . POPFETCHER_VERSION . ' @ ' . date("D M j G:i:s T Y") . '</h3>'); $debug_file = null; // DEVELOPERS: If set to a filename, you can bypass fetching POP and use a file instead. $debug_mail = $this->get_config('debug_mail'); if (strlen($debug_mail) != '' && file_exists($debug_mail)) { $debug_file = $debug_mail; } if ($debug_file != null) { $this->debug = true; } $authorid = $this->get_config('author'); if (empty($authorid) || $authorid == 'empty') { $authorid = isset($serendipity['authorid']) ? $serendipity['authorid'] : 1; } $mailserver = trim($this->get_config('mailserver')); $mailport = $this->get_config('mailport'); $mailuser = trim($this->get_config('mailuser')); $mailpass = trim($this->get_config('mailpass')); $timeout = $this->get_config('timeout'); $deleteflag = serendipity_db_bool($this->get_config('deleteflag')); $apopflag = serendipity_db_bool($this->get_config('apopflag')); $blogflag = serendipity_db_bool($this->get_config('blogflag')); $striptagsflag = serendipity_db_bool($this->get_config('striptagsflag')); $publishflag = serendipity_db_bool($this->get_config('publishflag')); $onlyfrom = $this->get_config('onlyfrom', ''); $maildir = trim($this->get_config('maildir')); $category = trim($this->get_config('category')); $adflag = serendipity_db_bool($this->get_config('adflag')); $plaintext_is_body_flag = serendipity_db_bool($this->get_config('plaintext_is_body')); $plaintext_use_extended_flag = serendipity_db_bool($this->get_config('plaintext_use_extended')); $list_virus = array('.pif', '.vbs', '.scr', '.bat', '.com', '.exe'); $list_imagetype = array('jpg', 'jpeg', 'gif', 'png', 'x-png', 'pjpeg'); $list_imageext = array('.gif', '.jpg', '.png', '.jpeg'); $list_ignore = array('.smil'); $output = ''; $dirpath = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $maildir; $dupcount = 0; // Upload directory must end with a slash character if (strrchr($dirpath, '/') != '/') { $output = MF_ERROR7; $this->out('<br />' . $output . '<br />'); return true; } // Upload directory must be writable if (!is_writable($dirpath)) { $output = MF_ERROR6; $this->out('<br />' . $output . '<br />'); return true; } if (serendipity_db_bool($this->get_config('subfolder'))) { $dirpath = $dirpath . '/' . date('Y'); if (!is_dir($dirpath)) { mkdir($dirpath); } $dirpath = $dirpath . '/' . date('m') . '/'; if (!is_dir($dirpath)) { mkdir($dirpath); } $maildir .= date('Y') . '/' . date('m') . '/'; } $maildir = str_replace('//', '/', $maildir); // Category (if specified) must exist if (!empty($category)) { $cid = serendipity_fetchCategoryInfo(null, $category); if ($cid == false) { $output = MF_ERROR8; $this->out('<br />' . $output . '<br />'); return true; } } if ($debug_file === null) { // Create new instance of POP3 connection $pop3 = new POP3($mailserver, $timeout); // Attempt to connect to mail server if (!$pop3->connect($mailserver, $mailport)) { $output = MF_ERROR1 . ': ' . $pop3->ERROR; $this->out('<br />' . $output . '<br />'); return true; } // Try APOP login if requested, otherwise, regular login if ($apopflag) { $Count = $pop3->apop($mailuser, $mailpass); } else { $Count = $pop3->login($mailuser, $mailpass); } // Check for error retrieving number of msgs in mailbox if ($Count === false or $Count == -1) { $output = MF_ERROR2 . ': ' . $pop3->ERROR; $this->out('<br />' . $output . '<br />'); return true; } // If no msgs in mailbox, exit if ($Count == 0) { $output = MF_MSG1; $this->out('<br />' . $output . '<br />'); return true; } // Get the list of email msgs $msglist = $pop3->uidl(); // Check for error in getting list of email msgs if (!is_array($msglist)) { $output = MF_ERROR3 . ': ' . $pop3->ERROR; $this->out('<br />' . $output . '<br />'); $pop3->quit(); return true; } } else { // Developer debug switch which reads from a file and not a POP3 connection. $dfiles = explode(':', $debug_file); $Count = count($dfiles); } $Message = array(); // ************************ // Fetch each email msg and attachments and put it into the $Message array // ************************ for ($i = 1; $i <= $Count; $i++) { // Messages are numbered starting with '1', not '0' if ($debug_file === null) { $MessArray = $pop3->get($i); } else { $MessArray = file($dfiles[$i - 1]); } // Should have an array. If not, there was an error if (!$MessArray or gettype($MessArray) != "array") { $output = MF_ERROR4 . ': ' . $pop3->ERROR; $this->out('<br />' . $output . '<br />'); $pop3->quit(); return true; } // Extract the msg from MessArray and store it in Message $Message[$i - 1] = ''; while (list($lineNum, $line) = each($MessArray)) { $Message[$i - 1] .= $line; } // Delete the msg if ($deleteflag && $debug_file === null) { $pop3->delete($i); } } if ($debug_file === null) { // Close the connection to the mail server $pop3->quit(); } // ************************ // Message processing section starts here // ************************ $this->out('<br />' . MF_MSG2 . ': ' . $Count . '<br />'); if ($deleteflag) { $this->out(MF_MSG11 . '<br />'); } else { $this->out(MF_MSG12 . '<br />'); } $params['include_bodies'] = true; $params['decode_bodies'] = true; $params['decode_headers'] = true; // Process each email msg foreach ($Message as $M) { $decode = new mimeDecode($M); #$this->out(print_r($M, true)); $s = $decode->decode($params); #$this->out(print_r($s, true)); if ($debug_file !== null) { // DEBUG Struct // echo '<pre>'; // print_r($s); // echo '</pre>'; } if ($s == null) { $this->out('<br />' . MF_ERROR9); return true; } $date = isset($s->headers['date']) ? $s->headers['date'] : MF_MSG3; $from = isset($s->headers['from']) ? $s->headers['from'] : MF_MSG4; if (!empty($onlyfrom) && trim($from) != trim($onlyfrom)) { $this->out('<br />' . sprintf(MF_ERROR_ONLYFROM, '"' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($from) : htmlspecialchars($from, ENT_COMPAT, LANG_CHARSET)) . '"', '"' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($onlyfrom) : htmlspecialchars($onlyfrom, ENT_COMPAT, LANG_CHARSET)) . '"')); continue; } if (empty($s->ctype_parameters['charset'])) { $s->ctype_parameters['charset'] = 'UTF-8'; } if (strtolower($s->ctype_parameters['charset']) == 'us-ascii') { $s->ctype_parameters['charset'] = 'ISO-8859-1'; } $subject = $this->decode(isset($s->headers['subject']) ? $s->headers['subject'] : MF_MSG17, $s->ctype_parameters['charset'], true); #$subject = $this->decode(isset($s->headers['subject']) ? $s->headers['subject'] : MF_MSG17, $s->ctype_parameters['charset']); #$subject = isset($s->headers['subject']) ? $s->headers['subject'] : MF_MSG17; $this->out('<hr />'); $this->out(MF_MSG5 . $date . '<br />'); $this->out(MF_MSG6 . (function_exists('serendipity_specialchars') ? serendipity_specialchars($from) : htmlspecialchars($from, ENT_COMPAT, LANG_CHARSET)) . '<br />'); $this->out(MF_MSG16 . $subject . '<br />'); // Find the author associated with the from address and // set them as the author of the post. $useAuthor = null; if ($authorid == 'byemail') { // We don't have tons of authors .. like two so this isn't a problem // If I wanted this to be "production" quality, I would have to add // a new s9y function that let you retrieve an author given an email address // I suppose I could go with a convention that the base name of the // email address had to be the author's name too. Lookup by name is // supported by s9y. $auths = serendipity_fetchUsers(); $vals = array(); $clean = strtolower($this->cleanEmail($from)); foreach ($auths as $auth) { if (isset($auth['email']) && strtolower($auth['email']) == $clean) { $useAuthor = $auth['authorid']; break; } } if (is_null($useAuthor)) { $this->out('<br />' . sprintf(MF_ERROR_NOAUTHOR, '"' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($clean) : htmlspecialchars($clean, ENT_COMPAT, LANG_CHARSET)) . '"')); continue; } } else { $useAuthor = $authorid; } $postattach = array(); $postbody = array(); $postex = array(); $verizonflag = false; $tmobileflag = false; $firstattachment = false; $firsttext = false; $o2flag = stristr($from, 'mms.o2online.de') !== FALSE; // A mail message with attachments is a series of "parts" if (isset($s->parts) and is_array($s->parts)) { if ($debug_file !== null || $debug) { $this->out('<pre>' . print_r($s->parts, true) . '</pre>'); } $textpref = $this->get_config('textpref'); if ($textpref != 'both') { $has_html = false; $has_text = false; $parts_html = array(); $parts_text = array(); foreach ($s->parts as $idx => $p) { if ($p->ctype_primary == 'text' && $p->ctype_secondary == 'html') { if ($debug_file !== null || $debug) { $this->out("This part is text/html.<br />\n"); } $has_html = true; $parts_html[] = $idx; } elseif ($p->ctype_primary == 'text' && $p->ctype_secondary == 'plain') { if ($debug_file !== null || $debug) { $this->out("This part is text/plain.<br />\n"); } $has_text = true; $parts_text[] = $idx; } } if ($debug_file !== null || $debug) { $this->out("Preference is: {$textpref}.<br />\n"); } if ($textpref == 'text' && $has_html) { if ($debug_file !== null || $debug) { $this->out("Preference is text/plain.<br />\n"); } foreach ($parts_html as $pidx) { if ($debug_file !== null || $debug) { $this->out("Stripping HTML part {$pidx}, because preference is plaintext.<br />\n"); } unset($s->parts[$pidx]); } } if ($textpref == 'html' && $has_text) { if ($debug_file !== null || $debug) { $this->out("Preference is text/html.<br />\n"); } foreach ($parts_text as $pidx) { if ($debug_file !== null || $debug) { $this->out("Stripping text part {$pidx}, because preference is html.<br />\n"); } unset($s->parts[$pidx]); } } } foreach ($s->parts as $p) { if ($debug_file !== null || $debug) { $this->out("Analyzing mail:<br />\n Disposition: {$p->disposition}<br />\n Body: " . (isset($p->body) ? 'Set' : 'Not Set') . "<br />\n Primary CType: {$p->ctype_primary}<br />\n Secondary CType: {$p->ctype_secondary}<br />\n Filename: {$p->d_parameters[filename]}\n .<br />\n"); } // Handle msgs with attachments and messages with images that are inlined if (isset($p->disposition) and $p->disposition == 'attachment' and isset($p->body) or isset($p->disposition) and $p->disposition == 'inline' and isset($p->body) and $p->ctype_primary == 'image' or !empty($p->body) and $p->ctype_primary == 'image') { $this->handleImage($p, $debug, $debug_file, $tmobileflag, $adflag, $dirpath, $list_virus, $list_ignore, $plaintext_is_body_flag, $firsttext, $plaintext_use_extended_flag, $postex, $postbody, $dupcount, $maildir, $authorid, $list_imagetype, $list_imageext, $subject); } elseif (strtolower($p->ctype_primary) == 'text' and isset($p->body)) { if ($debug_file !== null || $debug) { $this->out("<br />\nRecognized text part.<br />\n"); } if (trim($subject) == SPRINTPCS_IDENT_PICTURE) { $p->body = sprintpcs_pictureshare($maildir, $p->body, $authorid); if (strstr($p->body, ERROR_CHECK)) { $this->out('<br />' . $p->body); return true; } } if (trim($subject) == SPRINTPCS_IDENT_ALBUM) { $p->body = sprintpcs_albumshare($maildir, $p->body, $authorid); if (strstr($p->body, ERROR_CHECK)) { $this->out('<br />' . $p->body); return true; } } if (trim($subject) == SPRINTPCS_IDENT_VIDEO) { $p->body = sprintpcs_videoshare($maildir, $p->body, $authorid); if (strstr($p->body, ERROR_CHECK)) { $this->out('<br />' . $p->body); return true; } } if (stristr($subject, CINGULAR_IDENT_PICTURE)) { $p->body = cingular_photo($maildir, $p->body); if (strstr($p->body, ERROR_CHECK)) { $this->out('<br />' . $p->body); return true; } } if (stristr($p->body, VERIZON_IDENT_PICTURE)) { $p->body = verizon_photo($maildir, $p->body); $verizonflag = true; if (strstr($p->body, ERROR_CHECK)) { $this->out('<br />' . $p->body); return true; } } // Because text and HTML attachments get inlined // sometimes (notably Hotmail), // we want to collect them all and attach them to the // regular msg body $bodytext = trim($this->decode($p->body, $p->ctype_parameters['charset'])); if (empty($bodytext)) { continue; } // Strip evil HTML if (preg_match('@<body[^>]*>(.+)</body>@imsU', $bodytext, $m)) { if ($debug_file !== null || $debug) { $this->out("Reduced HTML text.<br />\n"); } $bodytext = $m[1]; } if ($adflag && preg_match('@T\\-Mobile MMS@', $bodytext) && preg_match('@http://www\\.T\\-Mobile\\.(de|nl|com)/mms@', $bodytext)) { if ($debug_file !== null || $debug) { $this->out("<br />\nSkipping T-Mobile ad.<br />\n"); } continue; } if ($firsttext && $plaintext_use_extended_flag) { $postex[] = $bodytext; } else { $postbody[] = $bodytext; $firsttext = true; } } elseif (is_array($p->parts)) { if ($debug_file !== null || $debug) { $this->out("<br />\nRecognized text/multipart.<br />\n"); } if ($textpref != 'both') { $has_html = false; $has_text = false; $parts_html = array(); $parts_text = array(); foreach ($p->parts as $idx => $subp) { if ($subp->ctype_primary == 'text' && $subp->ctype_secondary == 'html') { $has_html = true; $parts_html[] = $idx; } elseif ($subp->ctype_primary == 'text' && $subp->ctype_secondary == 'plain') { $has_text = true; $parts_text[] = $idx; } } if ($textpref == 'text' && $has_html) { foreach ($parts_html as $pidx) { if ($debug_file !== null || $debug) { $this->out("Stripping HTML part {$pidx}, because preference is plaintext.<br />\n"); } unset($p->parts[$pidx]); } } if ($textpref == 'html' && $has_text) { foreach ($parts_text as $pidx) { if ($debug_file !== null || $debug) { $this->out("Stripping text part {$pidx}, because preference is html.<br />\n"); } unset($p->parts[$pidx]); } } } foreach ($p->parts as $subpart) { if ($subpart->ctype_primary == 'text' && $subpart->ctype_secondary == 'html' && $o2flag) { $bodytext = trim($this->decode(popfetcher_provider_o2::getBody($subpart->body), $subpart->ctype_parameters['charset'])); if (empty($bodytext)) { continue; } if ($firsttext && $plaintext_use_extended_flag) { $postex[] = $bodytext; } else { $postbody[] = $bodytext; $firsttext = true; } } elseif ($subpart->ctype_primary == 'text') { $bodytext = trim($this->decode($subpart->body, $subpart->ctype_parameters['charset'])); if (preg_match('@<body[^>]*>(.+)</body>@imsU', $bodytext, $m)) { if ($debug_file !== null || $debug) { $this->out("Reduced HTML text.<br />\n"); } $bodytext = $m[1]; } if ($firsttext && $plaintext_use_extended_flag) { $postex[] = $bodytext; } else { $postbody[] = $bodytext; $firsttext = true; } } elseif ($subpart->ctype_primary == 'image') { // Handle inline multipart images $this->handleImage($subpart, $debug, $debug_file, $tmobileflag, $adflag, $dirpath, $list_virus, $list_ignore, $plaintext_is_body_flag, $firsttext, $plaintext_use_extended_flag, $postex, $postbody, $dupcount, $maildir, $authorid, $list_imagetype, $list_imageext, $subject); } } } else { if ($debug_file !== null || $debug) { $this->out("<br />\nRecognized unknown part.<br />\n"); } if ($p->disposition == 'inline' && isset($p->d_parameters['filename'])) { // Use makeFilename to get rid of spaces and other oddities $filename = serendipity_makeFilename($p->d_parameters['filename']); // if no file extension exists, add default .txt file extension if (!strrpos($filename, ".")) { $filename = $filename . 'txt'; } if ($debug_file !== null || $debug) { $this->out("<br />\nStoring attachment as {$filename}<br />\n"); } $this->out('<br />' . MF_MSG8 . $filename); $fullname = $dirpath . $filename; // Extract file extension and file name for various processing $ext = substr(strrchr($filename, "."), 0); $name = substr($filename, 0, strrpos($filename, ".")); // Skip message and all attachments if possible virus found $lext = strtolower($ext); if (in_array($lext, $list_virus)) { $output = MF_MSG19 . ': ' . $filename; $this->out('<br />' . $output . '<br />'); continue 2; } if (in_array($lext, $list_ignore)) { $this->out('<br />' . MF_MSG20 . '<br />'); continue; } // Check for duplicate filename. Give dup file name file.time().dup.ext if (is_file($fullname)) { $this->out('<br />' . MF_MSG14 . $filename); $name = $name . time() . $dupcount . 'dup'; $filename = $name . $ext; $fullname = $dirpath . $filename; $dupcount++; } $fp = fopen($fullname, 'w'); if (!$fp) { $this->out('<br />' . MF_ERROR5 . $fullname); return true; } fwrite($fp, $p->body); fclose($fp); serendipity_insertImageInDatabase($filename, $maildir, $authorid, NULL); $attlink = '<a class="popfetcherfile" href="' . $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $maildir . $filename . '" target="_blank">' . $filename . '</a>'; // Inline pictures to match the structure of the mail if ($plaintext_is_body_flag) { // Only the first image is embedded in body, or if no extended entry is used if (!$firstattachment || !$plaintext_use_extended_flag) { $postbody[] = $attlink; } else { $postex[] = $attlink; $firsttext = true; } } else { // Standard attachment mode $postattach[] = $attlink; } $firstattachment = true; $this->out('<br />' . MF_MSG13 . $filename); } $this->out('<br />' . MF_MSG9); // Tmobile sends a weird nested text and html // sub-attachment (at least the nokia does) if (isset($s->headers['x-operator']) and strtolower($s->headers['x-operator']) == TMOBILE_IDENT_PICTURE) { $p->body = tmobile_photo($maildir, $p->body); $tmobileflag = true; if (strstr($p->body, ERROR_CHECK)) { $this->out('<br />' . $p->body); return true; } } } } if ($blogflag) { if (trim($subject) == SPRINTPCS_IDENT_ALBUM || trim($subject) == SPRINTPCS_IDENT_PICTURE || trim($subject) == SPRINTPCS_IDENT_VIDEO || stristr($subject, CINGULAR_IDENT_PICTURE) || ($verizonflag and $subject == MF_MSG17) || ($tmobileflag and $subject == MF_MSG17)) { $time = strtotime($s->headers['date']); $stamp = $time == -1 ? date("l, F j, Y, g:ia") : date("l, F j, Y, g:ia", $time); $subject = MF_MSG23 . $stamp; } $msgbody = implode("<br />\n", $postbody); $msgbody .= implode("<br />\n", $postattach); //New draft post $entry = $this->workEntry($subject, $msgbody, $useAuthor, $postex, $cid, $s); } } elseif (strtolower($s->ctype_primary) == 'text') { // Email msg with no attachments if ($blogflag) { if (trim($subject) == SPRINTPCS_IDENT_ALBUM || trim($subject) == SPRINTPCS_IDENT_PICTURE || trim($subject) == SPRINTPCS_IDENT_VIDEO || stristr($subject, CINGULAR_IDENT_PICTURE) || (stristr($s->body, VERIZON_IDENT_PICTURE) and $subject == MF_MSG17) || ($tmobileflag and $subject == MF_MSG17)) { $time = strtotime($s->headers['date']); $stamp = $time == -1 ? date("l, F j, Y, g:ia") : date("l, F j, Y, g:ia", $time); $subject = MF_MSG23 . $stamp; } $bodytext = trim($this->decode($s->body, $s->ctype_parameters['charset'])); $entry = $this->workEntry($subject, $bodytext, $useAuthor, $postex, $cid, $s); } else { $this->out('<br />' . MF_MSG20); } } else { $this->out('<br />' . MF_MSG10 . '<br />'); } } echo '<br /><hr />'; }
/** * 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; }