protected function _createTmpFile($folder = 'INBOX')
    {
        if ($folder == 'INBOX') {
            $tmpdir = $this->_rootdir . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR;
        } else {
            $tmpdir = $this->_rootdir . '.' . $folder . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR;
        }
        if (!file_exists($tmpdir)) {
            if (!mkdir($tmpdir)) {
                /**
                 * @see Zend_Mail_Storage_Exception
                 */
                // require_once 'Zend/Mail/Storage/Exception.php';
                throw new Zend_Mail_Storage_Exception('problems creating tmp dir');
            }
        }

        // we should retry to create a unique id if a file with the same name exists
        // to avoid a script timeout we only wait 1 second (instead of 2) and stop
        // after a defined retry count
        // if you change this variable take into account that it can take up to $max_tries seconds
        // normally we should have a valid unique name after the first try, we're just following the "standard" here
        $max_tries = 5;
        for ($i = 0; $i < $max_tries; ++$i) {
            $uniq = $this->_createUniqueId();
            if (!file_exists($tmpdir . $uniq)) {
                // here is the race condition! - as defined in the standard
                // to avoid having a long time between stat()ing the file and creating it we're opening it here
                // to mark the filename as taken
                $fh = fopen($tmpdir . $uniq, 'w');
                if (!$fh) {
                    /**
                     * @see Zend_Mail_Storage_Exception
                     */
                    // require_once 'Zend/Mail/Storage/Exception.php';
                    throw new Zend_Mail_Storage_Exception('could not open temp file');
                }
                break;
            }
            sleep(1);
        }

        if (!$fh) {
            /**
             * @see Zend_Mail_Storage_Exception
             */
            // require_once 'Zend/Mail/Storage/Exception.php';
            throw new Zend_Mail_Storage_Exception("tried $max_tries unique ids for a temp file, but all were taken"
                                                . ' - giving up');
        }

        return array('dirname' => $this->_rootdir . '.' . $folder, 'uniq' => $uniq, 'filename' => $tmpdir . $uniq,
                     'handle' => $fh);
    }
protected function _createTmpFile($folder = 'INBOX')
    {
        if ($folder == 'INBOX') {
            $tmpdir = $this->_rootdir . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR;
        } else {
            $tmpdir = $this->_rootdir . '.' . $folder . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR;
        }
        if (!file_exists($tmpdir)) {
            if (!mkdir($tmpdir)) {
                /**
                 * @see Zend_Mail_Storage_Exception
                 */
                // require_once 'Zend/Mail/Storage/Exception.php';
                throw new Zend_Mail_Storage_Exception('problems creating tmp dir');
            }
        }

        // we should retry to create a unique id if a file with the same name exists
        // to avoid a script timeout we only wait 1 second (instead of 2) and stop
        // after a defined retry count
        // if you change this variable take into account that it can take up to $max_tries seconds
        // normally we should have a valid unique name after the first try, we're just following the "standard" here
        $max_tries = 5;
        for ($i = 0; $i < $max_tries; ++$i) {
            $uniq = $this->_createUniqueId();
            if (!file_exists($tmpdir . $uniq)) {
                // here is the race condition! - as defined in the standard
                // to avoid having a long time between stat()ing the file and creating it we're opening it here
                // to mark the filename as taken
                $fh = fopen($tmpdir . $uniq, 'w');
                if (!$fh) {
                    /**
                     * @see Zend_Mail_Storage_Exception
                     */
                    // require_once 'Zend/Mail/Storage/Exception.php';
                    throw new Zend_Mail_Storage_Exception('could not open temp file');
                }
                break;
            }
            sleep(1);
        }

        if (!$fh) {
            /**
             * @see Zend_Mail_Storage_Exception
             */
            // require_once 'Zend/Mail/Storage/Exception.php';
            throw new Zend_Mail_Storage_Exception("tried $max_tries unique ids for a temp file, but all were taken"
                                                . ' - giving up');
        }

        return array('dirname' => $this->_rootdir . '.' . $folder, 'uniq' => $uniq, 'filename' => $tmpdir . $uniq,
                     'handle' => $fh);
    }
protected function _createTmpFile ( $ folder = 'INBOX' ) { if ( $ folder == 'INBOX' ) { $ tmpdir = $ this -> _rootdir . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR ; } else { $ tmpdir = $ this -> _rootdir . '.' . $ folder . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR ; } if ( ! file_exists ( $ tmpdir ) ) { if ( ! mkdir ( $ tmpdir ) ) { /**
                 * @see Zend_Mail_Storage_Exception
                 */ // require_once 'Zend/Mail/Storage/Exception.php'; throw new Zend_Mail_Storage_Exception ( 'problems creating tmp dir' ) ; } } // we should retry to create a unique id if a file with the same name exists // to avoid a script timeout we only wait 1 second (instead of 2) and stop // after a defined retry count // if you change this variable take into account that it can take up to $max_tries seconds // normally we should have a valid unique name after the first try, we're just following the "standard" here $ max_tries = 5 ; for ( $ i = 0 ; $ i < $ max_tries ; ++ $ i ) { $ uniq = $ this -> _createUniqueId ( ) ; if ( ! file_exists ( $ tmpdir . $ uniq ) ) { // here is the race condition! - as defined in the standard // to avoid having a long time between stat()ing the file and creating it we're opening it here // to mark the filename as taken $ fh = fopen ( $ tmpdir . $ uniq , 'w' ) ; if ( ! $ fh ) { /**
                     * @see Zend_Mail_Storage_Exception
                     */ // require_once 'Zend/Mail/Storage/Exception.php'; throw new Zend_Mail_Storage_Exception ( 'could not open temp file' ) ; } break ; } sleep ( 1 ) ; } if ( ! $ fh ) { /**
             * @see Zend_Mail_Storage_Exception
             */ // require_once 'Zend/Mail/Storage/Exception.php'; throw new Zend_Mail_Storage_Exception ( "tried $max_tries unique ids for a temp file, but all were taken" . ' - giving up' ) ; } return array ( 'dirname' => $ this -> _rootdir . '.' . $ folder , 'uniq' => $ uniq , 'filename' => $ tmpdir . $ uniq , 'handle' => $ fh ) ; }
open a temporary maildir file

makes sure tmp/ exists and create a file with a unique name
you should close the returned filehandle!

@param   string $folder name of current folder without leading .
@return  array array('dirname' => dir of maildir folder, 'uniq' => unique id, 'filename' => name of create file
'handle'  => file opened for writing)
@throws  Zend_Mail_Storage_Exception
open a temporary maildir file