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;
?>