wie verwende ich die pop3 klasse von tbt
kann mir da einer helfen 
 
MFG Ascharan 
							
						
					kann mir da einer helfen
 
 MFG Ascharan
 
							
						
<?php
/**
 * class:         pop3.class.php
 * require:
 * optional:
 * description:    class for retrieving mail from pop3 server
 * created:        05.09.2002
 * last change:    14.01.2005
 * author:        Sven Denkert <sven dot denkert at webxsite dot de>
 * copyright:    Sven Denkert
 *
 * Extra:        MIME Mails and Attachment koennen mit maildecoder.class.php erledigt werden
 *              beim loeschen von mails (function delete) muss der server ordentlich geschlossen
 *              werden, ansonsten werden diese nicht geloescht!
 */
class POP3{
    var $server = "";
    var $port = 110;
    var $user = "";
    var $pass = "";
    var $error = "";
    var $con = 0;
    var $status = "disconnected";
    var $header    = array();
    var $body    = array();
    var $size    = array();
    var $ids    = array();
    /**
     * baut eine verbindung zum server auf
     **/
    function connect($_server = "", $_user = "", $_pass = "" ){
        $this->server = $_server;
        $this->user = $_user;
        $this->pass = $_pass;
        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";
    }
    /**
     * schliesst die verbindung zum server
     **/
    function disconnect() {
        if ( $this->con ) {
            $this->put('QUIT');
            fclose( $this->con );
            $this->con = 0;
        }
    }
    /**
     * oeffnet die verbindung zum server
     **/
    function open() {
        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 "";
    }
    /**
     * login mit benutzername und passwort
     **/
    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";
    }
    /**
     * schickt einen befehl zum server
     **/
    function put( $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 );
                return $line;
            }
        }
    }
    /**
     * zerlegt die antwort vom server
     **/
    function tokenize( $text, $token ) {
        $this->token = $token;
        $this->tokentext = $text;
        if ( $pos = strpos( $text, $token ) ) {
            $this->tokentext = substr( $text, $pos + 1 );
            return substr( $text, 0, $pos );
        }
        return $text;
    }
    /**
     * parst die naechste antwort vom server
     **/
    function nexttoken() {
        return $this->tokenize( $this->tokentext, $this->token );
    }
    /**
     * statistik ueber die mailbox
     **/
    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";
    }
    /**
     * loeschen einer mail
     * ACHTUNG: mail wird nur zum loeschen markiert, erst das QUIT zum server loescht sie!
     **/
    function delete($_id) {
        if ( $this->status != "loggedin" )
            return $this->error = "not logged in";
        if ( $this->put( "DELE ".$_id ) == 0 )
            return $this->error = "Could not send the DELE command";
        if ( $this->tokenize( $this->get(), " " ) != "+OK" )
            return $this->error = "Could not get DELE response";
    }
    /**
     * uebersicht ueber die mails in der mailbox
     **/
    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;
    }
    /**
     * gibt die vom server vergebenen ids fuer die mails zurueck
     **/
    function &ids()    {
        return $this->ids;
    }
    /**
     * holt eine mail
     **/
    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 "";
    }
}
?>
Comment