View Single Post
  #28  
Old 04-12-2001, 10:44 AM
chrispadfield's Avatar
chrispadfield chrispadfield is offline
 
Join Date: Oct 2001
Posts: 180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

i did start this a while ago, and got somewhere but not very far. Just in case this is any use to James:

PHP Code:
<?

require("./admin/global.php");

 function pop3_open($server, $port)  
  {
    global $POP3_GLOBAL_STATUS;

    $pop3 = fsockopen($server, $port);

    // Maybe some people need something like:
    // $pop3 = fsockopen($server, $port, &$errno, &$errstr, 30);
    
    if ($pop3 <= 0) return 0;

    $line = fgets($pop3, 1024);
        $POP3_GLOBAL_STATUS[$pop3]["LASTRESULT"] = substr($line, 0, 1);
        $POP3_GLOBAL_STATUS[$pop3]["LASTRESULTTXT"] = substr($line, 0, 1024);

    if ($POP3_GLOBAL_STATUS[$pop3]["LASTRESULT"] <> "+") return 0;

    return $pop3;
  }

  function pop3_user($pop3, $user)
  {
    global $POP3_GLOBAL_STATUS;

    fputs($pop3, "USER $user\r\n");
    $line = fgets($pop3, 1024);
        $POP3_GLOBAL_STATUS[$pop3]["LASTRESULT"] = substr($line, 0, 1);
        $POP3_GLOBAL_STATUS[$pop3]["LASTRESULTTXT"] = substr($line, 0, 1024);
    
    if ($POP3_GLOBAL_STATUS[$pop3]["LASTRESULT"] <> "+") return 0;

    return 1;
  }

  function pop3_pass($pop3, $pass)
  {
    global $POP3_GLOBAL_STATUS;

    fputs($pop3, "PASS $pass\r\n");
    $line = fgets($pop3, 1024);
        $POP3_GLOBAL_STATUS[$pop3]["LASTRESULT"] = substr($line, 0, 1);
        $POP3_GLOBAL_STATUS[$pop3]["LASTRESULTTXT"] = substr($line, 0, 1024);
    
    if ($POP3_GLOBAL_STATUS[$pop3]["LASTRESULT"] <> "+") return 0;

    return 1;
  }
  
  function pop3_stat($pop3)
  {
    global $POP3_GLOBAL_STATUS;

    fputs($pop3, "STAT\r\n");
    $line = fgets($pop3, 1024);
        $POP3_GLOBAL_STATUS[$pop3]["LASTRESULT"] = substr($line, 0, 1);
        $POP3_GLOBAL_STATUS[$pop3]["LASTRESULTTXT"] = substr($line, 0, 1024);

        if ($POP3_GLOBAL_STATUS[$pop3]["LASTRESULT"] <> "+") return 0;

    if (!eregi("+OK (.*) (.*)", $line, $regs)) 
        return 0;

    return $regs[1];
  }

  function pop3_list($pop3)
  {    
        global $POP3_GLOBAL_STATUS;
  
        fputs($pop3, "LIST\r\n");
        $line = fgets($pop3, 1024);
        $POP3_GLOBAL_STATUS[$pop3]["LASTRESULT"] = substr($line, 0, 1);
        $POP3_GLOBAL_STATUS[$pop3]["LASTRESULTTXT"] = substr($line, 0, 1024);

        if ($POP3_GLOBAL_STATUS[$pop3]["LASTRESULT"] <> "+") return 0;

    $i = 0;
    while  (substr($line  =  fgets($pop3, 1024),  0,  1)  <>  ".")
    {
        $articles[$i] = $line;
        $i++;
    }
    $articles["count"] = $i;

    return $articles;
  }

  function pop3_retr($pop3, $nr)
  {
        global $POP3_GLOBAL_STATUS;
  
        fputs($pop3, "RETR $nr\r\n");
        $line = fgets($pop3, 1024);
        $POP3_GLOBAL_STATUS[$pop3]["LASTRESULT"] = substr($line, 0, 1);
        $POP3_GLOBAL_STATUS[$pop3]["LASTRESULTTXT"] = substr($line, 0, 1024);

        if ($POP3_GLOBAL_STATUS[$pop3]["LASTRESULT"] <> "+") return 0;

    $i = 0;
        while  (substr($line  =  fgets($pop3, 1024),  0)  !=  ".\r\n")
        {
                $data[$i] = $line;
                $i++;
        }
        $data["count"] = $i;

        return $data;
  }


  function pop3_dele($pop3, $nr)
  {
        global $POP3_GLOBAL_STATUS;

        fputs($pop3, "DELE $nr\r\n");
        $line = fgets($pop3, 1024);
        $POP3_GLOBAL_STATUS[$pop3]["LASTRESULT"] = substr($line, 0, 1);
        $POP3_GLOBAL_STATUS[$pop3]["LASTRESULTTXT"] = substr($line, 0, 1024);

        if ($POP3_GLOBAL_STATUS[$pop3]["LASTRESULT"] <> "+") return 0;


        return 1;
  }

  function pop3_quit($pop3)
  {
        global $POP3_GLOBAL_STATUS;

        fputs($pop3, "QUIT\r\n");
        $line = fgets($pop3, 1024);
        $POP3_GLOBAL_STATUS[$pop3]["LASTRESULT"] = substr($line, 0, 1);
        $POP3_GLOBAL_STATUS[$pop3]["LASTRESULTTXT"] = substr($line, 0, 1024);

        if ($POP3_GLOBAL_STATUS[$pop3]["LASTRESULT"] <> "+") return 0;

        return 1;
  }
  
  
// end of class.. this is where it starts :)



### CONNECT TO POP3 SERVER


// so we are connecting
 $pop3 = pop3_open("mail.techuk.com", "110");
 if (!$pop3) {
    printf("[ERROR] Failed to connect to localhost<BR>\n");
    return 0;
 }
 
// with thus username 
 if (!pop3_user($pop3, "testing@ascifi.com")) {
    printf("[ERROR] Username failed!<BR>\n");
    return 0;
 }
 
 // and this password
 if (!pop3_pass($pop3, "****")) {
    printf("[ERROR] PASS failed!<BR>\n");
    return 0;
 }
 
 
### END OF CONNECTION


### FIND OUT HOW MANY ARTICLES - FUTURE LOOP

// finding out how many articles there are. if none giving error message i think
 $articles = pop3_list($pop3);
 if (!$articles) {
    printf("[ERROR] LIST failed!<BR>\n");
    return 0;
 }
 
 
$listit = pop3_list($pop3);

$numrows = count ($listit);
for ($count = 0; $count < $numrows; ++$count) {

echo HtmlSpecialChars($listit[$count]);
echo "<br>";
}
  
  
### END OF ARTICLE COLLECTION
 
// re-fresh $count 
$count = 0;  

### PROCESS THE EMAIL ###

// first lets retrieve the email
$data = pop3_retr($pop3, 8);

// start loop on email array
$numrows = count ($data);
for ($count = 0; $count < $numrows; ++$count) {

// create variables from the whole message
$message .= HtmlSpecialChars($data[$count]);
$message_html .= HtmlSpecialChars($data[$count]);
$message_html .= "<br>";

// check to see if divide, if so tell script we are no dealing with the body
if ($data[$count] == "\r\n") {
$stop = "1";
}


## we are doing header stuff here ##
if ($stop != "1") {
$header2 .= $data[$count];

// first lets get the subject

if (eregi("Subject:", $data[$count], $arr)) {
$subject = substr($data[$count],9);

echo "<b>have found the subject</b><br>";
} else {
echo "failed to find the subject<br>";
}

// second the return email address

$foo = 'From: "Chris Padfield" <chris@freeontheweb.com>';

if (eregi("<([^>]*)>",$data[$count],$arr)) {
$email = $arr[1];

echo "<b>have got email</b><br>";
} else {
echo "failed to get email<br>";
}

## now we are creating the body ##
} elseif ($stop == "1") {


$body2 .=$data[$count];
}


// end the email array loop
}

### EMAIL HAS BEEN PROCESSED ###


### CHECK TO SEE IF USER IS BANNED ###

// first check to see if this user has been banned.

if ($email == "banned") {

echo "sorry.. you are banned ....";

} elseif ($ip == "banned") {

echo "sorry.. you are banned ....";

} else {


### END OF USER BANNING CHECK ALTHOUGH } CONTINUES TO END ###



### WHAT DO WE DO BASED ON SUBJECT ###

// first if empty:

if ($subject == "") {

echo "Uh oh, the subject is empty";

} elseif ($subject == "help") {

echo "ar... we need to send help now";

} elseif ($subject == "new thread") {

echo "we now need to start a new thread"; 

} elseif ($subject == "Subscribe") {

echo "we need to subscribe them to this forum";

} elseif ($subject == "Unsubscribe") {

echo "we need to unsubscribe them to this forum";

} elseif ($subject == "daily") {

echo "we need to change settings to daily";

} elseif ($subject == "instant") {

echo "we need to change settings to instant";

} else {

// now a "command" so probably a post (or an error). Need to extract info from subject.

$delimiter == "**";


if (eregi("([[:digit:]]{1,})",$subject,$arr)) {

$threadno = (trim($arr[1]));
echo $threadno;
 
} else {

echo "Serious problem... did not match anything at all! Send back email with error message";
 
}


// end of subject matching
}

// end of email and ip address check


### END OF SUBJECT PROCESSING ###







#### done parsing, lets do some printing of found variables

echo "<b>Subject:</b><br>";
echo subject;
echo "<P>";
echo "<b>Email:</b><br>";
echo $email;
echo "<P>";
echo "<b>Clean Subject</b><br>";
echo $threadno;
echo "<P>";
echo "<B>Message Html</b><br>";
echo $message_html;
echo "<P>";
echo "<B>Header:</b><br>";
echo $header2;
echo "<P>";
echo "<b>Body:</b><br>";
echo $body2;



?>
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01148 seconds
  • Memory Usage 1,840KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_php
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete