b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (0.9.x) [ class tree: evocore ] [ index: evocore ] [ all elements ]

Source for file _class_pop3.php

Documentation is available at _class_pop3.php

  1. <?php
  2. /**
  3.  * An RFC 1939 compliant wrapper class for the POP3 protocol.
  4.  *
  5.  * b2evolution - {@link http://b2evolution.net/}
  6.  * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
  7.  * @copyright (c)2003-2005 by Francois PLANQUE - {@link http://fplanque.net/}
  8.  * @copyright (c)1999-2002 The SquirrelMail Project Team
  9.  * @copyright (c)1999 CDI (cdi@thewebmasters.net) All Rights Reserved
  10.  *
  11.  * @package evocore
  12.  * @subpackage pop3
  13.  */
  14. if!defined('DB_USER') ) die'Please, do not access this page directly.' );
  15.  
  16. /**
  17.  * An RFC 1939 compliant wrapper class for the POP3 protocol.
  18.  *
  19.  * @package evocore
  20.  */
  21. class POP3 {
  22.     var $ERROR            = '';                //    Error string.
  23.  
  24.     var $TIMEOUT        = 60;                //    Default timeout before giving up on a
  25.                                                             //    network operation.
  26.  
  27.     var $COUNT            = -1;                //    Mailbox msg count
  28.  
  29.     var $BUFFER            = 512;            //    Socket buffer for socket fgets() calls.
  30.                                                             //    Per RFC 1939 the returned line a POP3
  31.                                                             //    server can send is 512 bytes.
  32.  
  33.     var $FP                    = '';                //    The connection to the server's
  34.                                                             //    file descriptor
  35.  
  36.     var $MAILSERVER = '';                // Set this to hard code the server name
  37.  
  38.     var $DEBUG            = false;        // set to true to echo pop3
  39.                                                             // commands and responses to error_log
  40.                                                             // this WILL log passwords!
  41.  
  42.     var $BANNER            = '';                //    Holds the banner returned by the
  43.                                                             //    pop server - used for apop()
  44.  
  45.     var $RFC1939        = true;            //    Set by noop(). See rfc1939.txt
  46.                                                             //
  47.  
  48.     var $ALLOWAPOP    = false;        //    Allow or disallow apop()
  49.                                                             //    This must be set to true
  50.                                                             //    manually
  51.  
  52.  
  53.     /**
  54.      * Constructor
  55.      */
  56.     function POP3 $server ''$timeout '' {
  57.             settype($this->BUFFER,'integer');
  58.             if!empty($server) ) {
  59.                     // Do not allow programs to alter MAILSERVER
  60.                     // if it is already specified. They can get around
  61.                     // this if they -really- want to, so don't count on it.
  62.                     if(empty($this->MAILSERVER))
  63.                             $this->MAILSERVER = $server;
  64.             }
  65.             if(!empty($timeout)) {
  66.                     settype($timeout,'integer');
  67.                     $this->TIMEOUT = $timeout;
  68.                     iffunction_exists('set_time_limit') )
  69.                     {
  70.                         set_time_limit($timeout);
  71.                     }
  72.             }
  73.             return true;
  74.     }
  75.  
  76.  
  77.     /**
  78.      * sets/refreshes script timeout
  79.      */
  80.     function update_timer ({
  81.         iffunction_exists('set_time_limit') )
  82.         {
  83.             set_time_limit($this->TIMEOUT);
  84.             return true;
  85.         }
  86.         return false;
  87.     }
  88.  
  89.  
  90.     /**
  91.      * Opens a socket to the specified server. Unless overridden,
  92.      * port defaults to 110.
  93.      *
  94.      * @param string server, overriden by MAILSERVER, if not empty
  95.      * @param integer port, default 110
  96.      * @return true on success, false on fail
  97.      */
  98.     function connect ($server$port 110)
  99.     {
  100.         if!empty($this->MAILSERVER) )
  101.             $server $this->MAILSERVER;
  102.  
  103.         ifempty($server) ){
  104.             $this->ERROR = T_('POP3 connect:'' ' T_('No server specified');
  105.             unset($this->FP);
  106.             return false;
  107.         }
  108.  
  109.         $fp fsockopen($server$port$errno$errstr);
  110.  
  111.         if!$fp )
  112.         {
  113.             $this->ERROR = T_('POP3 connect:'' ' T_('Error'" [$errno] [$errstr]";
  114.             unset($this->FP);
  115.             return false;
  116.         }
  117.  
  118.         socket_set_blocking($fp,-1);
  119.         $this->update_timer();
  120.         $reply fgets($fp,$this->BUFFER);
  121.         $reply $this->strip_clf($reply);
  122.         if($this->DEBUG)
  123.             error_log("POP3 SEND [connect: $server] GOT [$reply]",0);
  124.         if(!$this->is_ok($reply)) {
  125.             $this->ERROR = T_('POP3 connect:'' ' T_('Error'" [$reply]";
  126.             unset($this->FP);
  127.             return false;
  128.         }
  129.         $this->FP = $fp;
  130.         $this->BANNER = $this->parse_banner($reply);
  131.         $this->RFC1939 = $this->noop();
  132.         if($this->RFC1939{
  133.             $this->ERROR = T_('POP3: premature NOOP OK, NOT an RFC 1939 Compliant server');
  134.             $this->quit();
  135.             return false;
  136.         }
  137.         else
  138.             return true;
  139.     }
  140.  
  141.  
  142.     function noop ({
  143.  
  144.             if(!isset($this->FP)) {
  145.                     $this->ERROR = T_('POP3 noop:'' ' T_('No connection to server');
  146.                     return false;
  147.             else {
  148.                     $cmd 'NOOP';
  149.                     $reply $this->send_cmd$cmd );
  150.                     return$this->is_ok$reply ) );
  151.             }
  152.     }
  153.  
  154.     /**
  155.      * Sends the USER command
  156.      * @return true or false
  157.      */
  158.     function user ($user ''{
  159.             ifempty($user) ) {
  160.                     $this->ERROR = T_('POP3 user:'' ' T_('No login ID submitted');
  161.                     return false;
  162.             elseif(!isset($this->FP)) {
  163.                     $this->ERROR = T_('POP3 user:'' ' T_('connection not established');
  164.                     return false;
  165.             else {
  166.                     $reply $this->send_cmd("USER $user");
  167.                     if(!$this->is_ok($reply)) {
  168.                             $this->ERROR = T_('POP3 user:'' ' T_('Error'" [$reply]";
  169.                             return false;
  170.                     else
  171.                             return true;
  172.             }
  173.     }
  174.  
  175.     function pass ($pass '')         {
  176.             // Sends the PASS command, returns # of msgs in mailbox,
  177.             // returns false (undef) on Auth failure
  178.  
  179.             if(empty($pass)) {
  180.                     $this->ERROR = T_('POP3 pass:'' ' T_('No password submitted');
  181.                     return false;
  182.             elseif(!isset($this->FP)) {
  183.                     $this->ERROR = T_('POP3 pass:'' ' T_('connection not established');
  184.                     return false;
  185.             else {
  186.                     $reply $this->send_cmd("PASS $pass");
  187.                     if(!$this->is_ok($reply)) {
  188.                             $this->ERROR = T_('POP3 pass:'' ' T_('authentication failed '"[$reply]";
  189.                             $this->quit();
  190.                             return false;
  191.                     else {
  192.                             //    Auth successful.
  193.                             $count $this->last('count');
  194.                             $this->COUNT = $count;
  195.                             $this->RFC1939 = $this->noop();
  196.                             if(!$this->RFC1939{
  197.                                     $this->ERROR = T_('POP3 pass:'' ' T_('NOOP failed. Server not RFC 1939 compliant');
  198.                                     $this->quit();
  199.                                     return false;
  200.                             else
  201.                                     return $count;
  202.                     }
  203.             }
  204.     }
  205.  
  206.     function apop ($login,$pass{
  207.             //    Attempts an APOP login. If this fails, it'll
  208.             //    try a standard login. YOUR SERVER MUST SUPPORT
  209.             //    THE USE OF THE APOP COMMAND!
  210.             //    (apop is optional per rfc1939)
  211.  
  212.             if(!isset($this->FP)) {
  213.                     $this->ERROR = T_('POP3 apop:'' ' T_('No connection to server');
  214.                     return false;
  215.             elseif(!$this->ALLOWAPOP{
  216.                     $retVal $this->login($login,$pass);
  217.                     return $retVal;
  218.             elseif(empty($login)) {
  219.                     $this->ERROR = T_('POP3 apop:'' ' T_('No login ID submitted');
  220.                     return false;
  221.             elseif(empty($pass)) {
  222.                     $this->ERROR = T_('POP3 apop:'' ' T_('No password submitted');
  223.                     return false;
  224.             else {
  225.                     $banner $this->BANNER;
  226.                     if( (!$banneror (empty($banner)) ) {
  227.                             $this->ERROR = T_('POP3 apop:'' ' T_('No server banner'' - ' T_('abort');
  228.                             $retVal $this->login($login,$pass);
  229.                             return $retVal;
  230.                     else {
  231.                             $AuthString $banner;
  232.                             $AuthString .= $pass;
  233.                             $APOPString md5($AuthString);
  234.                             $cmd "APOP $login $APOPString";
  235.                             $reply $this->send_cmd($cmd);
  236.                             if(!$this->is_ok($reply)) {
  237.                                     $this->ERROR = T_('POP3 apop:'' ' T_('apop authentication failed'' - ' T_('abort');
  238.                                     $retVal $this->login($login,$pass);
  239.                                     return $retVal;
  240.                             else {
  241.                                     //    Auth successful.
  242.                                     $count $this->last('count');
  243.                                     $this->COUNT = $count;
  244.                                     $this->RFC1939 = $this->noop();
  245.                                     if(!$this->RFC1939{
  246.                                             $this->ERROR = T_('POP3 apop:'' ' T_('NOOP failed. Server not RFC 1939 compliant');
  247.                                             $this->quit();
  248.                                             return false;
  249.                                     else
  250.                                             return $count;
  251.                             }
  252.                     }
  253.             }
  254.     }
  255.  
  256.     function login ($login ''$pass ''{
  257.             // Sends both user and pass. Returns # of msgs in mailbox or
  258.             // false on failure (or -1, if the error occurs while getting
  259.             // the number of messages.)
  260.  
  261.             if!isset($this->FP) ) {
  262.                     $this->ERROR = T_('POP3 login:'' ' T_('No connection to server');
  263.                     return false;
  264.             else {
  265.                     $fp $this->FP;
  266.                     if!$this->user$login ) ) {
  267.                             //    Preserve the error generated by user()
  268.                             return false;
  269.                     else {
  270.                             $count $this->pass($pass);
  271.                             if( (!$count|| ($count == -1) ) {
  272.                                     //    Preserve the error generated by last() and pass()
  273.                                     return false;
  274.                             else
  275.                                     return $count;
  276.                     }
  277.             }
  278.     }
  279.  
  280.     function top ($msgNum$numLines '0'{
  281.             //    Gets the header and first $numLines of the msg body
  282.             //    returns data in an array with each returned line being
  283.             //    an array element. If $numLines is empty, returns
  284.             //    only the header information, and none of the body.
  285.  
  286.             if(!isset($this->FP)) {
  287.                     $this->ERROR = T_('POP3 top:'' ' T_('No connection to server');
  288.                     return false;
  289.             }
  290.             $this->update_timer();
  291.  
  292.             $fp $this->FP;
  293.             $buffer $this->BUFFER;
  294.             $cmd "TOP $msgNum $numLines";
  295.             fwrite($fp"TOP $msgNum $numLines\r\n");
  296.             $reply fgets($fp$buffer);
  297.             $reply $this->strip_clf($reply);
  298.             if($this->DEBUG{
  299.                     @error_log("POP3 SEND [$cmd] GOT [$reply]",0);
  300.             }
  301.             if(!$this->is_ok($reply))
  302.             {
  303.                     $this->ERROR = T_('POP3 top:'' ' T_('Error'" [$reply]";
  304.                     return false;
  305.             }
  306.  
  307.             $count 0;
  308.             $MsgArray array();
  309.  
  310.             $line fgets($fp,$buffer);
  311.             while !ereg("^\.\r\n",$line))
  312.             {
  313.                     $MsgArray[$count$line;
  314.                     $count++;
  315.                     $line fgets($fp,$buffer);
  316.                     if(empty($line))        break}
  317.             }
  318.  
  319.             return $MsgArray;
  320.     }
  321.  
  322.     function pop_list ($msgNum ''{
  323.             //    If called with an argument, returns that msgs' size in octets
  324.             //    No argument returns an associative array of undeleted
  325.             //    msg numbers and their sizes in octets
  326.  
  327.             if(!isset($this->FP))
  328.             {
  329.                     $this->ERROR = T_('POP3 pop_list:'' ' T_('No connection to server');
  330.                     return false;
  331.             }
  332.             $fp $this->FP;
  333.             $Total $this->COUNT;
  334.             if( (!$Totalor ($Total == -1) )
  335.             {
  336.                     return false;
  337.             }
  338.             if($Total == 0)
  339.             {
  340.                     return array('0','0');
  341.                     // return -1;        // mailbox empty
  342.             }
  343.  
  344.             $this->update_timer();
  345.  
  346.             if(!empty($msgNum))
  347.             {
  348.                     $cmd "LIST $msgNum";
  349.                     fwrite($fp,"$cmd\r\n");
  350.                     $reply fgets($fp,$this->BUFFER);
  351.                     $reply $this->strip_clf($reply);
  352.                     if($this->DEBUG{
  353.                             @error_log("POP3 SEND [$cmd] GOT [$reply]",0);
  354.                     }
  355.                     if(!$this->is_ok($reply))
  356.                     {
  357.                             $this->ERROR = T_('POP3 pop_list:'' ' T_('Error'" [$reply]";
  358.                             return false;
  359.                     }
  360.                     list($junk,$num,$sizeexplode(' ',$reply);
  361.                     return $size;
  362.             }
  363.             $cmd 'LIST';
  364.             $reply $this->send_cmd($cmd);
  365.             if(!$this->is_ok($reply))
  366.             {
  367.                     $reply $this->strip_clf($reply);
  368.                     $this->ERROR = T_('POP3 pop_list:'' ' T_('Error'.    " [$reply]";
  369.                     return false;
  370.             }
  371.             $MsgArray array();
  372.             $MsgArray[0$Total;
  373.             for($msgC=1;$msgC <= $Total$msgC++)
  374.             {
  375.                     if($msgC $Totalbreak}
  376.                     $line fgets($fp,$this->BUFFER);
  377.                     $line $this->strip_clf($line);
  378.                     if(ereg("^\.",$line))
  379.                     {
  380.                             $this->ERROR = T_('POP3 pop_list:'' ' T_('Premature end of list');
  381.                             return false;
  382.                     }
  383.                     list($thisMsg,$msgSizeexplode(' ',$line);
  384.                     settype($thisMsg,'integer');
  385.                     if($thisMsg != $msgC)
  386.                     {
  387.                             $MsgArray[$msgC'deleted';
  388.                     }
  389.                     else
  390.                     {
  391.                             $MsgArray[$msgC$msgSize;
  392.                     }
  393.             }
  394.             return $MsgArray;
  395.     }
  396.  
  397.     function get ($msgNum{
  398.             //    Retrieve the specified msg number. Returns an array
  399.             //    where each line of the msg is an array element.
  400.  
  401.             if(!isset($this->FP))
  402.             {
  403.                     $this->ERROR = T_('POP3 get:'' ' T_('No connection to server');
  404.                     return false;
  405.             }
  406.  
  407.             $this->update_timer();
  408.  
  409.             $fp $this->FP;
  410.             $buffer $this->BUFFER;
  411.             $cmd "RETR $msgNum";
  412.             $reply $this->send_cmd($cmd);
  413.  
  414.             if(!$this->is_ok($reply))
  415.             {
  416.                     $this->ERROR = T_('POP3 get:'' ' T_('Error'" [$reply]";
  417.                     return false;
  418.             }
  419.  
  420.             $count 0;
  421.             $MsgArray array();
  422.  
  423.             $line fgets($fp,$buffer);
  424.             while !ereg("^\.\r\n",$line))
  425.             {
  426.                     $MsgArray[$count$line;
  427.                     $count++;
  428.                     $line fgets($fp,$buffer);
  429.                     if(empty($line))        break}
  430.             }
  431.             return $MsgArray;
  432.     }
  433.  
  434.     function last $type 'count' {
  435.             //    Returns the highest msg number in the mailbox.
  436.             //    returns -1 on error, 0+ on success, if type != count
  437.             //    results in a popstat() call (2 element array returned)
  438.  
  439.             $last = -1;
  440.             if(!isset($this->FP))
  441.             {
  442.                     $this->ERROR = T_('POP3 last:'' ' T_('No connection to server');
  443.                     return $last;
  444.             }
  445.  
  446.             $reply $this->send_cmd('STAT');
  447.             if(!$this->is_ok($reply))
  448.             {
  449.                     $this->ERROR = T_('POP3 last:'' ' T_('Error'" [$reply]";
  450.                     return $last;
  451.             }
  452.  
  453.             $Vars explode(' ',$reply);
  454.             $count $Vars[1];
  455.             $size $Vars[2];
  456.             settype($count,'integer');
  457.             settype($size,'integer');
  458.             if($type != 'count')
  459.             {
  460.                     return array($count,$size);
  461.             }
  462.             return $count;
  463.     }
  464.  
  465.     function reset ({
  466.             //    Resets the status of the remote server. This includes
  467.             //    resetting the status of ALL msgs to not be deleted.
  468.             //    This method automatically closes the connection to the server.
  469.  
  470.             if(!isset($this->FP))
  471.             {
  472.                     $this->ERROR = T_('POP3 reset:'' ' T_('No connection to server');
  473.                     return false;
  474.             }
  475.             $reply $this->send_cmd('RSET');
  476.             if(!$this->is_ok($reply))
  477.             {
  478.                     //    The POP3 RSET command -never- gives a -ERR
  479.                     //    response - if it ever does, something truely
  480.                     //    wild is going on.
  481.  
  482.                     $this->ERROR = T_('POP3 reset:'' ' T_('Error'" [$reply]";
  483.                     @error_log("POP3 reset: ERROR [$reply]",0);
  484.             }
  485.             $this->quit();
  486.             return true;
  487.     }
  488.  
  489.     function send_cmd $cmd '' )
  490.     {
  491.             //    Sends a user defined command string to the
  492.             //    POP server and returns the results. Useful for
  493.             //    non-compliant or custom POP servers.
  494.             //    Do NOT includ the \r\n as part of your command
  495.             //    string - it will be appended automatically.
  496.  
  497.             //    The return value is a standard fgets() call, which
  498.             //    will read up to $this->BUFFER bytes of data, until it
  499.             //    encounters a new line, or EOF, whichever happens first.
  500.  
  501.             //    This method works best if $cmd responds with only
  502.             //    one line of data.
  503.  
  504.             if(!isset($this->FP))
  505.             {
  506.                     $this->ERROR = T_('POP3 send_cmd:'' ' T_('No connection to server');
  507.                     return false;
  508.             }
  509.  
  510.             if(empty($cmd))
  511.             {
  512.                     $this->ERROR = T_('POP3 send_cmd:'' ' T_('Empty command string');
  513.                     return '';
  514.             }
  515.  
  516.             $fp $this->FP;
  517.             $buffer $this->BUFFER;
  518.             $this->update_timer();
  519.             fwrite($fp,"$cmd\r\n");
  520.             $reply fgets($fp,$buffer);
  521.             $reply $this->strip_clf($reply);
  522.             if($this->DEBUG@error_log("POP3 SEND [$cmd] GOT [$reply]",0)}
  523.             return $reply;
  524.     }
  525.  
  526.     function quit({
  527.             //    Closes the connection to the POP3 server, deleting
  528.             //    any msgs marked as deleted.
  529.  
  530.             if(!isset($this->FP))
  531.             {
  532.                     $this->ERROR = T_('POP3 quit:'' ' T_('connection does not exist');
  533.                     return false;
  534.             }
  535.             $fp $this->FP;
  536.             $cmd 'QUIT';
  537.             fwrite($fp,"$cmd\r\n");
  538.             $reply fgets($fp,$this->BUFFER);
  539.             $reply $this->strip_clf($reply);
  540.             if($this->DEBUG@error_log("POP3 SEND [$cmd] GOT [$reply]",0)}
  541.             fclose($fp);
  542.             unset($this->FP);
  543.             return true;
  544.     }
  545.  
  546.     function popstat ({
  547.             //    Returns an array of 2 elements. The number of undeleted
  548.             //    msgs in the mailbox, and the size of the mbox in octets.
  549.  
  550.             $PopArray $this->last('array');
  551.  
  552.             if($PopArray == -1return false}
  553.  
  554.             if( (!$PopArrayor (empty($PopArray)) )
  555.             {
  556.                     return false;
  557.             }
  558.             return $PopArray;
  559.     }
  560.  
  561.     function uidl ($msgNum '')
  562.     {
  563.             //    Returns the UIDL of the msg specified. If called with
  564.             //    no arguments, returns an associative array where each
  565.             //    undeleted msg num is a key, and the msg's uidl is the element
  566.             //    Array element 0 will contain the total number of msgs
  567.  
  568.             if(!isset($this->FP)) {
  569.                     $this->ERROR = T_('POP3 uidl:'' ' T_('No connection to server');
  570.                     return false;
  571.             }
  572.  
  573.             $fp $this->FP;
  574.             $buffer $this->BUFFER;
  575.  
  576.             if(!empty($msgNum)) {
  577.                     $cmd "UIDL $msgNum";
  578.                     $reply $this->send_cmd($cmd);
  579.                     if(!$this->is_ok($reply))
  580.                     {
  581.                             $this->ERROR = T_('POP3 uidl:'' ' T_('Error'" [$reply]";
  582.                             return false;
  583.                     }
  584.                     list ($ok,$num,$myUidlexplode(' ',$reply);
  585.                     return $myUidl;
  586.             else {
  587.                     $this->update_timer();
  588.  
  589.                     $UIDLArray array();
  590.                     $Total $this->COUNT;
  591.                     $UIDLArray[0$Total;
  592.  
  593.                     if ($Total 1)
  594.                     {
  595.                             return $UIDLArray;
  596.                     }
  597.                     $cmd 'UIDL';
  598.                     fwrite($fp"UIDL\r\n");
  599.                     $reply fgets($fp$buffer);
  600.                     $reply $this->strip_clf($reply);
  601.                     if($this->DEBUG@error_log("POP3 SEND [$cmd] GOT [$reply]",0)}
  602.                     if(!$this->is_ok($reply))
  603.                     {
  604.                             $this->ERROR = T_('POP3 uidl:'' ' T_('Error'" [$reply]";
  605.                             return false;
  606.                     }
  607.  
  608.                     $line '';
  609.                     $count 1;
  610.                     $line fgets($fp,$buffer);
  611.                     while !ereg("^\.\r\n",$line)) {
  612.                             if(ereg("^\.\r\n",$line)) {
  613.                                     break;
  614.                             }
  615.                             list ($msg,$msgUidlexplode(' ',$line);
  616.                             $msgUidl $this->strip_clf($msgUidl);
  617.                             if($count == $msg{
  618.                                     $UIDLArray[$msg$msgUidl;
  619.                             }
  620.                             else
  621.                             {
  622.                                     $UIDLArray[$count'deleted';
  623.                             }
  624.                             $count++;
  625.                             $line fgets($fp,$buffer);
  626.                     }
  627.             }
  628.             return $UIDLArray;
  629.     }
  630.  
  631.     function delete ($msgNum ''{
  632.             //    Flags a specified msg as deleted. The msg will not
  633.             //    be deleted until a quit() method is called.
  634.  
  635.             if(!isset($this->FP))
  636.             {
  637.                     $this->ERROR = T_('POP3 delete:'' ' T_('No connection to server');
  638.                     return false;
  639.             }
  640.             if(empty($msgNum))
  641.             {
  642.                     $this->ERROR = T_('POP3 delete:'' ' T_('No msg number submitted');
  643.                     return false;
  644.             }
  645.             $reply $this->send_cmd("DELE $msgNum");
  646.             if(!$this->is_ok($reply))
  647.             {
  648.                     $this->ERROR = T_('POP3 delete:'' ' T_('Command failed'" [$reply]";
  649.                     return false;
  650.             }
  651.             return true;
  652.     }
  653.  
  654.     //    *********************************************************
  655.  
  656.     //    The following methods are internal to the class.
  657.  
  658.     function is_ok ($cmd ''{
  659.             //    Return true or false on +OK or -ERR
  660.  
  661.             ifempty($cmd) )
  662.                     return false;
  663.             else
  664.                     returnereg ("^\+OK"$cmd ) );
  665.     }
  666.  
  667.     function strip_clf ($text ''{
  668.             // Strips \r\n from server responses
  669.  
  670.             if(empty($text))
  671.                     return $text;
  672.             else {
  673.                     $stripped str_replace("\r",'',$text);
  674.                     $stripped str_replace("\n",'',$stripped);
  675.                     return $stripped;
  676.             }
  677.     }
  678.  
  679.     function parse_banner $server_text {
  680.             $outside true;
  681.             $banner '';
  682.             $length strlen($server_text);
  683.             for($count =0$count $length$count++)
  684.             {
  685.                     $digit substr($server_text,$count,1);
  686.                     if(!empty($digit))                         {
  687.                             if( (!$outside&& ($digit != '<'&& ($digit != '>') )
  688.                             {
  689.                                     $banner .= $digit;
  690.                             }
  691.                             if ($digit == '<')
  692.                             {
  693.                                     $outside false;
  694.                             }
  695.                             if($digit == '>')
  696.                             {
  697.                                     $outside true;
  698.                             }
  699.                     }
  700.             }
  701.             $banner $this->strip_clf($banner);        // Just in case
  702.             return "<$banner>";
  703.     }
  704.  
  705. }        // End class
  706.  
  707. ?>

Documentation generated on Tue, 20 May 2008 01:53:26 +0200 by phpDocumentor 1.4.2