2011-05-14 36 views
0

我有一個腳本將郵件從一個源IMAP服務器傳輸到目標IMAP服務器。 我已經使用Eclipse作爲IDE在xampp中本地編寫了此腳本。 本地工作正常。但沒有INTERNALDATE。因爲我的XAMPP-PHP版本太舊了。imap_body中斷

所以我將腳本移動到我的服務器,其中PHP 5.3.6-pl0-gentoo正在運行。

第1步:
在開始的時候,該腳本將緩存一箱的所有郵件將文件在文件系統(FileCache)。

第2步:
的IMAP-連接-的ressource改變後的目標IMAP郵箱的腳本會做所有緩存郵件的「imap_append」寫這個郵件的目標IMAP郵箱。

我再說一遍,這個腳本在本地機器上工作正常(沒有INTERNALDATE)! INTERNALDATE僅用於imap_append。所以第一步(緩存)與INTERNALDATE無關!

我的問題:
在緩存郵件之後4個**郵件打破。它每次都是同一封郵件。 它每次打破「imap_body」這個郵件是沒有什麼特別的:正常的HTML附件(1x 32MB 7z文件)

在本地機器上,這個郵件被轉移了這個腳本。

關於執行的一些信息:PHP的

  1. 執行超時設置爲3 小時(腳本運轉3分鐘它打破 之前)。
  2. PHP的內存限制設置爲1GB (機器有2GB)腳本在斷開之前使用了63MB的 。
  3. PHP的套接字超時設置爲3 小時。
  4. 加載這個特殊的郵件頭 郵件在兩個系統上工作正常。 只有加載身體纔會中斷。
  5. 在我的分析是 「call_user_func_array」 與 「imap_body」我的腳本

這裏後直接突破:

RawHeader吸氣劑的一個郵件

/** 
* Getter of $_rawHeader 
* @access public 
* @return Content of $_rawHeader 
*/ 
public function getRawHeader($update=false) { 
     if(!$this->_rawHeader || $update) { 
       $cachename = urlencode('imap_'.$this->getIMAP()->getInstanceName().$this->getIndex().'_rawheader'); 
       if(!($this->_rawHeader = $this->Cache()->get($cachename)) || $update) { 
         $this->_rawHeader = $this->getIMAP()->fetchheader($this->getIndex()); 
         $this->Cache()->set($cachename, $this->_rawHeader, 2592000); 
         SYSLOG::debug($this->_rawHeader); 
       } 
     } 
     return $this->_rawHeader; 
} 

一個郵件的RawBody Getter

/** 
* Getter of $_rawBody 
* @access public 
* @return Content of $_rawBody 
*/ 
public function getRawBody($update=false) { 
     if(!$this->_rawBody || $update) { 
       $cachename = urlencode('imap_'.$this->getIMAP()->getInstanceName().$this->getIndex().'_rawbody'); 
       if(!($this->_rawBody = $this->Cache()->get($cachename)) || $update) { 
         SYSLOG::debug($this->getIMAP()->body($this->getIndex())); 
         $this->_rawBody = $this->getIMAP()->body($this->getIndex()); 
         SYSLOG::debug($this->_rawBody); 
         $this->Cache()->set($cachename, $this->_rawBody, 2592000); 
       } 
     } 
     return $this->_rawBody; 
} 

呼叫功能的IMAP級:

/** 
* Catch not accessable Method-Calls 
* 
* @param String Methodname 
* @param String Arguments 
* 
* This Method is for calling IMAP-Functions without "imap_" präfix 
* Possilbe Methods are: Look at http://de3.php.net/manual/en/ref.imap.php 
* 
* @link http://de3.php.net/manual/en/ref.imap.php 
* 
* @return null || Function-Return 
*/ 
public function __call($function, $arguments) { 
     //SYSLOG::debug('Call Function "imap_'.$function.'" on IMAP-Connection: '.$this->getAddress().':'.$this->getUsername()); 
     if(function_exists('imap_'.$function)) { 
       //Filtered Function that doesn't need Handle 
       $filter = array(
         '8bit', 
         'alerts', 
         'base64', 
         'binary', 
         'errors', 
         'last_error', 
         'mail_compose', 
         'mime_header_decode', 
         'qprint', 
         'rfc822_parse_adrlist', 
         'rfc822_parse_headers', 
         'rfc822_write_address', 
         'timeout', 
         'utf7_decode', 
         'utf7_encode', 
         'utf8' 
       ); 
       //SYSLOG::info($this->_handle); 
       if($function == 'reopen' && !$this->_handle) { 
         if(!$this->open()) { 
           return false; 
         } 
       } 

       //Make sure that the Connection is open if its needed 
       if(in_array($function, $filter) || $function == 'reopen' || $this->open()) { 
         if(!in_array($function, $filter)) { 
           // Prepend the imap resource to the arguments array 
           array_unshift($arguments, $this->_handle); 
         } 
         // Call the PHP function 
         $func = 'imap_'.$function; 
         //SYSLOG::debug($arguments); 
         SYSLOG::debug('Call Function "'.$func.'" on IMAP-Connection: '.$this->getAddress().':'.$this->getUsername()); 
         $result = call_user_func_array($func, $arguments); 
         //SYSLOG::debug($result); 
         return $result; 
       } else { 
         SYSLOG::warning('IMAP-Connection not available! Call-Function: "imap_'.$function.'" aborted!'); 
       } 
     } else { 
       SYSLOG::error('Call-Function: "imap_'.$function.'" does not exist!'); 
     } 
     return null; 
} 

爲什麼它打破了任何想法?

非常感謝您的幫助。

回答

0

我找到了解決方案,我的問題。 所以我發現郵件的附件很大。我不知道它是如何在我的xampp本地工作的,但對於我的高效系統來說它確實非常重要。

這是一種解決方法。也許不是正確的解決方案。我不知道。但它的工作。

我更換:

$this->_rawBody = $this->getIMAP()->body($this->getIndex()); 

與此:

//Workaround for imap_body because Attachment is to big 
$this->_rawBody = ''; 
$tmpFileName = 'data_'.$cachename.'.tmp'; 
$this->getIMAP()->savebody($tmpFileName, $this->getIndex()); 
$tmpFile = fopen($tmpFileName, 'r'); 
while(!feof($tmpFile)) { 
    $this->_rawBody .= fgets($tmpFile, 4096); 
} 
fclose($tmpFile); 
unlink($tmpFileName); 

感謝大家思考我的問題。