mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-12-25 07:10:12 +01:00
download eml name reflects the subject
This commit is contained in:
parent
034aed6de7
commit
c1f2a2bbf1
@ -41,6 +41,7 @@ $config['CAPTCHA_FAILED_LOGIN_COUNT'] = 0;
|
|||||||
|
|
||||||
$config['ENABLE_REFERENCES'] = 1;
|
$config['ENABLE_REFERENCES'] = 1;
|
||||||
$config['ENABLE_DOWNLOADING_ALL_SEARCH_HITS'] = 0;
|
$config['ENABLE_DOWNLOADING_ALL_SEARCH_HITS'] = 0;
|
||||||
|
$config['EML_NAME_BASED_ON_SUBJECT'] = 1;
|
||||||
|
|
||||||
$config['ENABLE_TABLE_RESIZE'] = 0;
|
$config['ENABLE_TABLE_RESIZE'] = 0;
|
||||||
$config['DEMO_MODE'] = 0;
|
$config['DEMO_MODE'] = 0;
|
||||||
|
@ -35,12 +35,18 @@ class ControllerMessageDownload extends Controller {
|
|||||||
|
|
||||||
AUDIT(ACTION_DOWNLOAD_MESSAGE, '', '', $this->data['id'], '');
|
AUDIT(ACTION_DOWNLOAD_MESSAGE, '', '', $this->data['id'], '');
|
||||||
|
|
||||||
$this->data['piler_id'] = $this->model_search_message->get_piler_id_by_id($this->data['id']);
|
$filename = $this->data['piler_id'] = $this->model_search_message->get_piler_id_by_id($this->data['id']);
|
||||||
|
|
||||||
|
if(EML_NAME_BASED_ON_SUBJECT == 1) {
|
||||||
|
$filename = $this->model_search_message->get_subject_id_by_id($this->data['id']);
|
||||||
|
$filename = $this->model_search_message->fix_subject($filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
header("Cache-Control: public, must-revalidate");
|
header("Cache-Control: public, must-revalidate");
|
||||||
header("Pragma: no-cache");
|
header("Pragma: no-cache");
|
||||||
header("Content-Type: application/octet-stream");
|
header("Content-Type: application/octet-stream");
|
||||||
header("Content-Disposition: attachment; filename=" . $this->data['piler_id'] . ".eml");
|
header("Content-Disposition: attachment; filename=" . $filename . ".eml");
|
||||||
header("Content-Transfer-Encoding: binary\n");
|
header("Content-Transfer-Encoding: binary\n");
|
||||||
|
|
||||||
$this->model_search_message->connect_to_pilergetd();
|
$this->model_search_message->connect_to_pilergetd();
|
||||||
|
@ -4,25 +4,33 @@ class ModelMessageRestore extends Model {
|
|||||||
|
|
||||||
|
|
||||||
public function download_files_as_zip($idlist = array()) {
|
public function download_files_as_zip($idlist = array()) {
|
||||||
|
$i = 0;
|
||||||
|
|
||||||
$zip = new ZipArchive();
|
$zip = new ZipArchive();
|
||||||
|
|
||||||
$randomid = generate_random_string(16);
|
$randomid = generate_random_string(16);
|
||||||
|
|
||||||
$filename = DIR_BASE . "tmp/" . $randomid;
|
$zipname = DIR_BASE . "tmp/" . $randomid;
|
||||||
|
|
||||||
if($zip->open($filename, ZIPARCHIVE::CREATE) != true) { exit("cannot open <$filename>\n"); }
|
if($zip->open($zipname, ZIPARCHIVE::CREATE) != true) { exit("cannot open <$zipname>\n"); }
|
||||||
|
|
||||||
$this->model_search_message->connect_to_pilergetd();
|
$this->model_search_message->connect_to_pilergetd();
|
||||||
|
|
||||||
foreach($idlist as $id) {
|
foreach($idlist as $id) {
|
||||||
$piler_id = $this->model_search_message->get_piler_id_by_id($id);
|
$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;
|
||||||
|
}
|
||||||
|
|
||||||
$rawemail = $this->model_search_message->get_raw_message($piler_id);
|
$rawemail = $this->model_search_message->get_raw_message($piler_id);
|
||||||
|
|
||||||
$this->model_search_message->remove_journal($rawemail);
|
$this->model_search_message->remove_journal($rawemail);
|
||||||
|
|
||||||
$zip->addFromString($piler_id . ".eml", $rawemail);
|
$zip->addFromString($filename . ".eml", $rawemail);
|
||||||
|
|
||||||
AUDIT(ACTION_DOWNLOAD_MESSAGE, '', '', $id, '');
|
AUDIT(ACTION_DOWNLOAD_MESSAGE, '', '', $id, '');
|
||||||
}
|
}
|
||||||
@ -37,13 +45,13 @@ class ModelMessageRestore extends Model {
|
|||||||
header("Pragma: no-cache");
|
header("Pragma: no-cache");
|
||||||
header("Content-Type: application/zip");
|
header("Content-Type: application/zip");
|
||||||
header("Expires: 0");
|
header("Expires: 0");
|
||||||
header("Content-Length: " . filesize($filename));
|
header("Content-Length: " . filesize($zipname));
|
||||||
header("Content-Disposition: attachment; filename=archive-$randomid.zip");
|
header("Content-Disposition: attachment; filename=archive-$randomid.zip");
|
||||||
header("Content-Transfer-Encoding: binary\n");
|
header("Content-Transfer-Encoding: binary\n");
|
||||||
|
|
||||||
readfile($filename);
|
readfile($zipname);
|
||||||
|
|
||||||
unlink($filename);
|
unlink($zipname);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -748,6 +748,19 @@ class ModelSearchMessage extends Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function get_subject_id_by_id($id = 0) {
|
||||||
|
$query = $this->db->query("SELECT `subject` FROM `" . TABLE_META . "` WHERE id=?", array($id));
|
||||||
|
if(isset($query->row['subject'])) { return $query->row['subject']; }
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function fix_subject($s = '') {
|
||||||
|
if($s == '') { $s = 'nosubject'; }
|
||||||
|
return preg_replace("/^\-{1,}/", "", preg_replace("/\W{1,}/", "-", $s));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function get_attachment_by_id($id = 0) {
|
public function get_attachment_by_id($id = 0) {
|
||||||
if($id <= 0) { return array(); }
|
if($id <= 0) { return array(); }
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user