Source for file getmail.php
Documentation is available at getmail.php
* b2evolution - {@link http://b2evolution.net/}
* Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
* @copyright (c)2003-2005 by Francois PLANQUE - {@link http://fplanque.net/}
* This file built upon code from original b2 - http://cafelog.com/
$output_debugging_info =
0; # =1 if you want to output debugging info
require_once(dirname(__FILE__
).
'/../conf/_config.php');
require_once(dirname(__FILE__
).
"/
$htsrv_dirout/
$core_subdir/_main.php
");
require_once(dirname(__FILE__
).
"/
$htsrv_dirout/
$core_subdir/_class_pop3.php
");
{ // if you're using phone email, the email will already be in your timezone
$Settings->set('time_difference', 0);
// error_reporting( E_ALL );
echo
T_('Connecting to pop server...'), "<br />\n";
if( !$pop3->connect($mailserver_url, $mailserver_port) )
echo
T_('Connection failed: ').
$pop3->ERROR.
" <br />\n";
echo
T_('Logging into pop server...'), "<br />\n";
$Count =
$pop3->login( $mailserver_login, $mailserver_pass );
if( (!$Count) ||
($Count == -
1) )
echo
T_('No mail or Login Failed:'), " $pop3->ERROR <br />\n";
// ONLY USE THIS IF YOUR PHP VERSION SUPPORTS IT! (PHP >= 3.0.4)
#register_shutdown_function( $pop3->quit() );
for( $iCount =
1; $iCount <=
$Count; $iCount++
)
printf( T_('Getting message #%d...').
"<br />\n", $iCount );
$MsgOne =
$pop3->get($iCount);
if((!$MsgOne) ||
(gettype($MsgOne) !=
'array'))
echo
$pop3->ERROR, "<br />\n";
echo
T_('Processing...'), "<br />\n";
$dmonths =
array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
while( list
( $lineNum, $line ) =
each ($MsgOne) )
$content_type =
trim($line);
$content_type =
substr($content_type, 14, strlen($content_type)-
14);
$content_type =
explode(';', $content_type);
$content_type =
$content_type[0];
if (($content_type ==
'multipart/alternative') &&
(preg_match('/boundary="/', $line)) &&
($boundary ==
''))
$boundary =
explode('"', $boundary);
$boundary =
$boundary[1];
$subject =
explode($phoneemail_separator, $subject);
$subject =
trim($subject[0]);
if (!ereg($subjectprefix, $subject))
{ // of the form '20 Mar 2002 20:32:37'
$date_time =
explode(':', $date_arr[3]);
$ddate_H =
$date_time[0];
$ddate_i =
$date_time[1];
$ddate_s =
$date_time[2];
for ($i=
0; $i<
12; $i++
) {
if ($ddate_m ==
$dmonths[$i]) {
$ddate_U =
mktime($ddate_H, $ddate_i, $ddate_s, $ddate_m, $ddate_d, $ddate_Y);
$ddate_U =
$ddate_U +
($Settings->get('time_difference') *
3600);
$post_date =
date('Y-m-d H:i:s', $ddate_U);
$ddate_today =
time() +
($Settings->get('time_difference') *
3600);
$ddate_difference_days =
($ddate_today -
$ddate_U) /
86400;
# starts buffering the output
if ($ddate_difference_days >
14)
echo
T_('Too old'), '<br />';
if( !preg_match('/'.
$subjectprefix.
'/', $subject))
echo
T_('Subject prefix does not match').
'.<br />';
echo
'<div style="border: 1px dashed #999; padding: 10px; margin: 10px;">';
echo
"<p><strong>$iCount</strong></p><p><strong>Subject: </strong>$subject</p>\n";
if ($content_type ==
'multipart/alternative') {
$content =
explode('--'.
$boundary, $content);
$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>');
$content =
trim($content);
echo
"<p><strong>Content-type:</strong> $content_type, <strong>boundary:</strong> $boundary</p>\n";
echo
'<p><strong>', T_('Raw content:'), '</strong><br /><xmp>', $content, '</xmp></p>';
$btpos =
strpos($content, $bodyterminator);
$content =
substr($content, 0, $btpos);
$content =
trim($content);
$btpos =
strpos($firstline, $phoneemail_separator);
$userpassstring =
trim(substr($firstline, 0, $btpos));
$btpos =
strpos($content, $phoneemail_separator);
$userpassstring =
trim(substr($content, 0, $btpos));
$contentfirstline =
$blah[1];
$userpassstring =
$firstline;
$blah =
explode(':', $userpassstring);
$user_login =
trim($blah[0]);
$user_pass =
@trim($blah[1]);
$content =
$contentfirstline.
str_replace($firstline, '', $content);
$content =
trim($content);
echo
'<p><strong>', T_('Login:'), '</strong> ', $user_login, ', <strong>', T_('Pass:'), '</strong> ', $user_pass, '</p>';
echo
'<p><strong>', T_('Wrong login or password.'), '</strong></p></div>';
$loop_User =
& new User( $userdata );
// --- get infos from content -----------
$post_category =
$default_category;
echo
'<p><strong>', T_('Category ID'), ':</strong> ',$post_category,'</p>';
$blog_ID =
get_catblog($post_category); // TODO: should not die, if cat does not exist!
echo
'<p><strong>', T_('Blog ID'), ':</strong> ',$blog_ID,'</p>';
if( ! $loop_User->check_perm( 'blog_post_statuses', 'published', false, $blog_ID ) )
echo
"\n", T_('Permission denied.'), '<br />';
// CHECK and FORMAT content
// INSERT NEW POST INTO DB:
$post_ID =
bpost_create( $loop_User->ID, $post_title, $content, $post_date, $post_category, array(), 'published', $loop_User->locale, '', $Settings->get('AutoBR'), true );
if (isset
($sleep_after_edit) &&
$sleep_after_edit >
0)
sleep($sleep_after_edit);
pingback( true, $content, $post_title, '', $post_ID, $blogparams, true);
echo
"\n<p><strong>", T_('Posted title'), ':</strong> ', $post_title, '<br />';
echo
"\n<strong>", T_('Posted content'), ':</strong><br /><xmp>', $content, '</xmp></p>';
if(!$pop3->delete($iCount))
echo
'<p>', $pop3->ERROR, '</p></div>';
echo
'<p>', T_('Mission complete, message deleted.'), '</p>';
if ($output_debugging_info)
echo
T_('OK.'), "<br />\n";