Changeset 1153

Show
Ignore:
Timestamp:
04/24/04 22:43:47 (4 years ago)
Author:
saxmatt
Message:

New mail functionality.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/wp-mail.php

    r1150 r1153  
    44require_once(ABSPATH.WPINC.'/class-pop3.php'); 
    55 
    6  
    7 timer_start(); 
    8  
    9 $output_debugging_info = 0; # =1 if you want to output debugging info 
    10  
    11 if (get_settings('use_phoneemail')) { 
    12     // if you're using phone email, the email will already be in your timezone 
    13     $time_difference = 0; 
    14 } 
    15  
    166error_reporting(2037); 
    17  
    18  
    197 
    208$pop3 = new POP3(); 
    219 
    22 if(!$pop3->connect(get_settings('mailserver_url'), get_settings('mailserver_port'))) { 
     10if (!$pop3->connect(get_settings('mailserver_url'), get_settings('mailserver_port'))) : 
    2311    echo "Ooops $pop3->ERROR <br />\n"; 
    2412    exit; 
    25 
     13endif; 
    2614 
    27 $Count = $pop3->login(get_settings('mailserver_login'), get_settings('mailserver_pass')); 
    28 if((!$Count) || ($Count == -1)) { 
    29     echo "<h1>Login Failed: $pop3->ERROR</h1>\n"; 
    30     $pop3->quit(); 
    31     exit; 
    32 
     15$count = $pop3->login(get_settings('mailserver_login'), get_settings('mailserver_pass')); 
     16if (0 == $count) die(__('There doesn&#8217;t seem to be any new mail.')); 
    3317 
    3418 
    35 // ONLY USE THIS IF YOUR PHP VERSION SUPPORTS IT! 
    36 //register_shutdown_function($pop3->quit()); 
     19for ($i=1; $i <= $count; $i++) : 
    3720 
    38 for ($iCount=1; $iCount<=$Count; $iCount++) { 
     21    $message = $pop3->get($i); 
    3922 
    40     $MsgOne = $pop3->get($iCount); 
    41     if((!$MsgOne) || (gettype($MsgOne) != 'array')) { 
    42         echo "oops, $pop3->ERROR<br />\n"; 
    43         $pop3->quit(); 
     23    if(!$pop3->delete($i)) { 
     24        echo '<p>Oops '.$pop3->ERROR.'</p></div>'; 
     25        $pop3->reset(); 
    4426        exit; 
     27    } else { 
     28        echo "<p>Mission complete, message <strong>$i</strong> deleted.</p>"; 
    4529    } 
    4630 
     
    5135    $dmonths = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 
    5236                     'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'); 
    53     while ( list ( $lineNum,$line ) = each ($MsgOne) ) { 
    54         if (strlen($line) < 3) { 
    55             $bodysignal = 1; 
    56         } 
     37    foreach ($message as $line) : 
     38        if (strlen($line) < 3) $bodysignal = 1; 
     39 
    5740        if ($bodysignal) { 
    5841            $content .= $line; 
     
    7457                if (!preg_match('#\=\?(.+)\?Q\?(.+)\?\=#i', $subject)) { 
    7558                  $subject = wp_iso_descrambler($subject); 
    76                 } 
    77                 if (get_settings('use_phoneemail')) { 
    78                     $subject = explode(get_settings('phoneemail_separator'), $subject); 
    79                     $subject = trim($subject[0]); 
    80                 } 
    81                 if (!ereg(get_settings('subjectprefix'), $subject)) { 
    82                     continue; 
    8359                } 
    8460            } 
     
    11086            } 
    11187        } 
    112     } 
     88    endforeach; 
    11389 
    11490    $ddate_today = time() + ($time_difference * 3600); 
     
    11692 
    11793 
    118     # starts buffering the output 
    119     ob_start(); 
     94    $subject = trim(str_replace(get_settings('subjectprefix'), '', $subject)); 
    12095 
    121     if ($ddate_difference_days > 14) { 
    122         echo 'Too old<br />'; 
    123         continue; 
     96    if ($content_type == 'multipart/alternative') { 
     97        $content = explode('--'.$boundary, $content); 
     98        $content = $content[2]; 
     99        $content = explode('Content-Transfer-Encoding: quoted-printable', $content); 
     100        $content = strip_tags($content[1], '<img><p><br><i><b><u><em><strong><strike><font><span><div>'); 
    124101    } 
     102    $content = trim($content); 
    125103 
    126     if (preg_match('/'.get_settings('subjectprefix').'/', $subject)) { 
     104    echo "<p><b>Content-type:</b> $content_type, <b>boundary:</b> $boundary</p>\n"; 
     105    echo "<p><b>Raw content:</b><br /><pre>".$content.'</pre></p>'; 
    127106 
    128        $userpassstring = ''
     107    $content = trim($content)
    129108 
    130         echo '<div style="border: 1px dashed #999; padding: 10px; margin: 10px;">'; 
    131         echo "<p><b>$iCount</b></p><p><b>Subject: </b>$subject</p>\n"; 
     109    $content = trim($content); 
    132110 
    133        $subject = trim(str_replace(get_settings('subjectprefix'), '', $subject)); 
     111    $post_title = xmlrpc_getposttitle($content); 
    134112 
    135         if ($content_type == 'multipart/alternative') { 
    136             $content = explode('--'.$boundary, $content); 
    137             $content = $content[2]; 
    138             $content = explode('Content-Transfer-Encoding: quoted-printable', $content); 
    139             $content = strip_tags($content[1], '<img><p><br><i><b><u><em><strong><strike><font><span><div>'); 
    140         } 
    141         $content = trim($content); 
     113    if ($post_title == '') $post_title = $subject; 
    142114 
    143         echo "<p><b>Content-type:</b> $content_type, <b>boundary:</b> $boundary</p>\n"; 
    144         echo "<p><b>Raw content:</b><br /><pre>".$content.'</pre></p>'; 
    145          
    146         $btpos = strpos($content, get_settings('bodyterminator')); 
    147         if ($btpos) { 
    148             $content = substr($content, 0, $btpos); 
    149         } 
    150         $content = trim($content); 
     115    if (empty($post_categories)) $post_categories[] = get_settings('default_category'); 
    151116 
    152        $blah = explode("\n", $content); 
    153        $firstline = $blah[0]
    154        $secondline = $blah[1]
     117    $post_title = addslashes(trim($post_title)); 
     118    $content = preg_replace("|\n([^\n])|", " $1", $content)
     119    $content = addslashes(trim($content))
    155120 
    156         if (get_settings('use_phoneemail')) { 
    157             $btpos = strpos($firstline, get_settings('phoneemail_separator')); 
    158             if ($btpos) { 
    159                 $userpassstring = trim(substr($firstline, 0, $btpos)); 
    160                 $content = trim(substr($content, $btpos+strlen(get_settings('phoneemail_separator')), strlen($content))); 
    161                 $btpos = strpos($content, get_settings('phoneemail_separator')); 
    162                 if ($btpos) { 
    163                     $userpassstring = trim(substr($content, 0, $btpos)); 
    164                     $content = trim(substr($content, $btpos+strlen(get_settings('phoneemail_separator')), strlen($content))); 
    165                 } 
    166             } 
    167             $contentfirstline = $blah[1]; 
    168         } else { 
    169             $userpassstring = $firstline; 
    170             $contentfirstline = ''; 
    171         } 
    172121 
    173         $flat = 999.0; 
    174         $flon = 999.0; 
    175         $secondlineParts = explode(':',$secondline); 
    176         if(strncmp($secondlineParts[0],"POS",3)==0) { 
    177             echo "Found POS:<br>\n"; 
    178             //echo "Second parts is:".$secondlineParts[1]; 
    179             // the second line is the postion listing line 
    180             $secLineParts = explode(',',$secondlineParts[1]); 
    181             $flatStr = $secLineParts[0]; 
    182             $flonStr = $secLineParts[1]; 
    183             //echo "String are ".$flatStr.$flonStr;  
    184             $flat = floatval($secLineParts[0]); 
    185             $flon = floatval($secLineParts[1]); 
    186             //echo "values are ".$flat." and ".$flon; 
    187             // ok remove that position... we should not have it in the final output 
    188             $content = str_replace($secondline,'',$content); 
    189         } 
     122    $sql = "INSERT INTO $tableposts (post_author, post_date, post_date_gmt, post_content, post_title, post_modified, post_modified_gmt) VALUES (1, '$post_date', '$post_date_gmt', '$content', '$post_title', '$post_date', '$post_date_gmt')"; 
    190123 
    191         $blah = explode(':', $userpassstring); 
    192         $user_login = $blah[0]; 
    193         $user_pass = md5($blah[1]); 
     124    $result = $wpdb->query($sql); 
     125    $post_ID = $wpdb->insert_id; 
    194126 
    195         $content = $contentfirstline.str_replace($firstline, '', $content); 
    196         $content = trim($content); 
    197127 
    198        echo "<p><b>Login:</b> $user_login, <b>Pass:</b> $user_pass</p>"
     128    pingback($content, $post_ID)
    199129 
    200        $sql = "SELECT ID, user_level FROM $tableusers WHERE user_login='$user_login' AND user_pass='$user_pass' ORDER BY ID DESC LIMIT 1"; 
    201        $result = $wpdb->get_row($sql)
     130    echo "\n<p><b>Posted title:</b> $post_title<br />"; 
     131    echo "\n<b>Posted content:</b><br /><pre>".$content.'</pre></p>'
    202132 
    203         if (!$result) { 
    204             echo '<p><b>Wrong login or password.</b></p></div>'; 
    205             continue; 
    206         } 
     133if (!$post_categories) $post_categories[] = 1; 
     134foreach ($post_categories as $post_category) : 
     135    $post_category = intval($post_category); 
    207136 
    208        $user_level = $result->user_level; 
    209        $post_author = $result->ID
     137    // Double check it's not there already 
     138    $exists = $wpdb->get_row("SELECT * FROM $tablepost2cat WHERE post_id = $post_ID AND category_id = $post_category")
    210139 
    211         if ($user_level > 0) { 
     140     if (!$exists && $result) {  
     141        $wpdb->query(" 
     142        INSERT INTO $tablepost2cat 
     143        (post_id, category_id) 
     144        VALUES 
     145        ($post_ID, $post_category) 
     146        "); 
     147    } 
     148endforeach; 
    212149 
    213             $post_title = xmlrpc_getposttitle($content); 
    214             $post_categories[] = xmlrpc_getpostcategory($content); 
    215  
    216             if ($post_title == '') { 
    217                 $post_title = $subject; 
    218             } 
    219             if (empty($post_categories)) { 
    220                 $post_categories[] = get_settings('default_category'); 
    221             } 
    222  
    223             if (!$thisisforfunonly) { 
    224                 $post_title = addslashes(trim($post_title)); 
    225                 $content = preg_replace("|\n([^\n])|", " $1", $content); 
    226                 $content = addslashes(trim($content)); 
    227                 if($flat > 500) { 
    228                     $sql = "INSERT INTO $tableposts (post_author, post_date, post_date_gmt, post_content, post_title, post_modified, post_modified_gmt) VALUES ($post_author, '$post_date', '$post_date_gmt', '$content', '$post_title', '$post_date', '$post_date_gmt')"; 
    229                 } else { 
    230                     $sql = "INSERT INTO $tableposts (post_author, post_date, post_date_gmt, post_content, post_title, post_modified, post_modified_gmt, post_lat, post_lon) VALUES ($post_author, '$post_date', '$post_date_gmt', '$content', '$post_title', '$post_date', '$post_date_gmt', $flat, $flon)"; 
    231                 } 
    232                 $result = $wpdb->query($sql); 
    233                 $post_ID = $wpdb->insert_id; 
    234  
    235                 if (isset($sleep_after_edit) && $sleep_after_edit > 0) { 
    236                     sleep($sleep_after_edit); 
    237                 } 
    238  
    239                 $blog_ID = 1; 
    240                 if($flat < 500) { 
    241                     pingGeoUrl($post_ID);    
    242                 } 
    243  
    244                 pingback($content, $post_ID); 
    245             } 
    246             echo "\n<p><b>Posted title:</b> $post_title<br />"; 
    247             echo "\n<b>Posted content:</b><br /><pre>".$content.'</pre></p>'; 
    248  
    249         if (!$post_categories) $post_categories[] = 1; 
    250         foreach ($post_categories as $post_category) { 
    251             $post_category = intval($post_category); 
    252  
    253             // Double check it's not there already 
    254             $exists = $wpdb->get_row("SELECT * FROM $tablepost2cat WHERE post_id = $post_ID AND category_id = $post_category"); 
    255  
    256              if (!$exists && $result) {  
    257                 $wpdb->query(" 
    258                 INSERT INTO $tablepost2cat 
    259                 (post_id, category_id) 
    260                 VALUES 
    261                 ($post_ID, $post_category) 
    262                 "); 
    263             } 
    264         } 
    265  
    266             if(!$pop3->delete($iCount)) { 
    267                 echo '<p>Oops '.$pop3->ERROR.'</p></div>'; 
    268                 $pop3->reset(); 
    269                 exit; 
    270             } else { 
    271                 echo "<p>Mission complete, message <strong>$iCount</strong> deleted.</p>"; 
    272             } 
    273  
    274         } else { 
    275             echo '<p><strong>Level 0 users can\'t post.</strong></p>'; 
    276         } 
    277         echo '</div>'; 
    278         if ($output_debugging_info) { 
    279             ob_end_flush(); 
    280         } else { 
    281             ob_end_clean(); 
    282         } 
    283     } 
    284 
     150endfor; 
    285151 
    286152$pop3->quit(); 
    287153 
    288 timer_stop($output_debugging_info); 
    289 exit; 
    290  
    291154?>