b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (0.9.x) [ class tree: htsrv ] [ index: htsrv ] [ all elements ]

Source for file getmail.php

Documentation is available at getmail.php

  1. <?php
  2. /**
  3.  * pop3-2-b2 mail to blog
  4.  *
  5.  * b2evolution - {@link http://b2evolution.net/}
  6.  * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
  7.  * @copyright (c)2003-2005 by Francois PLANQUE - {@link http://fplanque.net/}
  8.  *  This file built upon code from original b2 - http://cafelog.com/
  9.  *
  10.  * @package htsrv
  11.  */
  12.  
  13. $output_debugging_info 0;        # =1 if you want to output debugging info
  14.  
  15. /**
  16.  * Initialize:
  17.  */
  18. require_once(dirname(__FILE__).'/../conf/_config.php');
  19. require_once(dirname(__FILE__)."/$htsrv_dirout/$core_subdir/_main.php");
  20. require_once(dirname(__FILE__)."/$htsrv_dirout/$core_subdir/_class_pop3.php");
  21.  
  22. if$use_phoneemail )
  23. // if you're using phone email, the email will already be in your timezone
  24.     $Settings->set('time_difference'0);
  25. }
  26.  
  27. // error_reporting( E_ALL );
  28.  
  29.  
  30. $pop3 new POP3();
  31.  
  32. echo T_('Connecting to pop server...')"<br />\n";
  33. if!$pop3->connect($mailserver_url$mailserver_port) )
  34. {
  35.     echo T_('Connection failed: ').$pop3->ERROR." <br />\n";
  36.     exit;
  37. }
  38.  
  39. echo T_('Logging into pop server...')"<br />\n";
  40. $Count $pop3->login$mailserver_login$mailserver_pass );
  41. if( (!$Count|| ($Count == -1) )
  42. {
  43.     echo T_('No mail or Login Failed:')" $pop3->ERROR <br />\n";
  44.     $pop3->quit();
  45.     exit;
  46. }
  47.  
  48.  
  49. // ONLY USE THIS IF YOUR PHP VERSION SUPPORTS IT! (PHP >= 3.0.4)
  50. #register_shutdown_function( $pop3->quit() );
  51.  
  52. for$iCount 1$iCount <= $Count$iCount++)
  53. {
  54.     printfT_('Getting message #%d...')."<br />\n"$iCount );
  55.     $MsgOne $pop3->get($iCount);
  56.     if((!$MsgOne|| (gettype($MsgOne!= 'array'))
  57.     {
  58.         echo $pop3->ERROR"<br />\n";
  59.         $pop3->quit();
  60.         exit;
  61.     }
  62.  
  63.     echo T_('Processing...')"<br />\n";
  64.     $content '';
  65.     $content_type '';
  66.     $boundary '';
  67.     $bodysignal 0;
  68.     $dmonths array('Jan''Feb''Mar''Apr''May''Jun''Jul''Aug''Sep''Oct''Nov''Dec');
  69.     
  70.     whilelist$lineNum$line each ($MsgOne) )
  71.     {
  72.         ifstrlen($line{
  73.             $bodysignal 1;
  74.         }
  75.         if ($bodysignal{
  76.             $content .= $line;
  77.         else {
  78.             if (preg_match('/Content-Type: /'$line)) {
  79.                 $content_type trim($line);
  80.                 $content_type substr($content_type14strlen($content_type)-14);
  81.                 $content_type explode(';'$content_type);
  82.                 $content_type $content_type[0];
  83.             }
  84.             if (($content_type == 'multipart/alternative'&& (preg_match('/boundary="/'$line)) && ($boundary == ''))
  85.             {
  86.                 $boundary trim($line);
  87.                 $boundary explode('"'$boundary);
  88.                 $boundary $boundary[1];
  89.             }
  90.             if (preg_match('/Subject: /'$line))
  91.             {
  92.                 $subject trim($line);
  93.                 $subject substr($subject9strlen($subject)-9);
  94.                 if ($use_phoneemail)
  95.                 {
  96.                     $subject explode($phoneemail_separator$subject);
  97.                     $subject trim($subject[0]);
  98.                 }
  99.                 if (!ereg($subjectprefix$subject))
  100.                 {
  101.                     continue;
  102.                 }
  103.             }
  104.             if (preg_match('/Date: /'$line))
  105.             // of the form '20 Mar 2002 20:32:37'
  106.                 $ddate trim($line);
  107.                 $ddate str_replace('Date: '''$ddate);
  108.                 if (strpos($ddate',')) {
  109.                     $ddate trim(substr($ddatestrpos($ddate',')+1strlen($ddate)));
  110.                 }
  111.                 $date_arr explode(' '$ddate);
  112.                 $date_time explode(':'$date_arr[3]);
  113.  
  114.                 $ddate_H $date_time[0];
  115.                 $ddate_i $date_time[1];
  116.                 $ddate_s $date_time[2];
  117.  
  118.                 $ddate_m $date_arr[1];
  119.                 $ddate_d $date_arr[0];
  120.                 $ddate_Y $date_arr[2];
  121.                 for ($i=0$i<12$i++{
  122.                     if ($ddate_m == $dmonths[$i]{
  123.                         $ddate_m $i+1;
  124.                     }
  125.                 }
  126.                 $ddate_U mktime($ddate_H$ddate_i$ddate_s$ddate_m$ddate_d$ddate_Y);
  127.                 $ddate_U $ddate_U ($Settings->get('time_difference'3600);
  128.                 $post_date date('Y-m-d H:i:s'$ddate_U);
  129.             }
  130.         }
  131.     }
  132.  
  133.     $ddate_today time(($Settings->get('time_difference'3600);
  134.     $ddate_difference_days ($ddate_today $ddate_U86400;
  135.  
  136.  
  137.     # starts buffering the output
  138.     ob_start();
  139.  
  140.     if ($ddate_difference_days 14)
  141.     {
  142.         echo T_('Too old')'<br />';
  143.         continue;
  144.     }
  145.  
  146.     if!preg_match('/'.$subjectprefix.'/'$subject))
  147.     {
  148.         echo T_('Subject prefix does not match').'.<br />';
  149.         continue;
  150.     }
  151.  
  152.     $userpassstring '';
  153.  
  154.     echo '<div style="border: 1px dashed #999; padding: 10px; margin: 10px;">';
  155.     echo "<p><strong>$iCount</strong></p><p><strong>Subject: </strong>$subject</p>\n";
  156.  
  157.     $subject trim(str_replace($subjectprefix''$subject));
  158.  
  159.     if ($content_type == 'multipart/alternative'{
  160.         $content explode('--'.$boundary$content);
  161.         $content $content[2];
  162.         $content explode('Content-Transfer-Encoding: quoted-printable'$content);
  163.         $content strip_tags($content[1]'<img><p><br><i><b><u><em><strong><strike><font><span><div>');
  164.     }
  165.     $content trim($content);
  166.  
  167.     echo "<p><strong>Content-type:</strong> $content_type, <strong>boundary:</strong> $boundary</p>\n";
  168.     echo '<p><strong>'T_('Raw content:')'</strong><br /><xmp>'$content'</xmp></p>';
  169.  
  170.     $btpos strpos($content$bodyterminator);
  171.     if ($btpos{
  172.         $content substr($content0$btpos);
  173.     }
  174.     $content trim($content);
  175.  
  176.     $blah explode("\n"$content);
  177.     $firstline $blah[0];
  178.  
  179.     if ($use_phoneemail)
  180.     {
  181.         $btpos strpos($firstline$phoneemail_separator);
  182.         if ($btpos{
  183.             $userpassstring trim(substr($firstline0$btpos));
  184.             $content trim(substr($content$btpos+strlen($phoneemail_separator)strlen($content)));
  185.             $btpos strpos($content$phoneemail_separator);
  186.             if ($btpos{
  187.                 $userpassstring trim(substr($content0$btpos));
  188.                 $content trim(substr($content$btpos+strlen($phoneemail_separator)strlen($content)));
  189.             }
  190.         }
  191.         $contentfirstline $blah[1];
  192.     }
  193.     else
  194.     {
  195.         $userpassstring $firstline;
  196.         $contentfirstline '';
  197.     }
  198.  
  199.     $blah explode(':'$userpassstring);
  200.     $user_login trim($blah[0]);
  201.     $user_pass @trim($blah[1]);
  202.  
  203.     $content $contentfirstline.str_replace($firstline''$content);
  204.     $content trim($content);
  205.  
  206.     echo '<p><strong>'T_('Login:')'</strong> '$user_login', <strong>'T_('Pass:')'</strong> '$user_pass'</p>';
  207.  
  208.     if!user_pass_ok$user_login$user_pass ) )
  209.     {
  210.         echo '<p><strong>'T_('Wrong login or password.')'</strong></p></div>';
  211.         continue;
  212.     }
  213.  
  214.     $userdata get_userdatabylogin($user_login);
  215.     $loop_User new User$userdata );
  216.  
  217.     // --- get infos from content -----------
  218.     $post_title xmlrpc_getposttitle($content);
  219.     if ($post_title == '')
  220.     {
  221.         $post_title $subject;
  222.     }
  223.  
  224.     if($post_category xmlrpc_getpostcategory($content) ) )
  225.     {
  226.         $post_category $default_category;
  227.     }
  228.     echo '<p><strong>'T_('Category ID')':</strong> ',$post_category,'</p>';
  229.  
  230.     $content xmlrpc_removepostdata$content );
  231.     
  232.     $blog_ID get_catblog($post_category)// TODO: should not die, if cat does not exist!
  233.     echo '<p><strong>'T_('Blog ID')':</strong> ',$blog_ID,'</p>';
  234.  
  235.     // Check permission:
  236.     if$loop_User->check_perm'blog_post_statuses''published'false$blog_ID ) )
  237.     {
  238.         echo "\n"T_('Permission denied.')'<br />';
  239.         continue;
  240.     }
  241.  
  242.     if (!$thisisforfunonly)
  243.     {
  244.         // CHECK and FORMAT content
  245.         $post_title format_to_posttrim($post_title)0);
  246.         $content format_to_posttrim($content)$Settings->get('AutoBR')0);
  247.  
  248.         iferrors_displayT_('Cannot post, please correct these errors:')'' ) )
  249.         {
  250.             $errors array();
  251.             echo '</div>';
  252.             continue;
  253.         }
  254.  
  255.         // INSERT NEW POST INTO DB:
  256.         $post_ID bpost_create$loop_User->ID$post_title$content$post_date$post_category,    array()'published'$loop_User->locale'',    $Settings->get('AutoBR')true );
  257.  
  258.         if (isset($sleep_after_edit&& $sleep_after_edit 0)
  259.         {
  260.             sleep($sleep_after_edit);
  261.         }
  262.  
  263.         $blogparams get_blogparams_by_ID$blog_ID );
  264.         pingbacktrue$content$post_title''$post_ID$blogparamstrue);
  265.         pingb2evonet$blogparams$post_ID$post_title);
  266.         pingWeblogs($blogparams);
  267.         pingBlogs($blogparams);
  268.         pingTechnorati($blogparams);
  269.     }
  270.     echo "\n<p><strong>"T_('Posted title')':</strong> '$post_title'<br />';
  271.     echo "\n<strong>"T_('Posted content')':</strong><br /><xmp>'$content'</xmp></p>';
  272.  
  273.     if(!$pop3->delete($iCount))
  274.     {
  275.         echo '<p>'$pop3->ERROR'</p></div>';
  276.         $pop3->reset();
  277.         exit;
  278.     }
  279.     else
  280.     {
  281.         echo '<p>'T_('Mission complete, message deleted.')'</p>';
  282.     }
  283.  
  284.     echo '</div>';
  285.     if ($output_debugging_info)
  286.     {
  287.         ob_end_flush();
  288.     }
  289.     else
  290.     {
  291.         ob_end_clean();
  292.     }
  293. }
  294.  
  295. echo T_('OK.')"<br />\n";
  296.  
  297. $pop3->quit();
  298.  
  299. timer_stop($output_debugging_info);
  300. exit;
  301.  
  302. ?>

Documentation generated on Tue, 20 May 2008 01:51:39 +0200 by phpDocumentor 1.4.2