Daniel Sepeur - 2006-06-26 07:33:49 -
In reply to message 2 from Steffen Stollfuß
Hello,
the SQL-Tables will be created too late in the original version of this script.
In line 90 of the file pop3_test.php, the script will test for existence of a message wich is found on the server:
$query = 'SELECT `unique_id` FROM `'.$msg_table.'` WHERE 1 AND `unique_id` = \''.$unique_id.'\' LIMIT 0, 1';
At this moment, the required tables are not existant because they will be created later in line 142:
if($savetomysql){
In this if, the function save2mysql (pop3.class.inc) will be called and then it will create the appropriate tables.
Therefore i added a small function to pop3.class.inc like this
/*
Funktion create_mysql_tables($mysql_socket,$dir_table = "inbox",$msg_table = "messages")
Access: Public
*/
function create_mysql_tables($socket,$dir_table = "inbox",$msg_table = "messages"){
$this->mysql_socket = $socket;
// Create Table for Mail Header Data
$query = 'CREATE TABLE IF NOT EXISTS `'.$dir_table.'` (`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`unique_id` varchar(255) NOT NULL default\'\',
`msg_id` TEXT NOT NULL, `from` TEXT NOT NULL, `to` TEXT NOT NULL, `subject` TEXT NOT NULL,
`date` TEXT NOT NULL, `cc` TEXT, `bcc` TEXT, `content_type` TEXT, `content_encode` TEXT,
`mime_version` TEXT, `x_mailer` TEXT, `x_priority` INT( 1 ) DEFAULT \'3\', `reply_to` TEXT, `sender` TEXT,
`mail_followup_to` TEXT, `mail_reply_to` TEXT, `return_receipt_to` TEXT, `disposition_notification_to` TEXT,
`received` TEXT NOT NULL, `create` TIMESTAMP(14) NOT NULL, `read` TINYINT(1) DEFAULT \'0\' NOT NULL,
PRIMARY KEY ( `id` )) TYPE = MYISAM';
if(!mysql_query($query,$this->mysql_socket)){
$this->error = __LINE__." POP3 create_mysql_tables() - MySQL Error: ". mysql_errno() ." -- ". mysql_error();
$this->_cleanup();
return FALSE;
}
// Create table for messages !!!
$query = 'CREATE TABLE IF NOT EXISTS `'.$msg_table.'` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`unique_id` VARCHAR( 255 ) NOT NULL , `linenumber` INT UNSIGNED NOT NULL , `linetext` TEXT,
PRIMARY KEY ( `id` ) ) TYPE = MYISAM ';
if(!mysql_query($query,$this->mysql_socket)){
$this->error = __LINE__." POP3 create_mysql_tables() - MySQL Error: ". mysql_errno() ." -- ". mysql_error();
$this->_cleanup();
return FALSE;
}
$this->mysql_socket = FALSE;
$message = "TABLE CREATION DONE";
return($message);
} // EOF
I call this funtcion in pop3_test.php on line 73 directly after this
$db["link"] = mysql_connect($db["addr"],$db["user"],$db["pass"]) or die(mysql_error());
mysql_select_db($db["use"],$db["link"]) or die(mysql_error());
...like this ...
// Zuallererst schaun wir, ob die MySQL-Tabellen schon eingerichtet sind
if($savetomysql){
if($create_tables = $pop3->create_mysql_tables($db["link"],$db["dir_table"])){
echo "Required MySQL Tables created!! \r\n <br>";
$loadtime += getmtime() - $start ;
print "<br><b>Zeile ".__LINE__."</b> Erforderliche MySQL-Tabellen erzeugt";
print "<br>Benötigte Zeit: ".round($loadtime,3)." Sekunden<br>";
unset($loadtime);
}else{
echo $pop3->error;
return;
}
}
I have found alot of more small typos and bad usage of Variables and Array-Elements.
If someone is interested, i can ask the author to review my changes and take it over to the original code.
Daniel