Connecting to server...
"); $mailbox = imap_open ("{mail.$domain$suff:110/$method}INBOX", "$user@$domain$suff", "$pw"); Status("$domain -> Checking if connected...

"); // Check messages $check = imap_check($mailbox); $messagecount=$check->Nmsgs; Status("$domain -> Counted " . $messagecount . " messages on server...
"); for ($x=1; $x < ($messagecount+1); $x++) { Status("
$domain $x -> Downloading e-mail
"); $header = imap_header($mailbox, $x); $from=str_replace(">","",str_replace("<","",$header->fromaddress)); $subject=str_replace("'","",$header->Subject); $datesent=str_replace("'","",$header->Date); $body=str_replace("'","",imap_body($mailbox,$x)); $msgnumber=trim($header->Msgno); Status("$domain $msgnumber -> e-mail downloaded
"); if (strlen($body)<=4) { # Message is too short. Possibly some sort of error? # Leave this message on the server } ELSE { # SAVES THE EMAIL TO MYSQL # IGNORE IS USED FOR ANY KIND OF ERROR. LETS JUST GET THE THING IN THERE!! $query="INSERT IGNORE INTO email_$domain.$user ( `messagenumber` , `to` , `from` , `subject` , `message` , `sentdate` ) VALUES (0, '$user@$domain$suff', '$from', '$subject', '$body', '$datesent');"; Status("$domain $msgnumber -> Saving to Database
"); SmartQuery($query); if ($enablebackup==true) { # Save a backup of this message on the server $fsize=1; # set higher than zero to initiate loop while ($fsize>0) { # choose the appropriate file to save this as... $fx=$fx+1; $backupfile="C:/phpop3/$user@$domain$suff/Messages/" . $fx . ".txt"; $fsize=filesize($backupfile); if ($fsize<=0) { break; } } # while $fp=fopen($backupfile,"wb"); $fw=fwrite($fp,$body); fclose($fp); $confirm=filesize($backupfile); if ($confirm<=0) { Status("$domain $msgnumber -> Backup failed to save ``$backupfile``
"); } ELSE { $delete[]=$x; # adds this index to the OK TO DELETE. Apparently a backup file + MySQL are done Status("$domain $msgnumber -> Backup saved to disk
"); } } ELSE { # BACKUP DISABLED. Automatically enable file to be deleted... $delete[]=$msgnumber; # says its ok to delete after all is said and done.. depending on your settings } # check if enabledbackup = true... } # check eroneous body length... } # for x (checks all messages in your inbox) if ($Delete_From_Server==true) { // YOU REQUESTED THESE MESSAGES TO BE DELETED AFTER THEY ARE DOWNLOADED if (count($delete)>0) { # Delete the messages from the server! Status("
$domain -> Deleting " . count($delete) . " messages from server...
"); $delcount=0; for ($x=0; $x < count($delete); $x++) { $del=$delete[$x]; imap_delete($mailbox,$del); $delcount=$delcount+1; } # for (delete messages) # Removes deleted items from your inbox... imap_expunge($mailbox); Status("$domain -> $delcount messages were deleted...
"); } ELSE { Status("
Finished. No E-Mails were deleted...
"); } } ELSE { Status("
Finished. Your messages are still on the server though (none were deleted).
"); } # $Delete_From_Server # Close the mailbox... (Nothing left to do right)... imap_close($mailbox); # FUNCTIONS function Status($statusmsg) { $buildecho='' . $statusmsg . ''; echo $buildecho; } # Echos back the status, formatted... function SmartQuery ($QueryString) { global $db, $db_host, $db_user, $db_password; $con = mysql_connect($db_host,$db_user,$db_password); if (!$con) { die("MySQL Database Connection Problem: " . mysql_error() . "\n *"); exit; } if (is_array($QueryString)) { # Array of queries... for ($x=0; $x < count($QueryString)+1; $x++) { $arrquery = $QueryString[$x]; # The Query ($x) if ($arrquery=="") { # No query } ELSE { # has query if (strtolower(substr($arrquery,0,3))=="arr") { # Returns a normal ARR of 1 row $arrquery=trim(substr($arrquery,3)); $returnarray=true; $returnbig=false; } ELSE { if (strtolower(substr($arrquery,0,6))=="bigarr") { # Returns a big ARR of all rows $arrquery=trim(substr($arrquery,6)); $returnarray=true; $returnbig=true; } ELSE { $returnarray=false; $returnbig=false; } } $query = $arrquery; mysql_select_db("$db"); $mysql_result = mysql_query($query, $con); if ($returnbig==true) { # Output large array - special $ret[0] = mysql_fetch_row($mysql_result); # set first row for ($y=1; $y < mysql_num_rows($mysql_result); $y++) { # Multi-dimensional arrays $ret[$y] = mysql_fetch_row($mysql_result); } $buildret[$x]=$ret; } ELSE { # Normal output $ret = mysql_fetch_row($mysql_result); if ($returnarray==true) { $buildret[$x] = $ret; } ELSE { $buildret[$x]=$ret[0]; } } } # for x (array queries } # check empty return $buildret; # END OF ARRAY QUERIES } ELSE { # BEGIN OF SINGLE QUERY # Normal query if (strtolower(substr($QueryString,0,3))=="arr") { # Returns a normal ARR of 1 row $QueryString=trim(substr($QueryString,3)); $returnarray=true; $returnbig=false; } ELSE { if (strtolower(substr($QueryString,0,6))=="bigarr") { # Returns a big ARR of all rows $QueryString=trim(substr($QueryString,6)); $returnarray=true; $returnbig=true; } ELSE { $returnarray=false; $returnbig=false; } } $query = $QueryString; mysql_select_db("$db"); #error_reporting(0); $mysql_result = mysql_query($query, $con); if ($returnbig==true) { # Output large array - special $ret[0] = mysql_fetch_row($mysql_result); # set first row for ($x=1; $x < mysql_num_rows($mysql_result); $x++) { $ret[$x] = mysql_fetch_row($mysql_result); } return $ret; } ELSE { # Normal output $ret = mysql_fetch_row($mysql_result); if ($returnarray==true) { return $ret; } ELSE { return $ret[0]; } } } } # SMARTQUERY ?>