public function upload_init($max_size = null)
    {
        // Enable upload progress bar
        if ($seconds = $this->config->get('upload_progress')) {
            if (function_exists('uploadprogress_get_info')) {
                $field_name = 'UPLOAD_IDENTIFIER';
            }
            if (!$field_name && filter_var(ini_get('apc.rfc1867'), FILTER_VALIDATE_BOOLEAN)) {
                $field_name = ini_get('apc.rfc1867_name');
            }
            if (!$field_name && filter_var(ini_get('session.upload_progress.enabled'), FILTER_VALIDATE_BOOLEAN)) {
                $field_name = ini_get('session.upload_progress.name');
            }

            if ($field_name) {
                $this->output->set_env('upload_progress_name', $field_name);
                $this->output->set_env('upload_progress_time', (int) $seconds);
            }
        }

        // find max filesize value
        $max_filesize = rcube_utils::max_upload_size();
        if ($max_size && $max_size < $max_filesize) {
            $max_filesize = $max_size;
        }

        $max_filesize_txt = $this->show_bytes($max_filesize);
        $this->output->set_env('max_filesize', $max_filesize);
        $this->output->set_env('filesizeerror', $this->gettext(array(
            'name' => 'filesizeerror', 'vars' => array('size' => $max_filesize_txt))));

        if ($max_filecount = ini_get('max_file_uploads')) {
            $this->output->set_env('max_filecount', $max_filecount);
            $this->output->set_env('filecounterror', $this->gettext(array(
                'name' => 'filecounterror', 'vars' => array('count' => $max_filecount))));
        }

        return $max_filesize_txt;
    }