Ejemplo n.º 1
0
 /**
  * Check the correct configuration of the 'mime_types' mapping option
  */
 function check_mime_extensions()
 {
     $types = array('application/zip' => 'zip', 'application/x-tar' => 'tar', 'application/java-archive' => 'jar', 'image/gif' => 'gif', 'image/svg+xml' => 'svg');
     $errors = array();
     foreach ($types as $mimetype => $expected) {
         $ext = rcube_mime::get_mime_extensions($mimetype);
         if ($ext[0] != $expected) {
             $errors[] = array($mimetype, $ext, $expected);
         }
     }
     return $errors;
 }
Ejemplo n.º 2
0
 /**
  * Handler for attachment download action
  */
 public function download_attachments()
 {
     $rcmail = rcmail::get_instance();
     $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];
         $filename = $part->filename;
         if ($filename === null || $filename === '') {
             $ext = (array) rcube_mime::get_mime_extensions($part->mimetype);
             $ext = array_shift($ext);
             $filename = $rcmail->gettext('messagepart') . ' ' . $pid;
             if ($ext) {
                 $filename .= '.' . $ext;
             }
         }
         $disp_name = $this->_convert_filename($filename);
         if ($part->body) {
             $orig_message_raw = $part->body;
             $zip->addFromString($disp_name, $orig_message_raw);
         } else {
             $tmpfn = tempnam($temp_dir, 'zipattach');
             $tmpfp = fopen($tmpfn, 'w');
             $imap->get_message_part($message->uid, $part->mime_id, $part, null, $tmpfp, true);
             $tempfiles[] = $tmpfn;
             fclose($tmpfp);
             $zip->addFile($tmpfn, $disp_name);
         }
     }
     $zip->close();
     $filename = ($message->subject ? $message->subject : 'roundcube') . '.zip';
     $this->_deliver_zipfile($tmpfname, $filename);
     // delete temporary files from disk
     foreach ($tempfiles as $tmpfn) {
         unlink($tmpfn);
     }
     exit;
 }
Ejemplo n.º 3
0
 /**
  * Check the correct configuration of the 'mime_types' mapping option
  */
 public function check_mime_extensions()
 {
     $errors = array();
     $types = array('application/zip' => 'zip', 'text/css' => 'css', 'application/pdf' => 'pdf', 'image/gif' => 'gif', 'image/svg+xml' => 'svg');
     foreach ($types as $mimetype => $expected) {
         $ext = rcube_mime::get_mime_extensions($mimetype);
         if (!in_array($expected, (array) $ext)) {
             $errors[] = array($mimetype, $ext, $expected);
         }
     }
     return $errors;
 }
Ejemplo n.º 4
0
 /**
  * Handler for attachment download action
  */
 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];
         $filename = $part->filename;
         if ($filename === null || $filename === '') {
             $ext = (array) rcube_mime::get_mime_extensions($part->mimetype);
             $ext = array_shift($ext);
             $filename = $rcmail->gettext('messagepart') . ' ' . $pid;
             if ($ext) {
                 $filename .= '.' . $ext;
             }
         }
         $disp_name = $this->_convert_filename($filename);
         $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;
 }