roundcubemail/plugins/zipdownload/zipdownload.php
public function download_attachments()
    {
        $rcmail = rcmail::get_instance();

        // require CSRF protected request
        $rcmail->request_security_check(rcube_utils::INPUT_GET);

        $imap      = $rcmail->get_storage();
        $temp_dir  = $rcmail->config->get('temp_dir');
        $tmpfname  = tempnam($temp_dir, 'zipdownload');
        $tempfiles = array($tmpfname);
        $message   = new rcube_message(rcube_utils::get_input_value('_uid', rcube_utils::INPUT_GET));

        // open zip file
        $zip = new ZipArchive();
        $zip->open($tmpfname, ZIPARCHIVE::OVERWRITE);

        foreach ($message->attachments as $part) {
            $pid      = $part->mime_id;
            $part     = $message->mime_parts[$pid];
            $disp_name = $this->_create_displayname($part);

            $tmpfn       = tempnam($temp_dir, 'zipattach');
            $tmpfp       = fopen($tmpfn, 'w');
            $tempfiles[] = $tmpfn;

            $message->get_part_body($part->mime_id, false, 0, $tmpfp);
            $zip->addFile($tmpfn, $disp_name);
            fclose($tmpfp);
        }

        $zip->close();

        $filename = ($this->_filename_from_subject($message->subject) ?: 'attachments') . '.zip';

        $this->_deliver_zipfile($tmpfname, $filename);

        // delete temporary files from disk
        foreach ($tempfiles as $tmpfn) {
            unlink($tmpfn);
        }

        exit;
    }
public function download_attachments()
    {
        $rcmail = rcmail::get_instance();

        // require CSRF protected request
        $rcmail->request_security_check(rcube_utils::INPUT_GET);

        $imap      = $rcmail->get_storage();
        $temp_dir  = $rcmail->config->get('temp_dir');
        $tmpfname  = tempnam($temp_dir, 'zipdownload');
        $tempfiles = array($tmpfname);
        $message   = new rcube_message(rcube_utils::get_input_value('_uid', rcube_utils::INPUT_GET));

        // open zip file
        $zip = new ZipArchive();
        $zip->open($tmpfname, ZIPARCHIVE::OVERWRITE);

        foreach ($message->attachments as $part) {
            $pid      = $part->mime_id;
            $part     = $message->mime_parts[$pid];
            $disp_name = $this->_create_displayname($part);

            $tmpfn       = tempnam($temp_dir, 'zipattach');
            $tmpfp       = fopen($tmpfn, 'w');
            $tempfiles[] = $tmpfn;

            $message->get_part_body($part->mime_id, false, 0, $tmpfp);
            $zip->addFile($tmpfn, $disp_name);
            fclose($tmpfp);
        }

        $zip->close();

        $filename = ($this->_filename_from_subject($message->subject) ?: 'attachments') . '.zip';

        $this->_deliver_zipfile($tmpfname, $filename);

        // delete temporary files from disk
        foreach ($tempfiles as $tmpfn) {
            unlink($tmpfn);
        }

        exit;
    }
public function download_attachments ( ) { $ rcmail = rcmail :: get_instance ( ) ; // require CSRF protected request $ rcmail -> request_security_check ( rcube_utils :: INPUT_GET ) ; $ imap = $ rcmail -> get_storage ( ) ; $ temp_dir = $ rcmail -> config -> get ( 'temp_dir' ) ; $ tmpfname = tempnam ( $ temp_dir , 'zipdownload' ) ; $ tempfiles = array ( $ tmpfname ) ; $ message = new rcube_message ( rcube_utils :: get_input_value ( '_uid' , rcube_utils :: INPUT_GET ) ) ; // open zip file $ zip = new ZipArchive ( ) ; $ zip -> open ( $ tmpfname , ZIPARCHIVE :: OVERWRITE ) ; foreach ( $ message -> attachments as $ part ) { $ pid = $ part -> mime_id ; $ part = $ message -> mime_parts [ $ pid ] ; $ disp_name = $ this -> _create_displayname ( $ part ) ; $ tmpfn = tempnam ( $ temp_dir , 'zipattach' ) ; $ tmpfp = fopen ( $ tmpfn , 'w' ) ; $ tempfiles [ ] = $ tmpfn ; $ message -> get_part_body ( $ part -> mime_id , false , 0 , $ tmpfp ) ; $ zip -> addFile ( $ tmpfn , $ disp_name ) ; fclose ( $ tmpfp ) ; } $ zip -> close ( ) ; $ filename = ( $ this -> _filename_from_subject ( $ message -> subject ) ? : 'attachments' ) . '.zip' ; $ this -> _deliver_zipfile ( $ tmpfname , $ filename ) ; // delete temporary files from disk foreach ( $ tempfiles as $ tmpfn ) { unlink ( $ tmpfn ) ; } exit ; }
Handler for attachment download action
Handler for attachment download action