| | |
| | | * Plugin to allow the download of all message attachments in one zip file |
| | | * and downloading of many messages in one go. |
| | | * |
| | | * @version 3.0 |
| | | * @version 3.1 |
| | | * @requires php_zip extension (including ZipArchive class) |
| | | * @author Philip Weir |
| | | * @author Thomas Bruderli |
| | |
| | | '_action' => 'plugin.zipdownload.attachments', |
| | | '_mbox' => $rcmail->output->env['mailbox'], |
| | | '_uid' => $rcmail->output->env['uid'], |
| | | )); |
| | | ), false, false, true); |
| | | |
| | | $link = html::a(array('href' => $href, 'class' => 'button zipdownload'), |
| | | rcube::Q($this->gettext('downloadall')) |
| | |
| | | */ |
| | | public function download_attachments() |
| | | { |
| | | $rcmail = rcmail::get_instance(); |
| | | $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'); |
| | |
| | | } |
| | | } |
| | | |
| | | $disp_name = $this->_convert_filename($filename); |
| | | $disp_name = $this->_convert_filename($filename); |
| | | $tmpfn = tempnam($temp_dir, 'zipattach'); |
| | | $tmpfp = fopen($tmpfn, 'w'); |
| | | $tempfiles[] = $tmpfn; |
| | | |
| | | 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); |
| | | } |
| | | $message->get_part_body($part->mime_id, false, 0, $tmpfp); |
| | | $zip->addFile($tmpfn, $disp_name); |
| | | fclose($tmpfp); |
| | | } |
| | | |
| | | $zip->close(); |
| | | |
| | | $filename = ($message->subject ? $message->subject : 'roundcube') . '.zip'; |
| | | $filename = ($message->subject ?: 'roundcube') . '.zip'; |
| | | $this->_deliver_zipfile($tmpfname, $filename); |
| | | |
| | | // delete temporary files from disk |
| | |
| | | $imap->set_folder($mbox); |
| | | $path = $folders ? str_replace($imap->get_hierarchy_delimiter(), '/', $mbox) . '/' : ''; |
| | | |
| | | if ($uids === '*') { |
| | | $index = $imap->index($mbox, null, null, true); |
| | | $uids = $index->get(); |
| | | } |
| | | |
| | | foreach ($uids as $uid) { |
| | | $headers = $imap->get_message_headers($uid); |
| | | |
| | |
| | | $subject = $this->_convert_filename($subject); |
| | | $subject = substr($subject, 0, 16); |
| | | |
| | | $disp_name = ($subject ? $subject : 'message_rfc822') . ".eml"; |
| | | $disp_name = ($subject ?: 'message_rfc822') . ".eml"; |
| | | $disp_name = $path . $uid . "_" . $disp_name; |
| | | |
| | | $tmpfn = tempnam($temp_dir, 'zipmessage'); |