web/wp-includes/class-pop3.php
changeset 194 32102edaa81b
parent 136 bde1974c263b
equal deleted inserted replaced
193:2f6f6f7551ca 194:32102edaa81b
     1 <?php
     1 <?php
     2 /**
     2 /**
     3  * mail_fetch/setup.php
     3  * mail_fetch/setup.php
     4  *
     4  *
     5  * @package SquirrelMail
     5  * Copyright (c) 1999-2011 CDI (cdi@thewebmasters.net) All Rights Reserved
     6  *
     6  * Modified by Philippe Mingo 2001-2009 mingo@rotedic.com
     7  * @copyright (c) 1999-2006 The SquirrelMail Project Team
       
     8  *
       
     9  * @copyright (c) 1999 CDI (cdi@thewebmasters.net) All Rights Reserved
       
    10  * Modified by Philippe Mingo 2001 mingo@rotedic.com
       
    11  * An RFC 1939 compliant wrapper class for the POP3 protocol.
     7  * An RFC 1939 compliant wrapper class for the POP3 protocol.
    12  *
     8  *
    13  * Licensed under the GNU GPL. For full terms see the file COPYING.
     9  * Licensed under the GNU GPL. For full terms see the file COPYING.
    14  *
    10  *
    15  * pop3 class
    11  * POP3 class
    16  *
    12  *
    17  * $Id: class-pop3.php 9503 2008-11-03 23:25:11Z ryan $
    13  * @copyright 1999-2011 The SquirrelMail Project Team
       
    14  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
       
    15  * @package plugins
       
    16  * @subpackage mail_fetch
    18  */
    17  */
    19 
    18 
    20 class POP3 {
    19 class POP3 {
    21     var $ERROR      = '';       //  Error string.
    20     var $ERROR      = '';       //  Error string.
    22 
    21 
    73         //  Opens a socket to the specified server. Unless overridden,
    72         //  Opens a socket to the specified server. Unless overridden,
    74         //  port defaults to 110. Returns true on success, false on fail
    73         //  port defaults to 110. Returns true on success, false on fail
    75 
    74 
    76         // If MAILSERVER is set, override $server with it's value
    75         // If MAILSERVER is set, override $server with it's value
    77 
    76 
    78 	if (!isset($port) || !$port) {$port = 110;}
    77     if (!isset($port) || !$port) {$port = 110;}
    79         if(!empty($this->MAILSERVER))
    78         if(!empty($this->MAILSERVER))
    80             $server = $this->MAILSERVER;
    79             $server = $this->MAILSERVER;
    81 
    80 
    82         if(empty($server)){
    81         if(empty($server)){
    83             $this->ERROR = "POP3 connect: " . _("No server specified");
    82             $this->ERROR = "POP3 connect: " . _("No server specified");
   250 
   249 
   251         $count = 0;
   250         $count = 0;
   252         $MsgArray = array();
   251         $MsgArray = array();
   253 
   252 
   254         $line = fgets($fp,$buffer);
   253         $line = fgets($fp,$buffer);
   255         while ( !ereg("^\.\r\n",$line))
   254         while ( !preg_match('/^\.\r\n/',$line))
   256         {
   255         {
   257             $MsgArray[$count] = $line;
   256             $MsgArray[$count] = $line;
   258             $count++;
   257             $count++;
   259             $line = fgets($fp,$buffer);
   258             $line = fgets($fp,$buffer);
   260             if(empty($line))    { break; }
   259             if(empty($line))    { break; }
   317         for($msgC=1;$msgC <= $Total; $msgC++)
   316         for($msgC=1;$msgC <= $Total; $msgC++)
   318         {
   317         {
   319             if($msgC > $Total) { break; }
   318             if($msgC > $Total) { break; }
   320             $line = fgets($fp,$this->BUFFER);
   319             $line = fgets($fp,$this->BUFFER);
   321             $line = $this->strip_clf($line);
   320             $line = $this->strip_clf($line);
   322             if(ereg("^\.",$line))
   321             if(strpos($line, '.') === 0)
   323             {
   322             {
   324                 $this->ERROR = "POP3 pop_list: " . _("Premature end of list");
   323                 $this->ERROR = "POP3 pop_list: " . _("Premature end of list");
   325                 return false;
   324                 return false;
   326             }
   325             }
   327             list($thisMsg,$msgSize) = preg_split('/\s+/',$line);
   326             list($thisMsg,$msgSize) = preg_split('/\s+/',$line);
   363 
   362 
   364         $count = 0;
   363         $count = 0;
   365         $MsgArray = array();
   364         $MsgArray = array();
   366 
   365 
   367         $line = fgets($fp,$buffer);
   366         $line = fgets($fp,$buffer);
   368         while ( !ereg("^\.\r\n",$line))
   367         while ( !preg_match('/^\.\r\n/',$line))
   369         {
   368         {
   370             if ( $line{0} == '.' ) { $line = substr($line,1); }
   369             if ( $line{0} == '.' ) { $line = substr($line,1); }
   371             $MsgArray[$count] = $line;
   370             $MsgArray[$count] = $line;
   372             $count++;
   371             $count++;
   373             $line = fgets($fp,$buffer);
   372             $line = fgets($fp,$buffer);
   551             }
   550             }
   552 
   551 
   553             $line = "";
   552             $line = "";
   554             $count = 1;
   553             $count = 1;
   555             $line = fgets($fp,$buffer);
   554             $line = fgets($fp,$buffer);
   556             while ( !ereg("^\.\r\n",$line)) {
   555             while ( !preg_match('/^\.\r\n/',$line)) {
   557                 if(ereg("^\.\r\n",$line)) {
       
   558                     break;
       
   559                 }
       
   560                 list ($msg,$msgUidl) = preg_split('/\s+/',$line);
   556                 list ($msg,$msgUidl) = preg_split('/\s+/',$line);
   561                 $msgUidl = $this->strip_clf($msgUidl);
   557                 $msgUidl = $this->strip_clf($msgUidl);
   562                 if($count == $msg) {
   558                 if($count == $msg) {
   563                     $UIDLArray[$msg] = $msgUidl;
   559                     $UIDLArray[$msg] = $msgUidl;
   564                 }
   560                 }
   604         //  Return true or false on +OK or -ERR
   600         //  Return true or false on +OK or -ERR
   605 
   601 
   606         if( empty($cmd) )
   602         if( empty($cmd) )
   607             return false;
   603             return false;
   608         else
   604         else
   609             return( ereg ("^\+OK", $cmd ) );
   605             return( stripos($cmd, '+OK') !== false );
   610     }
   606     }
   611 
   607 
   612     function strip_clf ($text = "") {
   608     function strip_clf ($text = "") {
   613         // Strips \r\n from server responses
   609         // Strips \r\n from server responses
   614 
   610 
   615         if(empty($text))
   611         if(empty($text))
   616             return $text;
   612             return $text;
   617         else {
   613         else {
   618             $stripped = str_replace("\r",'',$text);
   614             $stripped = str_replace(array("\r","\n"),'',$text);
   619             $stripped = str_replace("\n",'',$stripped);
       
   620             return $stripped;
   615             return $stripped;
   621         }
   616         }
   622     }
   617     }
   623 
   618 
   624     function parse_banner ( $server_text ) {
   619     function parse_banner ( $server_text ) {
   646         $banner = $this->strip_clf($banner);    // Just in case
   641         $banner = $this->strip_clf($banner);    // Just in case
   647         return "<$banner>";
   642         return "<$banner>";
   648     }
   643     }
   649 
   644 
   650 }   // End class
   645 }   // End class
   651 ?>
   646 
       
   647 // For php4 compatibility
       
   648 if (!function_exists("stripos")) {
       
   649     function stripos($haystack, $needle){
       
   650         return strpos($haystack, stristr( $haystack, $needle ));
       
   651     }
       
   652 }