piler/webui/model/message/restore.php

57 lines
1.4 KiB
PHP
Raw Permalink Normal View History

2012-05-11 23:42:55 +02:00
<?php
class ModelMessageRestore extends Model {
public function download_files_as_zip($idlist = array()) {
2015-10-23 20:40:07 +02:00
$i = 0;
2012-05-11 23:42:55 +02:00
$zip = new ZipArchive();
$randomid = generate_random_string(16);
2015-10-23 20:40:07 +02:00
$zipname = DIR_BASE . "tmp/" . $randomid;
2012-05-11 23:42:55 +02:00
2015-10-23 20:40:07 +02:00
if($zip->open($zipname, ZIPARCHIVE::CREATE) != true) { exit("cannot open <$zipname>\n"); }
2012-05-11 23:42:55 +02:00
foreach($idlist as $id) {
2015-10-23 20:40:07 +02:00
$i++;
$filename = $piler_id = $this->model_search_message->get_piler_id_by_id($id);
if(EML_NAME_BASED_ON_SUBJECT == 1) {
$filename = $this->model_search_message->get_subject_id_by_id($id);
$filename = $this->model_search_message->fix_subject($filename) . "-" . $i;
}
2012-09-06 15:27:20 +02:00
$rawemail = $this->model_search_message->get_raw_message($piler_id);
2013-04-09 15:02:10 +02:00
2015-02-17 13:56:51 +01:00
$this->model_search_message->remove_journal($rawemail);
2015-10-23 20:40:07 +02:00
$zip->addFromString($filename . ".eml", $rawemail);
2012-05-11 23:42:55 +02:00
AUDIT(ACTION_DOWNLOAD_MESSAGE, '', '', $id, '');
}
$zip->close();
header("Cache-Control: public, must-revalidate");
header("Pragma: no-cache");
header("Content-Type: application/zip");
header("Expires: 0");
2015-10-23 20:40:07 +02:00
header("Content-Length: " . filesize($zipname));
2012-05-11 23:42:55 +02:00
header("Content-Disposition: attachment; filename=archive-$randomid.zip");
header("Content-Transfer-Encoding: binary\n");
2015-10-23 20:40:07 +02:00
readfile($zipname);
2012-05-11 23:42:55 +02:00
2015-10-23 20:40:07 +02:00
unlink($zipname);
2012-05-11 23:42:55 +02:00
}
}
?>