I have a script that will transfer Mails from one source IMAP-Server to a target IMAP-Server.
I’ve written this script locally in my xampp with eclipse as IDE.
Local it works fine. But without INTERNALDATE. Because my XAMPP-PHP Version was to old.
So i moved the script to my server where PHP 5.3.6-pl0-gentoo is running.
Step 1:
In the beginning, the script will cache all mails of one Box to Files on the FileSystem (FileCache).
Step 2:
After the IMAP-Connection-Ressource is changed to target IMAP-Mailbox the script will do an “imap_append” on all cached mails to write this mails to the target IMAP-Mailbox.
I repeat, this script works fine on local machine (without INTERNALDATE)!
INTERNALDATE is only used on imap_append. So step one (caching) has nothing to do with INTERNALDATE!
My Problem:
On caching Mails it breaks after 4** mails. It is everytime the same mail where it breaks.
and it breaks everytime on “imap_body” this mail is nothing special: normal html with attachment (1x 32MB 7z-File)
On local machine this mail was transfered by this script.
Some information about the execution:
- Execution Timeout of PHP is set to 3
hours (script is running 3 minutes
before it breaks). - Memory Limit of PHP is set to 1GB
(machine has 2GB) script is using
63MB before it breaks. - Socket Timeout of PHP is set to 3
hours. - To load the Header of this special
mail works fine on both systems.
Only to load the body will break. - In my analyse it breaks directly after “call_user_func_array” with
“imap_body”
Here my Script:
Getter of RawHeader of one Mail
/**
* 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;
}
Getter of RawBody of one Mail
/**
* 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;
}
Call-Function on IMAP-Class:
/**
* 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;
}
Any ideas why it breaks?
Thanks a lot for help.
I have found a solution for my problem.
So i have found out that the attachment of the mail is to big. I don’t know how it works local on my xampp but it is definitly to big for my productive system.
It’s a workaround. Maybe not the right solution. I don’t know. But it works.
I have replace the:
with this:
Thanks everyone for thinking about my problem.