Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5839539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:35:54+00:00 2026-05-22T11:35:54+00:00

I have a script that will transfer Mails from one source IMAP-Server to a

  • 0

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:

  1. Execution Timeout of PHP is set to 3
    hours (script is running 3 minutes
    before it breaks).
  2. Memory Limit of PHP is set to 1GB
    (machine has 2GB) script is using
    63MB before it breaks.
  3. Socket Timeout of PHP is set to 3
    hours.
  4. To load the Header of this special
    mail works fine on both systems.
    Only to load the body will break.
  5. 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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T11:35:55+00:00Added an answer on May 22, 2026 at 11:35 am

    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:

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

    with this:

    //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);
    

    Thanks everyone for thinking about my problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a script that will fetch data from server and compose a DIV
I have a script that imports a models.py from an app, but it will
I have a script that retrieves objects from a remote server through an Ajax
I have a script that will slide a div up from the bottom of
I am trying to make a bash script that will transfer a file from
I have a code in VB that looks like this: 'Server.Transfer(txtUser.Text + _page.aspx) which
I have a script that will convert a text file into a resource file,
I have a simple PHP script that will either serve up a streaming ASF
Does anyone have a script for logparser that will output a graph for daily
I'm writing a script that will ping my ip range. Here's what I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.