@TobiaZ
Kannst du mal dein Script posten?
Kannst du mal dein Script posten?
$pop3 = new POP3( $server, $port, $user, $pass );
if ( !$pop3error = $pop3->open() ) {
if ( !$pop3error = $pop3->login() ) {
if ( !$pop3error = $pop3->stat() ) {
$mail_sizes = $pop3->listing();
$ids = $pop3->ids();
$row = "";
for( $ii = 1;$ii <= count( $mail_sizes );++$ii ) {
if ( in_array( $ids[$ii], $alreadyhave ) ) { // alreadyhave ist ein Array mit Mailids
continue; // welche nicht nochmal vom Server geholt werden
}
$headers = $body = $h = $b = "";
if ( ( $pop3error = $pop3->retrieve( $ii, $headers, $body ) ) == "" ) {
for( $line = 0;$line < count( $headers );$line++ ) {
$h .= addslashes( $headers[$line] ) . "\r\n";
}
for( $line = 0;$line < count( $body );$line++ ) {
$b .= addslashes( $body[$line] ) . "\r\n";
}
$row = "('" . $ids[$ii] . "'," . $server[$i][0] . ",'$h','$b')";
}
$sql .= ( $sql?",":"" ) . $row;
}
}
}
}
if ( $pop3error ) {
echo $pop3error;
}
$pop3->disconnect();
if ( $sql ) {
$query->insert( "insert into mails (mailserver_id,server_id,header,body) values $sql" );
}
/**
* class: pop3.class.php
* require:
* optional:
* description: class for retrieving mail from pop3 server
* created: 05.09.2002
* last change: 18.09.2002
* author: Sven Denkert <sven.denkert@t-online.de>
* copyright: Sven Denkert
*
* TODO: MIME Mails and Attachment
*/
if ( !isset( $_CLASS_POP3_ ) ) {
$_CLASS_POP3_ = 1;
class POP3 {
var $server = "";
var $port = 110;
var $user = "";
var $pass = "";
var $error = "";
var $con = 0;
var $status = "disconnected";
var $debug = 0;
var $header = array();
var $body = array();
var $size = array();
var $ids = array();
function POP3( $_server = "", $_port = 0, $_user = "", $_pass = "" )
{
$this->server = $_server;
$this->port = $_port;
$this->user = $_user;
$this->pass = $_pass;
}
function connect()
{
$this->debugger( "connecting to server" );
if ( !$this->server )
return $this->error = "no server given!";
if ( !( $this->con = fsockopen( $this->server, $this->port, $error ) ) ) {
switch ( $error ) {
case -3:
return $this->error = "socket could not be created";
case -4:
return $this->error = "dns lookup on hostname \"" . $this->server . "\" failed";
case -5:
return $this->error = "connection refused or timed out";
case -6:
return $this->error = "fdopen() call failed";
case -7:
return $this->error = "setvbuf() call failed";
default:
return $this->error = $error . " could not connect to the host \"" . $this->server . "\"";
}
}
$this->status = "connected";
}
function disconnect()
{
$this->debugger( "disconnecting" );
if ( $this->con ) {
fclose( $this->con );
$this->con = 0;
}
}
function open()
{
$this->debugger( "open mailslot" );
if ( $this->status != "connected" ) {
if ( $this->error = $this->connect() )
return $this->error;
if ( $this->tokenize( $this->get(), " " ) != "+OK" )
return $this->error = "could not open connection";
$this->status = "authorize";
return "";
}
}
function login()
{
if ( $this->status != "authorize" )
return $this->error = "no authorize state";
if ( !$this->put( "USER " . $this->user ) )
return $this->error = "Could not send the USER command";
if ( $this->tokenize( $this->get(), " " ) != "+OK" )
return $this->error = "Could not get USER response";
if ( !$this->put( "PASS " . $this->pass ) )
return $this->error = "Could not send the PASS command";
if ( $this->tokenize( $this->get(), " " ) != "+OK" )
return $this->error = "Username or Password not correct ?";
$this->status = "loggedin";
}
function put( $line )
{
$this->debugger( "puting line: $line" );
return( fputs( $this->con, "$line\r\n" ) );
}
function get()
{
for( $line = "";; ) {
if ( feof( $this->con ) )
return 0;
$line .= fgets( $this->con, 100 );
$length = strlen( $line );
if ( $length >= 2 && substr( $line, $length-2, 2 ) == "\r\n" ) {
$line = substr( $line, 0, $length-2 );
$this->debugger( " getting line from server: " . $line );
return $line;
}
}
}
function debugger( $text )
{
if ( $this->debug )
echo $text . "<br>";
}
function tokenize( $text, $token )
{
$this->token = $token;
$this->tokentext = $text;
if ( $pos = strpos( $text, $token ) ) {
$this->tokentext = substr( $text, $pos + 1 );
$this->debugger( "returning from tokenize: " . substr( $text, 0, $pos ) );
return substr( $text, 0, $pos );
}
$this->debugger( "returning from tokenize: " . $text );
return $text;
}
function nexttoken()
{
return $this->tokenize( $this->tokentext, $this->token );
}
function stat()
{
if ( $this->status != "loggedin" )
return $this->error = "not logged in";
if ( $this->put( "STAT" ) == 0 )
return $this->error = "Could not send the STAT command";
if ( $this->tokenize( $this->get(), " " ) != "+OK" )
return $this->error = "Could not get STAT response";
$this->debugger( "mailcount: " . $mail_count = $this->nexttoken() );
$this->debugger( "mailsize: " . $mail_size = $this->nexttoken() );
}
function &listing()
{
if ( $this->status != "loggedin" )
return $this->error = "not logged in";
if ( $this->put( "LIST" ) == 0 )
return $this->error = "Could not send the LIST command";
if ( $this->tokenize( $this->get(), " " ) != "+OK" )
return $this->error = "Could not get LIST response";
while ( true ) {
$response = $this->get();
if ( $response == "." )break;
$message = intval( $this->tokenize( $response, " " ) );
$this->size[$message] = $this->nexttoken();
$this->ids[$message] = $this->nexttoken();
}
return $this->size;
}
function &ids()
{
return $this->ids;
}
function retrieve( $message, &$header, &$body )
{
if ( $this->status != "loggedin" )
return $this->error = "not logged in";
if ( $this->put( "RETR $message" ) == 0 )
return $this->error = "Could not send the RETR command";
if ( $this->tokenize( $this->get(), " " ) != "+OK" )
return $this->error = "Could not get RETR response";
$header = $body = array();
for( $line = 0;;$line++ ) {
if ( GetType( $response = $this->get() ) != "string" )
return $this->error = "Could not retrieve the message";
switch ( $response ) {
case ".":
return( "" );
case "":
break 2;
default:
if ( substr( $response, 0, 1 ) == "." )
$response = substr( $response, 1, strlen( $response )-1 );
break;
}
$header[$line] = $response;
}
for( $line = 0;;$line++ ) {
if ( GetType( $response = $this->get() ) != "string" )
return $this->error = "Could not retrieve the message";
switch ( $response ) {
case ".":
return( "" );
default:
if ( substr( $response, 0, 1 ) == "." )
$response = substr( $response, 1, strlen( $response )-1 );
break;
}
$body[$line] = $response;
}
return "";
}
}
}
Warning: Wrong datatype for second argument in call to in_array in /usr/home/pop/test.php on line 12
Fatal error: Call to a member function on a non-object in /usr/home/pop/test.php on line 35
Kommentar