diff options
author | Thomas Bruederli <thomas@roundcube.net> | 2014-04-07 17:32:31 +0200 |
---|---|---|
committer | Thomas Bruederli <thomas@roundcube.net> | 2014-04-07 17:32:31 +0200 |
commit | bde3ba5e93f9b02ac8bd1d10e33fa65cc4da31c5 (patch) | |
tree | cf468211c5d3c6b927c732adcbf8c7df8a1fa587 /plugins/zipdownload | |
parent | 0456f728ee3f6312101d0a372b7385fb34fdaf2a (diff) |
Update zipdownload plugin to work with multi-folder search results
Diffstat (limited to 'plugins/zipdownload')
-rw-r--r-- | plugins/zipdownload/composer.json | 2 | ||||
-rw-r--r-- | plugins/zipdownload/package.xml | 6 | ||||
-rw-r--r-- | plugins/zipdownload/zipdownload.php | 51 |
3 files changed, 33 insertions, 26 deletions
diff --git a/plugins/zipdownload/composer.json b/plugins/zipdownload/composer.json index 168415cba..7f6e30935 100644 --- a/plugins/zipdownload/composer.json +++ b/plugins/zipdownload/composer.json @@ -3,7 +3,7 @@ "type": "roundcube-plugin", "description": "Adds an option to download all attachments to a message in one zip file, when a message has multiple attachments. Also allows the download of a selection of messages in one zip file and the download of entire folders.", "license": "GNU GPLv3+", - "version": "2.0", + "version": "2.1", "authors": [ { "name": "Thomas Bruederli", diff --git a/plugins/zipdownload/package.xml b/plugins/zipdownload/package.xml index bf5511563..3e5722045 100644 --- a/plugins/zipdownload/package.xml +++ b/plugins/zipdownload/package.xml @@ -19,10 +19,10 @@ <email>roundcube@gmail.com</email> <active>yes</active> </lead> - <date>2012-09-20</date> - <time>19:16:00</time> + <date>2014-04-07</date> + <time>17:28:00</time> <version> - <release>2.0</release> + <release>2.1</release> <api>2.0</api> </version> <stability> diff --git a/plugins/zipdownload/zipdownload.php b/plugins/zipdownload/zipdownload.php index 3bab286c5..32ff1b88b 100644 --- a/plugins/zipdownload/zipdownload.php +++ b/plugins/zipdownload/zipdownload.php @@ -5,7 +5,7 @@ * * Plugin to allow the download of all message attachments in one zip file * - * @version @package_version@ + * @version 2.1 * @requires php_zip extension (including ZipArchive class) * @author Philip Weir * @author Thomas Bruderli @@ -156,10 +156,10 @@ class zipdownload extends rcube_plugin public function download_selection() { if (isset($_REQUEST['_uid'])) { - $uids = explode(",", rcube_utils::get_input_value('_uid', rcube_utils::INPUT_GPC)); + $messageset = rcmail::get_uids(); - if (sizeof($uids) > 0) { - $this->_download_messages($uids); + if (sizeof($messageset) > 0) { + $this->_download_messages($messageset); } } } @@ -193,7 +193,7 @@ class zipdownload extends rcube_plugin } if (sizeof($uids) > 0) - $this->_download_messages($uids); + $this->_download_messages(array($mbox_name => $uids)); } /** @@ -201,38 +201,45 @@ class zipdownload extends rcube_plugin * * @param array List of message UIDs to download */ - private function _download_messages($uids) + private function _download_messages($messageset) { $rcmail = rcmail::get_instance(); $imap = $rcmail->get_storage(); $temp_dir = $rcmail->config->get('temp_dir'); $tmpfname = tempnam($temp_dir, 'zipdownload'); $tempfiles = array($tmpfname); + $folders = count($messageset) > 1; // open zip file $zip = new ZipArchive(); $zip->open($tmpfname, ZIPARCHIVE::OVERWRITE); - foreach ($uids as $uid){ - $headers = $imap->get_message_headers($uid); - $subject = rcube_mime::decode_mime_string((string)$headers->subject); - $subject = $this->_convert_filename($subject); - $subject = substr($subject, 0, 16); - - $disp_name = ($subject ? $subject : 'message_rfc822') . ".eml"; - $disp_name = $uid . "_" . $disp_name; - - $tmpfn = tempnam($temp_dir, 'zipmessage'); - $tmpfp = fopen($tmpfn, 'w'); - $imap->get_raw_body($uid, $tmpfp); - $tempfiles[] = $tmpfn; - fclose($tmpfp); - $zip->addFile($tmpfn, $disp_name); + foreach ($messageset as $mbox => $uids){ + $imap->set_folder($mbox); + $path = $folders ? str_replace($imap->get_hierarchy_delimiter(), '/', $mbox) . '/' : ''; + + foreach ($uids as $uid){ + $headers = $imap->get_message_headers($uid); + $subject = rcube_mime::decode_mime_string((string)$headers->subject); + $subject = $this->_convert_filename($subject); + $subject = substr($subject, 0, 16); + + $disp_name = ($subject ? $subject : 'message_rfc822') . ".eml"; + $disp_name = $path . $uid . "_" . $disp_name; + + $tmpfn = tempnam($temp_dir, 'zipmessage'); + $tmpfp = fopen($tmpfn, 'w'); + $imap->get_raw_body($uid, $tmpfp); + $tempfiles[] = $tmpfn; + fclose($tmpfp); + $zip->addFile($tmpfn, $disp_name); + } } $zip->close(); - $this->_deliver_zipfile($tmpfname, $imap->get_folder() . '.zip'); + $filename = $folders ? 'messages' : $imap->get_folder(); + $this->_deliver_zipfile($tmpfname, $filename . '.zip'); // delete temporary files from disk foreach ($tempfiles as $tmpfn) { |