File:  [mozdev] / cdn / www / b2mail.php
Revision 1.2: download - view: text, annotated - select for diffs - revision graph
Thu Mar 6 12:08:41 2003 UTC (16 years, 3 months ago) by cdn
Branches: MAIN
CVS tags: HEAD
..

    1: <?php
    2: 
    3: # pop3-2-b2 mail to blog
    4: # v0.3 20020716
    5: 
    6: require('b2config.php');
    7: require($b2inc.'/b2vars.php');
    8: require($b2inc.'/class.POP3.php');
    9: require($b2inc.'/b2functions.php');
   10: require($b2inc."/b2template.functions.php");
   11: require($b2inc."/xmlrpc.php");
   12: require($b2inc."/xmlrpcs.php");
   13: 
   14: dbconnect();
   15: timer_start();
   16: 
   17: $use_cache = 1;
   18: $output_debugging_info = 0;	# =1 if you want to output debugging info
   19: $autobr = get_settings('AutoBR');
   20: $time_difference = get_settings('time_difference');
   21: 
   22: if ($use_phoneemail) {
   23: 	// if you're using phone email, the email will already be in your timezone
   24: 	$time_difference = 0;
   25: }
   26: 
   27: error_reporting(2037);
   28: 
   29: 
   30: 
   31: $pop3 = new POP3();
   32: 
   33: if(!$pop3->connect($mailserver_url, $mailserver_port)) {
   34: 	echo "Ooops $pop3->ERROR <br />\n";
   35: 	exit;
   36: }
   37: 
   38: $Count = $pop3->login($mailserver_login, $mailserver_pass);
   39: if((!$Count) || ($Count == -1)) {
   40: 	echo "<h1>Login Failed: $pop3->ERROR</h1>\n";
   41: 	$pop3->quit();
   42: 	exit;
   43: }
   44: 
   45: 
   46: // ONLY USE THIS IF YOUR PHP VERSION SUPPORTS IT!
   47: //register_shutdown_function($pop3->quit());
   48: 
   49: for ($iCount=1; $iCount<=$Count; $iCount++) {
   50: 
   51: 	$MsgOne = $pop3->get($iCount);
   52: 	if((!$MsgOne) || (gettype($MsgOne) != 'array')) {
   53: 		echo "oops, $pop3->ERROR<br />\n";
   54: 		$pop3->quit();
   55: 		exit;
   56: 	}
   57: 
   58: 	$content = '';
   59: 	$content_type = '';
   60: 	$boundary = '';
   61: 	$bodysignal = 0;
   62: 	$dmonths = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
   63: 					 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
   64: 	while ( list ( $lineNum,$line ) = each ($MsgOne) ) {
   65: 		if (strlen($line) < 3) {
   66: 			$bodysignal = 1;
   67: 		}
   68: 		if ($bodysignal) {
   69: 			$content .= $line;
   70: 		} else {
   71: 			if (preg_match('/Content-Type: /', $line)) {
   72: 				$content_type = trim($line);
   73: 				$content_type = substr($content_type, 14, strlen($content_type)-14);
   74: 				$content_type = explode(';', $content_type);
   75: 				$content_type = $content_type[0];
   76: 			}
   77: 			if (($content_type == 'multipart/alternative') && (preg_match('/boundary="/', $line)) && ($boundary == '')) {
   78: 				$boundary = trim($line);
   79: 				$boundary = explode('"', $boundary);
   80: 				$boundary = $boundary[1];
   81: 			}
   82: 			if (preg_match('/Subject: /', $line)) {
   83: 				$subject = trim($line);
   84: 				$subject = substr($subject, 9, strlen($subject)-9);
   85: 				if ($use_phoneemail) {
   86: 					$subject = explode($phoneemail_separator, $subject);
   87: 					$subject = trim($subject[0]);
   88: 				}
   89: 				if (!ereg($subjectprefix, $subject)) {
   90: 					continue;
   91: 				}
   92: 			}
   93: 			if (preg_match('/Date: /', $line)) { // of the form '20 Mar 2002 20:32:37'
   94: 				$ddate = trim($line);
   95: 				$ddate = str_replace('Date: ', '', $ddate);
   96: 				if (strpos($ddate, ',')) {
   97: 					$ddate = trim(substr($ddate, strpos($ddate, ',')+1, strlen($ddate)));
   98: 				}
   99: 				$date_arr = explode(' ', $ddate);
  100: 				$date_time = explode(':', $date_arr[3]);
  101: 				
  102: 				$ddate_H = $date_time[0];
  103: 				$ddate_i = $date_time[1];
  104: 				$ddate_s = $date_time[2];
  105: 				
  106: 				$ddate_m = $date_arr[1];
  107: 				$ddate_d = $date_arr[0];
  108: 				$ddate_Y = $date_arr[2];
  109: 				for ($i=0; $i<12; $i++) {
  110: 					if ($ddate_m == $dmonths[$i]) {
  111: 						$ddate_m = $i+1;
  112: 					}
  113: 				}
  114: 				$ddate_U = mktime($ddate_H, $ddate_i, $ddate_s, $ddate_m, $ddate_d, $ddate_Y);
  115: 				$ddate_U = $ddate_U + ($time_difference * 3600);
  116: 				$post_date = date('Y-m-d H:i:s', $ddate_U);
  117: 			}
  118: 		}
  119: 	}
  120: 
  121: 	$ddate_today = time() + ($time_difference * 3600);
  122: 	$ddate_difference_days = ($ddate_today - $ddate_U) / 86400;
  123: 
  124: 
  125: 	# starts buffering the output
  126: 	ob_start();
  127: 
  128: 	if ($ddate_difference_days > 14) {
  129: 		echo 'too old<br />';
  130: 		continue;
  131: 	}
  132: 
  133: 	if (preg_match('/'.$subjectprefix.'/', $subject)) {
  134: 
  135: 		$userpassstring = '';
  136: 
  137: 		echo '<div style="border: 1px dashed #999; padding: 10px; margin: 10px;">';
  138: 		echo "<p><b>$iCount</b></p><p><b>Subject: </b>$subject</p>\n";
  139: 
  140: 		$subject = trim(str_replace($subjectprefix, '', $subject));
  141: 
  142: 		if ($content_type == 'multipart/alternative') {
  143: 			$content = explode('--'.$boundary, $content);
  144: 			$content = $content[2];
  145: 			$content = explode('Content-Transfer-Encoding: quoted-printable', $content);
  146: 			$content = strip_tags($content[1], '<img><p><br><i><b><u><em><strong><strike><font><span><div>');
  147: 		}
  148: 		$content = trim($content);
  149: 
  150: 		echo "<p><b>Content-type:</b> $content_type, <b>boundary:</b> $boundary</p>\n";
  151: 		echo "<p><b>Raw content:</b><br /><xmp>".$content.'</xmp></p>';
  152: 		
  153: 		$btpos = strpos($content, $bodyterminator);
  154: 		if ($btpos) {
  155: 			$content = substr($content, 0, $btpos);
  156: 		}
  157: 		$content = trim($content);
  158: 
  159: 		$blah = explode("\n", $content);
  160: 		$firstline = $blah[0];
  161: 
  162: 		if ($use_phoneemail) {
  163: 			$btpos = strpos($firstline, $phoneemail_separator);
  164: 			if ($btpos) {
  165: 				$userpassstring = trim(substr($firstline, 0, $btpos));
  166: 				$content = trim(substr($content, $btpos+strlen($phoneemail_separator), strlen($content)));
  167: 				$btpos = strpos($content, $phoneemail_separator);
  168: 				if ($btpos) {
  169: 					$userpassstring = trim(substr($content, 0, $btpos));
  170: 					$content = trim(substr($content, $btpos+strlen($phoneemail_separator), strlen($content)));
  171: 				}
  172: 			}
  173: 			$contentfirstline = $blah[1];
  174: 		} else {
  175: 			$userpassstring = $firstline;
  176: 			$contentfirstline = '';
  177: 		}
  178: 
  179: 		$blah = explode(':', $userpassstring);
  180: 		$user_login = $blah[0];
  181: 		$user_pass = $blah[1];
  182: 
  183: 		$content = $contentfirstline.str_replace($firstline, '', $content);
  184: 		$content = trim($content);
  185: 
  186: 		echo "<p><b>Login:</b> $user_login, <b>Pass:</b> $user_pass</p>";
  187: 
  188: 		$sql = "SELECT ID, user_level FROM $tableusers WHERE user_login='$user_login' AND user_pass='$user_pass' ORDER BY ID DESC LIMIT 1";
  189: 		$result = mysql_query($sql);
  190: 
  191: 		if (!mysql_num_rows($result)) {
  192: 			echo '<p><b>Wrong login or password.</b></p></div>';
  193: 			continue;
  194: 		}
  195: 
  196: 		$row = mysql_fetch_object($result);
  197: 		$user_level = $row->user_level;
  198: 		$post_author = $row->ID;
  199: 
  200: 		if ($user_level > 0) {
  201: 
  202: 			$post_title = xmlrpc_getposttitle($content);
  203: 			$post_category = xmlrpc_getpostcategory($content);
  204: 
  205: 			if ($post_title == '') {
  206: 				$post_title = $subject;
  207: 			}
  208: 			if ($post_category == '') {
  209: 				$post_category = $default_category;
  210: 			}
  211: 
  212: 			if ($autobr) {
  213: 				$content = autobrize($content);
  214: 			}
  215: 
  216: 			if (!$thisisforfunonly) {
  217: 				$post_title = addslashes(trim($post_title));
  218: 				$content = addslashes(trim($content));
  219: 				$sql = "INSERT INTO $tableposts (post_author, post_date, post_content, post_title, post_category) VALUES ($post_author, '$post_date', '$content', '$post_title', $post_category)";
  220: 				$result = mysql_query($sql) or die('Couldn\'t add post: '.mysql_error());
  221: 				$post_ID = mysql_insert_id();
  222: 
  223: 				if (isset($sleep_after_edit) && $sleep_after_edit > 0) {
  224: 					sleep($sleep_after_edit);
  225: 				}
  226: 
  227: 				$blog_ID = 1;
  228: 				rss_update($blog_ID);
  229: 				pingWeblogs($blog_ID);
  230: 				pingCafelog($cafelogID, $post_title, $post_ID);
  231: 				pingBlogs($blog_ID);
  232: 				pingback($content, $post_ID);
  233: 			}
  234: 			echo "\n<p><b>Posted title:</b> $post_title<br />";
  235: 			echo "\n<b>Posted content:</b><br /><xmp>".$content.'</xmp></p>';
  236: 
  237: 			if(!$pop3->delete($iCount)) {
  238: 				echo '<p>oops '.$pop3->ERROR.'</p></div>';
  239: 				$pop3->reset();
  240: 				exit;
  241: 			} else {
  242: 				echo "<p>Mission complete, message <b>$iCount</b> deleted </p>";
  243: 			}
  244: 
  245: 		} else {
  246: 			echo '<p><b>Level 0 users can\'t post.</b></p>';
  247: 		}
  248: 		echo '</div>';
  249: 		if ($output_debugging_info) {
  250: 			ob_end_flush();
  251: 		} else {
  252: 			ob_end_clean();
  253: 		}
  254: 	}
  255: }
  256: 
  257: $pop3->quit();
  258: 
  259: timer_stop($output_debugging_info);
  260: exit;
  261: 
  262: ?>

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>