2009-02-09 14:25:49 -08:00
|
|
|
<?php
|
|
|
|
|
class EmailAttachmentsController extends AppController {
|
|
|
|
|
|
2012-11-07 03:55:24 -08:00
|
|
|
var $name = 'EmailAttachments';
|
|
|
|
|
var $helpers = array('Html', 'Form');
|
2009-02-09 14:25:49 -08:00
|
|
|
|
|
|
|
|
|
2011-03-09 23:18:26 -08:00
|
|
|
|
|
|
|
|
|
2012-11-07 03:55:24 -08:00
|
|
|
function download($id) {
|
2019-12-17 20:06:53 -08:00
|
|
|
// maybe make this GET a go webservice that's something like
|
|
|
|
|
// GET vault.cmctechnologies.com.au/filename
|
|
|
|
|
// HTTP basic auth, or some sort of preshared key
|
|
|
|
|
// service hits S3 if required. Cached on disk for $sometime
|
|
|
|
|
|
2012-11-07 03:55:24 -08:00
|
|
|
$file = $this->EmailAttachment->findById($id);
|
2011-03-09 23:18:26 -08:00
|
|
|
|
2012-11-07 03:55:24 -08:00
|
|
|
$file_path = Configure::read('email_directory');
|
|
|
|
|
if(file_exists($file_path."/".$file['EmailAttachment']['name'])) {
|
2011-03-09 23:18:26 -08:00
|
|
|
|
|
|
|
|
|
2019-07-03 23:25:10 -07:00
|
|
|
|
2012-11-07 03:55:24 -08:00
|
|
|
Configure::write('debug', 0);
|
2011-03-09 23:18:26 -08:00
|
|
|
|
2012-11-07 03:55:24 -08:00
|
|
|
if(!$file['EmailAttachment']['filename']) {
|
|
|
|
|
$filename = 'vault_'.time();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$filename = $file['EmailAttachment']['filename'];
|
|
|
|
|
}
|
2011-03-09 23:18:26 -08:00
|
|
|
|
2012-11-07 03:55:24 -08:00
|
|
|
header('Content-type: ' . $file['EmailAttachment']['type']);
|
2019-07-03 23:53:39 -07:00
|
|
|
header('Content-length: ' . $file['EmailAttachment']['size']);
|
2012-11-07 03:55:24 -08:00
|
|
|
header('Content-Disposition: attachment; filename='.$filename);
|
2011-03-09 23:18:26 -08:00
|
|
|
|
2012-11-07 03:55:24 -08:00
|
|
|
readfile($file_path."/".$file['EmailAttachment']['name']);
|
2011-03-09 23:18:26 -08:00
|
|
|
|
2012-11-07 03:55:24 -08:00
|
|
|
exit();
|
2010-04-26 23:49:20 -07:00
|
|
|
}
|
2012-11-07 03:55:24 -08:00
|
|
|
else {
|
|
|
|
|
echo "ERROR!! : File Not Found";
|
|
|
|
|
echo $file['EmailAttachment']['filename'];
|
|
|
|
|
die();
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-02-09 14:25:49 -08:00
|
|
|
|
2012-11-07 03:55:24 -08:00
|
|
|
function view($id = null) {
|
|
|
|
|
Configure::write('debug', 0);
|
|
|
|
|
$this->layout = 'minimal';
|
|
|
|
|
if(!$id) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2011-03-09 23:18:26 -08:00
|
|
|
|
2012-11-07 03:55:24 -08:00
|
|
|
$file = $this->EmailAttachment->find('first', array('conditions'=>array('EmailAttachment.id'=>$id)));
|
|
|
|
|
//$this->set('attachment', $file);
|
2011-03-09 23:18:26 -08:00
|
|
|
|
2012-11-07 03:55:24 -08:00
|
|
|
$file_path = Configure::read('email_directory');
|
2011-03-09 23:18:26 -08:00
|
|
|
|
2012-11-07 03:55:24 -08:00
|
|
|
$contents = file_get_contents($file_path."/".$file['EmailAttachment']['name']);
|
2011-03-13 17:21:56 -07:00
|
|
|
|
|
|
|
|
|
2012-11-07 03:55:24 -08:00
|
|
|
if($file['EmailAttachment']['type'] == 'text/plain') {
|
|
|
|
|
$contents = nl2br($contents, true);
|
|
|
|
|
}
|
2011-03-13 17:21:56 -07:00
|
|
|
|
2011-03-09 23:18:26 -08:00
|
|
|
|
2012-11-07 03:55:24 -08:00
|
|
|
$this->set('contents', $contents);
|
2011-03-09 23:18:26 -08:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-07 03:55:24 -08:00
|
|
|
}
|
|
|
|
|
|
2011-03-09 23:18:26 -08:00
|
|
|
|
2009-02-09 14:25:49 -08:00
|
|
|
}
|